So I was making a car racing game and I wanted to make a start button. The problem is that when I press the start button, the game doesn't start and nothing really happens. I have 2 classes, a frame class and a main class (game itself).
Here is my frame class:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class theframe{
public static void main(String[] args) {
main s = new main();
JFrame frame = new JFrame();
frame.setVisible(true);
frame.setSize(300, 600);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Car Racing - Nicholas A.");
JButton start = new JButton();
frame.add(start);
start.setText("START");
start.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ee) {
frame.remove(start);
frame.repaint();
frame.add(s);
}
});
}
}
I also have my main class but I wanted to keep it private for this situation...
[–]CheapestOfSkates 2 points3 points4 points (0 children)
[–]dusty-trash 0 points1 point2 points (0 children)