首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

请教cannot resolve symbol的一个有关问题

2012-01-20 
请问cannot resolve symbol的一个问题importjava.awt.*importjava.awt.event.*importjavax.swing.*impo

请问cannot resolve symbol的一个问题
import   java.awt.*;
import   java.awt.event.*;
import   javax.swing.*;
import   ch08.Time3;

public   class   TimeTest5   extends   JApplet   implements   ActionListener{

private   Time3   time;
private   JLabel   hourLabel,   minuteLabel,   secondLabel;
private   JTextArea   hourField,   minuteField,   secondField,   displayField;
private   JButton   tickButton;

public   void   init()
{
time   =   new   Time3();

Container   container   =   getContenPane();
container.setLayout(   new   FlowLayout()   );

hourLabel   =   new   JLabel(   "Set   Hour "   );
hourField   =   new   JTextArea(   10   );
hourField.addActionListener(   this   );
container.add(   hourLabel   );
container.add(   hourField   );

minuteLabel   =   new   JLabel(   "Set   minute "   );
minuteField   =   new   JTextArea(   10   );
minuteField.addActionListener(   this   );
container.add(   minuteLabel   );
container.add(   minuteField   );

secondLabel   =   new   JLabel(   "Set   second "   );
secondField   =   new   JTextArea(   10   );
secondField.addActionListener(   this   );
container.add(   secondLabel   );
container.add(   secondField   );

displayField   =   new   JTextArea(   30   );
displayField.setEditable(   false   );
container.add(   displayField   );

tickButton   =   new   JButton(   "Add   1   to   second "   );
tickButton.addActionListener(   this   );
container.add(   tickButton   );

updateDisplay();
}

public   void   actionPerformed(   ActionEvent   actionEvent   )
{
if   (   actionEvent.getSource()   ==   tickButton   )
tick();
else   if   (   actionEvent.getSource()   ==   hourField   )
{
time.setHour(   Integer.parseInt(   actionEvent.getActionCommand()   )   );
hourField.setText(   " "   );
}
else   if   (   actionEvent.getSource()   ==   minuteField   )
{
time.setMinute(   Integer.parseInt(   actionEvent.getActionCommand()   )   );
minuteField.setText(   " "   );
}
else   if   (   actionEvent.getSource()   ==   secondField   )
{
time.setSecond(   Integer.parseInt(   actionEvent.getActionCommand()   )   );
secondField.setText(   " "   );
}
updateDisplay();  
}

public   void   updateDisplay()
{
displayField.setText(   "Hour: "   +   time.getHour()   +  
";   Minute:   "   +   time.getMinute()   +  
";   Second:   "   +   time.getSecond()   );

showStatus(   "Standard   time   is:   "   +   time.toString()   +
";   Universal   time   is:   "   +   time.toUniversalString()   );


}

public   void   tick()
{
time.setSecond(   (time.getSecond()   +   1   )   %   60   );

if   (   time.getSecond()   ==   0   )
{
time.setMinute(   (   time.getMinute()   +   1   )   %   60   );

if   (   time.getMinute()   ==   0   )
time.setHour(   (   time.getHour()   +   1   )   %   24   );
}
}
}

******************************************
编译时提示错误:
cannot   resolve   symbol   method   getContenPane   ()
cannot   resolve   symbol   constructor   JTextArea   (int)
cannot   resolve   symbol   method   addActionListener   (TimeTest5)
cannot   resolve   symbol   constructor   JTextArea   (int)
cannot   resolve   symbol   method   addActionListener   (TimeTest5)
cannot   resolve   symbol   constructor   JTextArea   (int)
cannot   resolve   symbol   method   addActionListener   (TimeTest5)
cannot   resolve   symbol   constructor   JTextArea   (int)
**********************************************
ch08.Time3   是自定义的包 
sdk安装在D盘 编写的程序和自定义的包在E盘
设置过环境变量
其它没有   import   自定义包   的程序都能正确编译和执行
不知是怎么回事?

[解决办法]
JApplet 没有这个方法 getContenPane()

new JTextArea( 10 ) //JTextArea没有只带一个参数的构造函数
[解决办法]
以下是JAVA DOC中的所有JTextArea构造函数。它没有一个是接收一个int参数的.
new JTextArea(10),它会去调JTextArea(String text) 构造函数,它会把new JTextArea(10)中的10当成一个String 变量,而这个变量你又没有声明,它找不到,所以就会报cannot resolve symbol异常.
-------------------------------------
JTextArea()
构造一个新的 TextArea。
JTextArea(Document doc)
构造一个新的 JTextArea,使其具有给定的文档模型,所有其他参数均默认为 (null, 0, 0)。
JTextArea(Document doc, String text, int rows, int columns)
构造具有指定行数和列数以及给定模型的新的 JTextArea。
JTextArea(int rows, int columns)
构造具有指定行数和列数的新的空 TextArea。
JTextArea(String text)
构造显示指定文本的新的 TextArea。
JTextArea(String text, int rows, int columns)
构造具有指定文本、行数和列数的新的 TextArea。

热点排行