package 我的记事本;
import java.awt.*;
import javax.print.attribute.standard.Destination;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
public static void main
(String []args
){
Mytext a = new Mytext();
}
Mytext(){
//标题栏
source
= new JMenu("资源");
New.setMnemonic('f');
Open.addActionListener(this);
Open.setActionCommand("open");
Save.addActionListener(this);
Save.setActionCommand("save");
myMenuBar.add(file);
myMenuBar.add(edit);
myMenuBar.add(source);
file.add(New);
file.addSeparator();
file.add(Open);
file.addSeparator();
file.add(Save);
edit.add(Cut);
edit.addSeparator();
edit.add(Copy);
source.add(test);
this.add(my);
this.setTitle("记事本");
this.
setIconImage(new ImageIcon("image/tubiao2.jpg").
getImage());
this.setJMenuBar(myMenuBar);
this.setSize(500,500);
this.setLocation(100, 200);
this.setResizable(true);
this.
setDefaultCloseOperation(JFrame.
EXIT_ON_CLOSE);
this.setVisible(true);
}
@Override
if(e.getActionCommand().equals("open")){
//System.out.println("打开");
mychoose.setDialogTitle("文件打开");
mychoose.showOpenDialog(null);
mychoose.setVisible(true);
String category
= mychoose.
getSelectedFile().
getAbsolutePath();
try {
while((msg =Mytextbuf.readLine()) != null){
zfc +=msg+"\n";
}
myTextArea.setText(zfc);
e1.printStackTrace();
}finally{
try {
mytext.close();
Mytextbuf.close();
e1.printStackTrace();
}
}
}
if(e.getActionCommand().equals("save")){
filedestination.setDialogTitle("文件另存为");
filedestination.showSaveDialog(this);
filedestination.setVisible(true);
String category
= filedestination.
getSelectedFile().
getAbsolutePath();
try {
myTextArea.write(destinationbuf);
e1.printStackTrace();
}finally{
try {
destination.close();
destinationbuf.close();
e1.printStackTrace();
}
}
}
}
}