JavaPaintComponent实际上是在画画,而不是什么都没有发生?

fkaflof6  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(261)

这个问题在这里已经有答案了

使用paintcomponent()和paint()的java自定义绘图(1个答案)
在调用了paintcomponent方法(3个答案)之后,如何在jpanel中绘制一些东西
为什么必须使用paintcomponent方法在java中绘制(1个答案)
21天前关门了。
我在一个功能绘图仪工作,并期待着画2线,这将代表x轴和y轴。请您检查一下我的代码,并告诉我哪里出了问题!谢谢!:)这件事和我的问题无关。

public class AUSGABE_GUI extends JFrame {
  // Anfang Attribute
  public static final int WIDTH = 1024;
  public static final int HEIGHT = 768;
  Funktionsschar funktionsschar;

  private JPanel jPanel1 = new JPanel(null);
  // Ende Attribute

  public AUSGABE_GUI(Funktionsschar pFunktionsschar) { 
    super ("Plotter");
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    setSize(WIDTH, HEIGHT);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (d.width - getSize().width) / 2;
    int y = (d.height - getSize().height) / 2;
    setLocation(x, y);
    Container cp = getContentPane();
    cp.setLayout(null);

    jPanel1.setBounds(0, 0, WIDTH, HEIGHT);
    cp.add(jPanel1);

    setVisible(true);
  } 
  public void paintComponents(Graphics g) {
    super.paintComponents(g);
    Graphics2D g2d = (Graphics2D) g;
    g2d.setColor(Color.blue);
    g2d.drawLine(0, HEIGHT / 2, WIDTH, HEIGHT / 2);
    g2d.drawLine(WIDTH / 2, 0, WIDTH / 2, HEIGHT);
  }

另外,我真的很抱歉,如果我的代码看起来可怕,我是新的编码!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题