大体的注释下下面的代吗 每句话或是每段话是用来干嘛的
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.ActionEvent;
import java.awt.*;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class MyNotepad extends JFrame implements ActionListener {
File file = null;
Color color = Color.black;
JTextPane text = new JTextPane();
JDialog about = new JDialog(this);
JFileChooser filechooser = new JFileChooser();
GraphicsEnvironment getFont = GraphicsEnvironment.getLocalGraphicsEnvironment();
Font [] fonts = getFont.getAllFonts();
JColorChooser colorchooser = new JColorChooser();
private JMenuItem jminew, jmiopen, jmisave, jmisaveas;
private JMenuItem jmicut, jmicopy, jmiplaster, jmiall;
private JMenuItem jmifont, jmicolor;
private JMenuItem jminotepad, jmicalculator;
private JMenuItem jmiabout;
private JMenuItem jmiexit;
public static void main(String[] args) {
Notepad frame = new Notepad();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
public MyNotepad() {
setTitle("Notepad");
setLocation(100, 50);
JMenuBar jmb = new JMenuBar();
setJMenuBar(jmb);
JMenu filemenu = new JMenu("File");
filemenu.setMnemonic('F');
jmb.add(filemenu);
JMenu editmenu = new JMenu("Edit");
editmenu.setMnemonic('E');
jmb.add(editmenu);
JMenu formatmenu = new JMenu("Format");
formatmenu.setMnemonic('T');
jmb.add(formatmenu);
JMenu toolmenu = new JMenu("Tool");
toolmenu.setMnemonic('L');
jmb.add(toolmenu);
JMenu helpmenu = new JMenu("Help");
helpmenu.setMnemonic('H');
jmb.add(helpmenu);
JMenu exitmenu = new JMenu("Exit");
exitmenu.setMnemonic('X');
jmb.add(exitmenu);
filemenu.add(jminew = new JMenuItem("New", 'N'));
filemenu.add(jmiopen = new JMenuItem("Open", 'O'));
filemenu.add(jmisave = new JMenuItem("Save", 'S'));
filemenu.addSeparator();
filemenu.add(jmisaveas = new JMenuItem("Save as"));
jminew.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
jmiopen.setAccelerator(
KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
jmisave.setAccelerator(
KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
editmenu.add(jmicut = new JMenuItem("Cut", 'X'));
editmenu.add(jmicopy = new JMenuItem("Copy", 'C'));
editmenu.add(jmiplaster = new JMenuItem("Plaster", 'V'));
editmenu.addSeparator();
editmenu.add(jmiall = new JMenuItem("All"));
jmicut.setAccelerator(
KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));
jmicopy.setAccelerator(
KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
jmiplaster.setAccelerator(
KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK));
jmiall.setAccelerator(
KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
formatmenu.add(jmifont = new JMenuItem("Font"));
formatmenu.addSeparator();
formatmenu.add(jmicolor = new JMenuItem("Color"));
toolmenu.add(jminotepad = new JMenuItem("MS Notepad"));
toolmenu.addSeparator();
toolmenu.add(jmicalculator = new JMenuItem("MS Calculator"));
helpmenu.add(jmiabout = new JMenuItem("About"));
exitmenu.add(jmiexit = new JMenuItem("Exit"));
setFont(new Font("Times New Roman", Font.PLAIN, 12));
JScrollPane scrollpane = new JScrollPane(text);
scrollpane.setPreferredSize(new Dimension(600, 500));
getContentPane().add(scrollpane);
jminew.addActionListener(this);
jmiopen.addActionListener(this);
jmisave.addActionListener(this);
jmisaveas.addActionListener(this);
jmicut.addActionListener(this);
jmicopy.addActionListener(this);
jmiplaster.addActionListener(this);
jmiall.addActionListener(this);
jmifont.addActionListener(this);
jmicolor.addActionListener(this);
jminotepad.addActionListener(this);
jmicalculator.addActionListener(this);
jmiabout.addActionListener(this);
jmiexit.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
String name = e.getActionCommand();
if (e.getSource() instanceof JMenuItem) {
if ("New".equals(name)) {
text.setText("");
file = null;
}
if ("Open".equals(name)) {
//需要你来填写
}
if ("Save".equals(name)) {
//需要你来填写
}
if ("Cut".equals(name)) {
text.cut();
}
if ("Copy".equals(name)) {
text.copy();
}
if ("Plaster".equals(name)) {
text.paste();
}
if ("All".equals(name)) {
text.selectAll();
}
if ("Font".equals(name)) {
}
if ("Color".equals(name)) {
color = JColorChooser.showDialog(MyNotepad.this, "", color);
text.setForeground(color);
}
if ("MS Notepad".equals(name)) {
try {
String command = "notepad.exe";
Process child = Runtime.getRuntime().exec(command);
}
catch (IOException ex) {
}
}
if ("MS Calculator".equals(name)) {
try {
String command = "calc.exe";
Process child = Runtime.getRuntime().exec(command);
}
catch (IOException ex) {
}
}
if ("Exit".equals(name)) {
System.exit(0);
}
if ("About".equals(name)) {
about.setLayout(new GridLayout(6, 1));
about.setTitle("Notepad About...");
about.setSize(320, 280);
about.getContentPane().setBackground(Color.yellow);
JLabel jlbfirst = new JLabel();
about.getContentPane().add(jlbfirst);
about.getContentPane().add(new JLabel("Notepad"));
about.getContentPane().add(new JLabel("Edition 1.0 (author:Tian Mingjun)"));
about.getContentPane().add(new JLabel("copyright possession (C) 2010.4.3."));
about.setModal(true);
about.show();
}
}
}
}