• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JFrame

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic