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 s
I've made a start below. It looks like you might want to invest some time in following a more basic java tutorial or course to get your basic java knowledge up to speed.
What happens in the code below is that the class theGame has a main entry for the program. The JVM will invoke the main method at the start of your program. From there, it will execute the instructions you give. So most of the times, two main methods do not make sense in a single project. Exception to this rule is if you want to have two separate application entry points two the same program (for instance a command-line application and a GUI application that use the same logic but are controlled differently).
So with the code below, you will have to specify the TheGame class as a main entry point when starting your JVM for this application.
public class TheGame {
private final LineTest theBoard;
public TheGame() {
theBoard = new LineTest();
}
public void run() {
JFrame frame = new JFrame("Points");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(theBoard);
frame.setSize(250, 200);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
/**
* Main entry for the program. Called by JRE.
*/
public static void main(String[] args) {
TheGame instance = new TheGame();
instance.run();
}
}
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);
}
}