我想实现点击 菜单-新建,使得text中的文字清空~
请求高手指点下面这段小代码到底是哪里出错了?class HtmlFrame extends JFrame
{ public HtmlFrame()
{
setTitle("text");
setSize(WIDTH,HEIGHT); HtmlPanel panel=new HtmlPanel();
add(panel); JMenu fileMenu=new JMenu("File");
fileMenu.setMnemonic('F');
JMenuItem newItem=new JMenuItem("New(N)");
fileMenu.add(newItem);
newItem.addActionListener(new
ActionListener()
{
public void actionPerformed(ActionEvent event)
{
htmlTextArea.setText("");
}
}); JMenuBar menuBar=new JMenuBar();
setJMenuBar(menuBar); menuBar.add(fileMenu); }
public static final int WIDTH=600;
public static final int HEIGHT=500;}class HtmlPanel extends JPanel
{
public HtmlPanel()
{
final JTextArea htmlTextArea=new JTextArea(10,20);
htmlTextArea.setText("11111111111"); //htmlTextArea中的初始内容为111111111
JScrollPane scrollpane=new JScrollPane(htmlTextArea); }}
编译后,显示如下错误:
cannot find symbol
symbol: variable htmlTextArea
htmlTextArea.setText("");
请问高手这行htmlTextArea.setText("");究竟是哪里错了?
应该如何改正?谢谢大家的帮忙~!
请求高手指点下面这段小代码到底是哪里出错了?class HtmlFrame extends JFrame
{ public HtmlFrame()
{
setTitle("text");
setSize(WIDTH,HEIGHT); HtmlPanel panel=new HtmlPanel();
add(panel); JMenu fileMenu=new JMenu("File");
fileMenu.setMnemonic('F');
JMenuItem newItem=new JMenuItem("New(N)");
fileMenu.add(newItem);
newItem.addActionListener(new
ActionListener()
{
public void actionPerformed(ActionEvent event)
{
htmlTextArea.setText("");
}
}); JMenuBar menuBar=new JMenuBar();
setJMenuBar(menuBar); menuBar.add(fileMenu); }
public static final int WIDTH=600;
public static final int HEIGHT=500;}class HtmlPanel extends JPanel
{
public HtmlPanel()
{
final JTextArea htmlTextArea=new JTextArea(10,20);
htmlTextArea.setText("11111111111"); //htmlTextArea中的初始内容为111111111
JScrollPane scrollpane=new JScrollPane(htmlTextArea); }}
编译后,显示如下错误:
cannot find symbol
symbol: variable htmlTextArea
htmlTextArea.setText("");
请问高手这行htmlTextArea.setText("");究竟是哪里错了?
应该如何改正?谢谢大家的帮忙~!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货