Trying to make a GUI program
Hey, I'm trying to make a game but this is my first time dealing with GUI components. I want a main menu on the game with four buttons. The buttons are :Infantry Battle", "Tank Battle", "Mixed Battle", and "Exit Wars". However, I am having trouble making the buttons show up on the frame and they are not working. The book I am looking at isn't making much sense to me. Can anyone help me? Here's my code:
import java.awt.*;
import java.awt.event.*;
import jpb.*;
public class War
{
public static void main(String[] args)
{
Frame f = new Frame("Main Menu");
f.setSize(400, 400);
f.setVisible(true);
f.setLocation(300, 300);
}
}
// Frame class
class ButtonTestFrame extends Frame
{
public ButtonTestFrame(String title)
{
super(title);
setLayout(new FlowLayout());
Button exit = new Button("Exit Wars");
add(exit);
exit.addActionListener(new ButtonListener());
// Attach window listener
addWindowListener(new ButtonListener());
}
// Listener for button
class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
System.exit(0);
}
}
}
:confused: