0

i'm using NetBeans and i keep getting an error in this code:

package desktopapplication7;

import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JPanel;


public class Frame extends JFrame 
{
    Container c= getContentPane();
    setLayout(new BorderLayout(5,10));
    JPanel p= new JPanel();
    p.add(new JButton("OK"));  // ERROR HERE
    
    c.add(p,BorderLayout.Center);  // ERROR HERE
}

on both lines above, it keeps telling me : <identifier> Expected.

can anyone help me fixing this ?

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Blackeagle
0

If you want to call methods you can only do it inside other methods (a Constructor maybe).
Where you wrote the code that gives you the error you can only put variable declarations.
So you must declare a method (preferably a Constructor) and put the code that gives you the error there

0

OH i see .... don't know how i missed that one, probably of tiredness.
Thanks a lot

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.