0

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
}
1
  • That code is outside the constructor's body frame.setVisible (true); frame.pack(); also there is no variable frame declared in the code that you've posted Commented Jan 16, 2015 at 21:07

2 Answers 2

3

You have no frame object declared, your class extends it so use superclass's method.

setVisible(true);
pack();
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.