A bit confused about the public static void main method in Java and was hoping someone could help. I have two classes
public class theGame {
public static void main(String[] args) {
lineTest gameBoard = new lineTest();
}
and
public class lineTest extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.red);
g2d.drawLine(100, 100, 100, 200);
}
public static void main(String[] args) {
lineTest points = new lineTest();
JFrame frame = new JFrame("Points");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(points);
frame.setSize(250, 200);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
My program doesn't draw the line unfortunately. I am trying to figure out why the main method in the lineTest class doesn't kick in?
While I can make it work by changing the main method to something else, such as 'go' and then running that method from the 'theGame' class, I am intrigued as to why the main method in the lineTest class doesn't work.