..........
Panel panel=new Panel();
panel.add(labelAppID);
panel.add(textAppID); //Adding controls for Applicant name
panel.add(labelAppName);
panel.add(textAppName);
//Adding controls for Applicant Address
panel.add(labelAppAddress);
panel.add(textAppAddress); //Adding controls for Applicant Position
panel.add(labelAppPosition);
panel.add(comboAppPosition);
panel.add(l);
frame.getContentPane().add(panel);
Panel panel=new Panel();
panel.add(labelAppID);
panel.add(textAppID); //Adding controls for Applicant name
panel.add(labelAppName);
panel.add(textAppName);
//Adding controls for Applicant Address
panel.add(labelAppAddress);
panel.add(textAppAddress); //Adding controls for Applicant Position
panel.add(labelAppPosition);
panel.add(comboAppPosition);
panel.add(l);
frame.getContentPane().add(panel);
cannot resolve symbol
symbol : method getContentPane ()
location: class Applicant
getContentPane().add(panel);===========全部代码 import javax.swing.*;
public class Applicant
{ //Variable for frame window
//main is static,it will call this
JPanel panel; //variables of labels
JLabel labelAppID;
JLabel labelAppName;
JLabel labelAppAddress;
JLabel labelAppPosition; //variables for data entry controls
JTextField textAppID;
JTextField textAppName;
JTextField textAppAddress;
JComboBox comboAppPosition; public Applicant()
{ //Create a panel
panel = new JPanel();
labelAppID = new JLabel("Applicant ID");
labelAppName = new JLabel("Name");
labelAppAddress = new JLabel("Address");
labelAppPosition = new JLabel("Position"); //Initializing JTextField
textAppID = new JTextField(5);
textAppName = new JTextField(30);
textAppAddress = new JTextField(30);
String []C ={"China","india","English","American"};
JList l=new JList (C);
l.setSelectionMode(2);//0only single,1 continuous-shift key,2 any sequence- ctrl key String position[] = { "Manager","Executive", "Associate"};
comboAppPosition = new JComboBox(position);
panel.add(labelAppID);
panel.add(textAppID); //Adding controls for Applicant name
panel.add(labelAppName);
panel.add(textAppName);
//Adding controls for Applicant Address
panel.add(labelAppAddress);
panel.add(textAppAddress); //Adding controls for Applicant Position
panel.add(labelAppPosition);
panel.add(comboAppPosition);
panel.add(l);
add(panel);
//Create a panel
//Create and add the appropriate controls }
public static void main(String args[])
{
//Creating the JFrame object
JFrame frame = new JFrame("Applicant Details");
//making the frame visible
Applicant appObject;
appObject = new Applicant();
frame.setVisible(true);
frame.setSize(300,300);
}}
你的frame是在main()方法里申明的,不能在main()方法引用你应该申明为类的全局对象。
import javax.swing.*;public class Applicant
{ //Variable for frame window
//main is static,it will call this
public static void main(String args[])
{
//Creating the JFrame object
ApplicantFrame frame = new ApplicantFrame();
//making the frame visible
frame.setVisible(true);
frame.setSize(300,300);
frame.setTitle("Applicant Details");
}
}class ApplicantFrame extends JFrame
{
JPanel panel;
//variables of labels
JLabel labelAppID;
JLabel labelAppName;
JLabel labelAppAddress;
JLabel labelAppPosition; //variables for data entry controls
JTextField textAppID;
JTextField textAppName;
JTextField textAppAddress;
JComboBox comboAppPosition;
public ApplicantFrame()
{
//Create a panel
panel = new JPanel();
labelAppID = new JLabel("Applicant ID");
labelAppName = new JLabel("Name");
labelAppAddress = new JLabel("Address");
labelAppPosition = new JLabel("Position"); //Initializing JTextField
textAppID = new JTextField(5);
textAppName = new JTextField(30);
textAppAddress = new JTextField(30);
String []C ={"China","india","English","American"};
JList l=new JList (C);
l.setSelectionMode(2);//0only single,1 continuous-shift key,2 any sequence- ctrl key String position[] = { "Manager","Executive", "Associate"};
comboAppPosition = new JComboBox(position);
panel.add(labelAppID);
panel.add(textAppID); //Adding controls for Applicant name
panel.add(labelAppName);
panel.add(textAppName);
//Adding controls for Applicant Address
panel.add(labelAppAddress);
panel.add(textAppAddress); //Adding controls for Applicant Position
panel.add(labelAppPosition);
panel.add(comboAppPosition);
panel.add(l);
getContentPane().add(panel);
//Create a panel
}
}