I am working on a funtion plotter and am looking towards painting 2 lines which shall represent the x and y axis. Would you be so kind and review my code and possibly tell me what is wrong! Thank you! :) This thing funktionsschar is irrelevant to my question.
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);
}
Also i am really sorry if my code looks terrbile i am NEW to coding!