wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes JFrame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JFrame" Watch "JFrame" New topic
Author

JFrame

Suela Smith
Greenhorn

Joined: Apr 20, 2006
Posts: 11
Hi, I want to create a JFrame that has JLabels, JTextArea, JTextField, and JButtons, i have this code but when i try to cmpile i got an error.

code:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;


public class PersonGUI extends JFrame {{

JPanel panel1 = null;
JPanel panel2 = null;
JPanel panel2a = null;
JPanel panel2b = null;
JPanel panel2c = null;
JPanel panel2a1 = null;

JLabel label1 = null;
JLabel label2 = null;
JLabel label3 = null;
JLabel label4 = null;
JLabel label5 = null;

JTextField textfield1 = null;
JTextField textfield2 = null;
JTextField textfield3 = null;
JTextField textfield4 = null;
JTextField textfield5 = null;

JTextArea textarea1 = null;

JButton button1 = null;
JButton button2 = null;
JButton button3 = null;
JButton button4 = null;


panel1 = new JPanel();
panel2 = new JPanel();
panel2a = new JPanel();
panel2b = new JPanel();
panel2c = new JPanel();
panel2a1 = new JPanel();

label1 = new JLabel("First Name");
label2 = new JLabel("Last Name");
label3 = new JLabel("Middle Name");
label4 = new JLabel("Age");
label5 = new JLabel("Gender");

textfield1 = new JTextField(20);
textfield2 = new JTextField(20);
textfield3 = new JTextField(20);
textfield4 = new JTextField(20);
textfield5 = new JTextField(20);

textarea1 = new JTextArea(50, 20);
JScrollPane scrollpane = new JScrollPane(textarea1);

button1 = new JButton("Save");
button1.addActionListener(al);
button2 = new JButton("Next");
button2.addActionListener(al);
button3 = new JButton("Load");
button3.addActionListener(al);
button4 = new JButton("Clear");
button4.addActionListener(al);

panel2.setLayout(new GridLayout(3, 1, 0, 0));

panel2a.setLayout(new GridLayout(2, 1, 0, 0));
panel1.add(scrollpane);

panel2a1.add(label1);
panel2a1.add(textfield1);

panel2a1.add(label2);
panel2a1.add(textfield2);

panel2a1.add(label3);
panel2a1.add(textfield3);

panel2a1.add(label4);
panel2a1.add(textfield4);

panel2a1.add(label5);
panel2a1.add(textfield5);

panel2.add(panel2a);

panel2.add(panel2b);
panel2.add(panel2c);

this.getContentPane().setLayout(new GridLayout(2, 1, 0, 0));
this.getContentPane().add(panel1);
this.getContentPane().add(panel2);
this.setSize(800,600);
this.setLocation(200,200);
this.pack();
this.setVisible(true);
}
}
errors:
cannot resolve symbol
variable al
button1.addActionListener(al);

Ty in advance for ur help
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535

The first of four errors. "cannot find symbol" means that java tried to look something up and could not find it. The error message in the console says it is the symbol "al" on line 57. So it could not find where you delcared "al".

[ April 21, 2006: Message edited by: Craig Wood ]
Suela Smith
Greenhorn

Joined: Apr 20, 2006
Posts: 11
thanks Craig for your help
I need your help again becouse i still get an error
error:

";" expected
al = ActionLstener(){

when i replaced "{" with ";" i got more erors

thanks again
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
when you get the error, does the compiler message point to the closing parenthesis?

(the above '^' might not line up correctly to the ')' - but it is supposed to)

if you do see that from the compiler, remove the closing parenthesis
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JFrame
 
Similar Threads
JPanel
Sample maintenance disply
another .ttf question
TEXTFIELDS TO INT
JFrame