日期:2014-05-20 浏览次数:20786 次
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;
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("子菜单的子菜单");
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()//当选择点叉时隐藏dialog对画框时,编译都都不能通过,该如何修改呢,如果我想点叉时 直接将dialog对话框关闭(也就是不隐藏),又该如何改呢
{
public void windowClosing(WindowEvent e){
dialogs.setVisible(false);
}
});
saveItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e2) {
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("确定");
dialogs.add(labelTexts);
dialogs.add(bt);
dialogs.setBounds(300,300,100,50);
dialogs.setVisible(true);
}
}
});
}
public static void main(String[] args) {
new jishiben();
}
}