当前位置: 技术问答>java相关
新手的一个简单问题~
来源: 互联网 发布时间:2015-07-30
本文导语: 下面是程序: import javax.swing.*; public class Applicant { //框架窗口的变量 static JFrame frame; static JPanel panel; //标签变量 JLabel labelAppid; JLabel labelAppName; JLabel labelAppAddress; JLabel labelAppPosition; //数据输入项控件变量 JTextFie...
下面是程序:
import javax.swing.*;
public class Applicant
{
//框架窗口的变量
static JFrame frame;
static JPanel panel;
//标签变量
JLabel labelAppid;
JLabel labelAppName;
JLabel labelAppAddress;
JLabel labelAppPosition;
//数据输入项控件变量
JTextField textAppID;
JTextField textAppName;
JTextField textAppAddress;
JComboBox comboAppPosition;
public static void main(String args[])
{
//创建Jframe对象
frame=new JFrame("Applicant Details");
//使框架可见
Applicant ao;
ao=new Applicant();
frame.setVisible(true);
frame.setSize(300,300);
}
public Applicant()
{
//在构造函数中将相应控件添加到框架中
//创建一个面板
panel=new JPanel();
frame.getContentPane().add(panel);
//创建并添加相应控件
//初始化标签
labelAppID=new JLabel("Applicant ID");
labelAppName=new JLabel("Applicant Name");
labelAppAddress=new JLabel("Applicant Address");
labelAppPosition=new JLabel("Applicant Position");
//初始化文本框
textAppID=new JTextField(5);
textAppName=new JTextField(30);
textAppAddress=new JTextField(30);
String positions[]={"Manager","Executive","Associate"};
ComboAppPosition=new JComboBox(positions);
//为Applicant ID添加控件
panel.add(labelAppID);
panel.add(textAppID);
//为Applicant Name添加控件
panel.add(labelAppName);
panel.add(textAppName);
//为Applicant Address添加控件
panel.add(labelAppAddress);
panel.add(textAppAddres);
//为Applicant Position添加控件
panel.add(labelAppPosition);
panel.add(comboAppPosition);
}
}
然后我运行:
C:>javac Applicant.java
Applicant.java:35: cannot resolve symbol
symbol : variable labelAppID
location: class Applicant
labelAppID=new JLabel("Applicant ID");
^
Applicant.java:44: cannot resolve symbol
symbol : variable ComboAppPosition
location: class Applicant
ComboAppPosition=new JComboBox(positions);
^
Applicant.java:46: cannot resolve symbol
symbol : variable labelAppID
location: class Applicant
panel.add(labelAppID);
^
Applicant.java:53: cannot resolve symbol
symbol : variable textAppAddres
location: class Applicant
panel.add(textAppAddres);
^
4 errors
到底哪里出错了?!希望大家能帮帮我,谢谢了!
import javax.swing.*;
public class Applicant
{
//框架窗口的变量
static JFrame frame;
static JPanel panel;
//标签变量
JLabel labelAppid;
JLabel labelAppName;
JLabel labelAppAddress;
JLabel labelAppPosition;
//数据输入项控件变量
JTextField textAppID;
JTextField textAppName;
JTextField textAppAddress;
JComboBox comboAppPosition;
public static void main(String args[])
{
//创建Jframe对象
frame=new JFrame("Applicant Details");
//使框架可见
Applicant ao;
ao=new Applicant();
frame.setVisible(true);
frame.setSize(300,300);
}
public Applicant()
{
//在构造函数中将相应控件添加到框架中
//创建一个面板
panel=new JPanel();
frame.getContentPane().add(panel);
//创建并添加相应控件
//初始化标签
labelAppID=new JLabel("Applicant ID");
labelAppName=new JLabel("Applicant Name");
labelAppAddress=new JLabel("Applicant Address");
labelAppPosition=new JLabel("Applicant Position");
//初始化文本框
textAppID=new JTextField(5);
textAppName=new JTextField(30);
textAppAddress=new JTextField(30);
String positions[]={"Manager","Executive","Associate"};
ComboAppPosition=new JComboBox(positions);
//为Applicant ID添加控件
panel.add(labelAppID);
panel.add(textAppID);
//为Applicant Name添加控件
panel.add(labelAppName);
panel.add(textAppName);
//为Applicant Address添加控件
panel.add(labelAppAddress);
panel.add(textAppAddres);
//为Applicant Position添加控件
panel.add(labelAppPosition);
panel.add(comboAppPosition);
}
}
然后我运行:
C:>javac Applicant.java
Applicant.java:35: cannot resolve symbol
symbol : variable labelAppID
location: class Applicant
labelAppID=new JLabel("Applicant ID");
^
Applicant.java:44: cannot resolve symbol
symbol : variable ComboAppPosition
location: class Applicant
ComboAppPosition=new JComboBox(positions);
^
Applicant.java:46: cannot resolve symbol
symbol : variable labelAppID
location: class Applicant
panel.add(labelAppID);
^
Applicant.java:53: cannot resolve symbol
symbol : variable textAppAddres
location: class Applicant
panel.add(textAppAddres);
^
4 errors
到底哪里出错了?!希望大家能帮帮我,谢谢了!
|
大小写搞错了
|
楼上说得没有错,的确是你的大小写问题,你只要把你的这些地方该了就可以编译通过了:
1,labelAppid-----〉labelAppID
2,panel.add(textAppAddres);------>panel.add(textAppAddress);
不过我想尽管你可以通过编译,运行的时候也会跑出空指针!
祝你好运!!
1,labelAppid-----〉labelAppID
2,panel.add(textAppAddres);------>panel.add(textAppAddress);
不过我想尽管你可以通过编译,运行的时候也会跑出空指针!
祝你好运!!
|
老大,怎么不是大小些的问题??
你看看这一行:
//标签变量
JLabel labelAppid;
再看看这:
//初始化标签
labelAppID=new JLabel("Applicant ID");
晕倒!!!
你看看这一行:
//标签变量
JLabel labelAppid;
再看看这:
//初始化标签
labelAppID=new JLabel("Applicant ID");
晕倒!!!