问题:为什么点击菜单打开后,文本域不显示aaaaa
代码
*******************************************************************************
/*记事本*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Notepad
{
public static void main(String[] args)
{
AFrame frame = new AFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
class AFrame extends JFrame
{
public AFrame()
{
setSize(500,500);
setTitle("NotepadDemo");
setResizable(false);
Container c = getContentPane();
APanel panel = new APanel();
c.add(panel);
MenuInit();
}
void MenuInit() //初始化菜单
{
JMenuBar menuBar = new JMenuBar();
JMenu menuFile = new JMenu("操作");
JMenuItem menuFileOpen = new JMenuItem("打开..");
JMenuItem menuFileSave = new JMenuItem("保存..");
JMenuItem menuFileSaveAs = new JMenuItem("另存为..");
JMenuItem menuFileExit = new JMenuItem("退出");
setJMenuBar(menuBar);
menuBar.add(menuFile);
menuFile.add(menuFileOpen);
menuFile.add(menuFileSave);
menuFile.add(menuFileSaveAs);
menuFile.add(menuFileExit);
menuFileOpen.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
textArea.setText("aaaaa"); //为什么点击打开按钮文本域上不显示aaaaa呢?
}
});
}
}
class APanel extends JPanel
{
JTextArea textArea = new JTextArea();
APanel()
{
textArea.setColumns(44);
textArea.setRows(33);
add(textArea);
}
}