Reputation: 1
I am trying to make an interface with various different JPanels , however for some reason, I am getting this one error. The error is at the bottom of the code. It's with setting my frame visible.
public class GUIExampleApp extends JFrame implements ActionListener {
JLabel Title, Description;
JButton Start, Help, Quit;
TextField Limiting;
JPanel panelContainer = new JPanel (true);
JPanel StartApplication = new JPanel (true);
JPanel StartingApplication = new JPanel (true);
CardLayout card = new CardLayout();
public GUIExampleApp() { // constructing the window
super("GUIExampleApp");
panelContainer.setLayout(card);
panelContainer.add(StartApplication, "1");
panelContainer.add(StartingApplication, "2");
card.show(panelContainer, "now");
// Set the frame's name
// get the container frame
// Create labels, text boxes and buttons
Title = new JLabel("INTERFACE");
Description = new JLabel("Knowledge grows everyday");
MainMenuApplicationDesc= new JLabel("Pick Which Unit you want to study");
Title.setBackground(Color.red);
Title.setForeground(Color.blue);
StartingApplication.setBackground(Color.red);
Description.setBackground(Color.red);
Description.setForeground(Color.blue);
Start = new JButton("Start");
Help = new JButton("Help");
Quit = new JButton("Quit");
// make the buttons listen to clicks on this application
Start.addActionListener(this);
Help.addActionListener(this);
Quit.addActionListener(this);
setSize(600, 600); // Set the frame's size
Start.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
card.show(panelContainer, "2");
}
});
Back.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
card.show(panelContainer, "1");
}
});
Quit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0){
System.exit (1);
}
});
}
// ERRORS ARE HERE, "Syntax Error"
frame.setVisible(true);
frame.pack();
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new GUIExampleApp();
} // Create a GUIExampleApp frame
});
} // main method
}
Upvotes: 0
Views: 75
Reputation: 159
You have no frame object declared, your class extends it so use superclass's method.
setVisible(true);
pack();
Upvotes: 3
Reputation: 356
There are a couple of things. One, where is the variable frame declared? Look at your scope, these lines are outside of any method. That's the syntax error.
Upvotes: 0