日期:2014-05-20 浏览次数:20987 次
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class GUITest1 extends JFrame implements ActionListener
{
JMenuBar jmb = new JMenuBar();
JMenu jm1 = new JMenu("游戏");
JMenu jm2 = new JMenu("查看");
JMenuItem jmi1 = new JMenuItem("开始");
JMenuItem jmi2 = new JMenuItem("暂停");
JMenuItem jmi3 = new JMenuItem("关于");
File f = new File("D:/jworkspace/说明书.txt");
String a = null;
JTextArea ja = null;
boolean help = false;
public GUITest1()
{
setBounds(200, 300, 200, 300);
this.setJMenuBar(jmb);
jmb.add(jm1);
jm1.add(jmi1);
jm1.add(jmi2);
jmb.add(jm2);
jm2.add(jmi3);
jmi3.addActionListener(this);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == jmi3)
{
if (e.getActionCommand().equals("关于"))
{
if (help)
{
this.remove(ja);
help = false;
}
ja = new JTextArea();
ja.setEditable(false);
this.add(ja);
try
{
InputStreamReader read = new InputStreamReader(
new FileInputStream(f), "GBK");
BufferedReader reader = new BufferedReader(read);
while ((a = reader.readLine()) != null)
{
System.out.println(a);