import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
public class jishiben {
private Frame f;
private Menu m,mc;
private MenuBar mb;
private MenuItem closeItem,saveItem,openItem,mcc;
private TextArea TextAreas;
private FileDialog openDialog,saveDialog;
private Dialog dialogs;
private Label labelTexts;
private Button bt;
private File file;
jishiben(){
init();
}
public void init(){
f=new Frame("记事本");
f.setBounds(300,100,600,500);
//f.setLayout(new FlowLayout());
mb=new MenuBar();
m=new Menu("文件");
mc=new Menu("子菜单");
openItem =new MenuItem("打开");
saveItem =new MenuItem("保存");
closeItem =new MenuItem("退出");
mcc=new MenuItem("子菜单的子菜单");
dialogs=new Dialog(f,"dialogs",true);
dialogs.setLayout(new FlowLayout());
m.add(mc);
mc.add(mcc);
m.add(openItem);
m.add(saveItem);
m.add(closeItem);
mb.add(m);
f.setMenuBar(mb);
TextAreas =new TextArea();
TextAreas.setColumns(5);
f.add(TextAreas);
myEvents();
f.setVisible(true);
}
public void myEvents(){
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
dialogs.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e){
dialogs.dispose();
}
});
bt.addActionListener(new ActionListener() {//这里报错
public void actionPerformed(ActionEvent e) {
//dialogs.setVisible(false);
dialogs.dispose();
//dialogs.setVisible(false);
//System.out.print("1111111");
}
});
saveItem.addActionListener(new ActionListener(){//保存文件动作
public void actionPerformed(ActionEvent e2) {
if(file==null){
saveDialog=new FileDialog(f,"我要保存",FileDialog.LOAD);
saveDialog.setVisible(true);
String getPath=saveDialog.getDirectory();
String getFile=saveDialog.getFile();
if(getPath==null || getFile==null){
//dialogs=new Dialog(f,"对不起,你没有选择",true);
labelTexts=new Label("你没有选择任何内容");
bt=new Button("确定");
详细解决方案
求高手帮忙这段代码错哪了
热度:25 发布时间:2016-04-23 22:36:35.0
相关解决方案