您的位置:首页 > 编程语言

有点问题的代码

2008-03-27 22:28 288 查看
一个有问题的程序。。

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class EditBook
{
public static void main(String[] args)
{
Edit e=new Edit();
e.run();
}
}
class Edit extends JFrame
{

JMenuBar jmb;
JMenu file;
JMenu compile;
JMenu tool;
JMenu help;
JMenuItem newF;
JMenuItem open;
JMenuItem save;
JMenuItem exit;
JMenuItem copy;
JMenuItem cut;
JMenuItem paste;
JMenuItem s_all;
JMenuItem color;
JMenuItem toolb;
JMenuItem toolc;
JMenuItem h;
JTextArea jta;
JDialog jd;
JPanel jp;
JToolBar jtb;
String message;
public void run(){
jmb=new JMenuBar();
jp=new JPanel();
file=new JMenu("文件");
compile=new JMenu("编辑");
tool=new JMenu("工具");
help=new JMenu("帮助");

newF=new JMenuItem("新建");
open=new JMenuItem("打开");
save=new JMenuItem("保存");
exit=new JMenuItem("退出");
copy=new JMenuItem("Copy");
cut=new JMenuItem("Cut");
paste=new JMenuItem("Paste");
s_all=new JMenuItem("保存全部");
color=new JMenuItem("Color");
toolb=new JMenuItem("MS记事本");
toolc=new JMenuItem("MS计算器");

h=new JMenuItem("关于");
jtb=new JToolBar("MyJToolBar");

jta=new JTextArea(20,30);
/*
ef.addWindowListener(new WindowAdapter(WindowEvent e){
System.exit(0);
});
*/

//文件
file.add(newF);
file.add(open);
//////////如何显示文件内容
open.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
jd=new JDialog(new JFrame(),"Color");
JFileChooser jfc=new JFileChooser();
String f=jfc.getName();
System.out.println(f);
jd.add(jfc);
jd.pack();
jd.setVisible(true);
}
});
file.add(save);
file.add(exit);
exit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});

//编辑
compile.add(copy);
copy.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
jta.copy();
}
});
compile.add(cut);
cut.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
jta.cut();
}
});
compile.add(paste);
paste.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
jta.paste();
}
});
compile.add(s_all);
compile.add(color);
color.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
jd=new JDialog(new JFrame(),"Color");
jd.add(new JColorChooser());
jd.pack();
jd.setVisible(true);
}
});

//工具
tool.add(toolb);
tool.add(toolc);
toolc.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Calculate cc=new Calculate();
cc.display();
}
});

//帮助
help.add(h);
jmb.add(file);
jmb.add(compile);
jmb.add(tool);
jmb.add(help);
jtb.add(new JButton(new ImageIcon("copy.jpg")));
jtb.add(new JButton(new ImageIcon("copy.jpg")));
jtb.add(new JButton(new ImageIcon("copy.jpg")));
jp.setLayout(new BorderLayout());
jp.add("North",jtb);
jp.add("Center",jta);
this.setJMenuBar(jmb);
this.add(jp);
this.pack();
this.setTitle("简单文本编辑器");
this.setLocation(100,150);
this.setVisible(true);
}

}






内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: