java编写一个记事本小程序,接着下面的代码写,求大神解救!实现新建,保存,打开功能就行!
求大神解救,要怎么写,要写新建,保存,打开功能了!importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;...
求大神解救,要怎么写,要写新建,保存,打开功能了!
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class NotePad extends JFrame{
public static void main(String[] args) {
JFrame jFrame = new JFrame();
JMenuBar jmb = new JMenuBar();
JMenu jFile = new JMenu("文件");
JMenu jEdit = new JMenu("编辑");
JMenu jFormat = new JMenu("格式");
JMenu jView = new JMenu("查看");
JMenu jHelp = new JMenu("帮助");
JMenuItem jNew = new JMenuItem("新建 (N)");
JMenuItem jOpen = new JMenuItem("打开 (O)");
JMenuItem jSave = new JMenuItem("保存 (S)");
JMenuItem jSaveAs = new JMenuItem("另存为 (A)");
JMenuItem jExit = new JMenuItem("退出 (X)");
JMenuItem jChexiao = new JMenuItem("撤销 (Z)");
JMenuItem jJianqie = new JMenuItem("剪切 (D)");
JMenuItem jFuzhi = new JMenuItem("复制 (C)");
JMenuItem jZhantie = new JMenuItem("粘贴 (V)");
//文件
jNew.setAccelerator(KeyStroke.getKeyStroke('N',InputEvent.ALT_MASK));
jOpen.setAccelerator(KeyStroke.getKeyStroke('O',InputEvent.ALT_MASK));
jSave.setAccelerator(KeyStroke.getKeyStroke('S',InputEvent.ALT_MASK));
jSaveAs.setAccelerator(KeyStroke.getKeyStroke('A',InputEvent.ALT_MASK));
jExit.setAccelerator(KeyStroke.getKeyStroke('X',InputEvent.ALT_MASK));
//编辑
jChexiao.setAccelerator(KeyStroke.getKeyStroke('Z',InputEvent.ALT_MASK));
jJianqie.setAccelerator(KeyStroke.getKeyStroke('D',InputEvent.ALT_MASK));
jFuzhi.setAccelerator(KeyStroke.getKeyStroke('C',InputEvent.ALT_MASK));
jZhantie.setAccelerator(KeyStroke.getKeyStroke('V',InputEvent.ALT_MASK));
jmb.add(jFile);
jmb.add(jEdit);
jmb.add(jFormat);
jmb.add(jView);
jmb.add(jHelp);
jFile.add(jNew);
jFile.add(jOpen);
jFile.add(jSave);
jFile.add(jSaveAs);
jFile.addSeparator();
jFile.add(jExit);
jEdit.add(jChexiao);
jEdit.add(jJianqie);
jEdit.add(jFuzhi);
jEdit.add(jZhantie);
jExit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});
JTextArea jTextArea = new JTextArea();
JScrollPane jsp = new JScrollPane(jTextArea);
//jsp.add(jTextArea);
jFrame.setJMenuBar(jmb);
jFrame.setContentPane(jsp);
jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
//jFrame.pack();
jFrame.setBounds(200,100,400,400);
jFrame.setVisible(true);
}
} 展开
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class NotePad extends JFrame{
public static void main(String[] args) {
JFrame jFrame = new JFrame();
JMenuBar jmb = new JMenuBar();
JMenu jFile = new JMenu("文件");
JMenu jEdit = new JMenu("编辑");
JMenu jFormat = new JMenu("格式");
JMenu jView = new JMenu("查看");
JMenu jHelp = new JMenu("帮助");
JMenuItem jNew = new JMenuItem("新建 (N)");
JMenuItem jOpen = new JMenuItem("打开 (O)");
JMenuItem jSave = new JMenuItem("保存 (S)");
JMenuItem jSaveAs = new JMenuItem("另存为 (A)");
JMenuItem jExit = new JMenuItem("退出 (X)");
JMenuItem jChexiao = new JMenuItem("撤销 (Z)");
JMenuItem jJianqie = new JMenuItem("剪切 (D)");
JMenuItem jFuzhi = new JMenuItem("复制 (C)");
JMenuItem jZhantie = new JMenuItem("粘贴 (V)");
//文件
jNew.setAccelerator(KeyStroke.getKeyStroke('N',InputEvent.ALT_MASK));
jOpen.setAccelerator(KeyStroke.getKeyStroke('O',InputEvent.ALT_MASK));
jSave.setAccelerator(KeyStroke.getKeyStroke('S',InputEvent.ALT_MASK));
jSaveAs.setAccelerator(KeyStroke.getKeyStroke('A',InputEvent.ALT_MASK));
jExit.setAccelerator(KeyStroke.getKeyStroke('X',InputEvent.ALT_MASK));
//编辑
jChexiao.setAccelerator(KeyStroke.getKeyStroke('Z',InputEvent.ALT_MASK));
jJianqie.setAccelerator(KeyStroke.getKeyStroke('D',InputEvent.ALT_MASK));
jFuzhi.setAccelerator(KeyStroke.getKeyStroke('C',InputEvent.ALT_MASK));
jZhantie.setAccelerator(KeyStroke.getKeyStroke('V',InputEvent.ALT_MASK));
jmb.add(jFile);
jmb.add(jEdit);
jmb.add(jFormat);
jmb.add(jView);
jmb.add(jHelp);
jFile.add(jNew);
jFile.add(jOpen);
jFile.add(jSave);
jFile.add(jSaveAs);
jFile.addSeparator();
jFile.add(jExit);
jEdit.add(jChexiao);
jEdit.add(jJianqie);
jEdit.add(jFuzhi);
jEdit.add(jZhantie);
jExit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});
JTextArea jTextArea = new JTextArea();
JScrollPane jsp = new JScrollPane(jTextArea);
//jsp.add(jTextArea);
jFrame.setJMenuBar(jmb);
jFrame.setContentPane(jsp);
jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
//jFrame.pack();
jFrame.setBounds(200,100,400,400);
jFrame.setVisible(true);
}
} 展开
展开全部
package tuxingjiemian;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.PrintStream;
public class jishiben extends JFrame {
JPanel jp=new JPanel();
JFrame find_replace=new JFrame();
JMenu file=new JMenu("文件");
JMenu edit=new JMenu("编辑");
JMenu help=new JMenu("帮助");
JMenuBar menubar=new JMenuBar();
JTextArea aa=new JTextArea();
class Open implements ActionListener {
public void actionPerformed(ActionEvent e) {
JFileChooser jf= new JFileChooser();
jf.showOpenDialog(jishiben.this);
try {
PrintStream p=new PrintStream(jf.getSelectedFile().getPath());
} catch (Exception e2) {
}
}
}
class Save implements ActionListener {
public void actionPerformed(ActionEvent e) {
JFileChooser jf= new JFileChooser();
jf.showSaveDialog(jishiben.this);
try {
PrintStream p=new PrintStream(jf.getSelectedFile().getPath());
} catch (Exception e2) {
}
}
}
public jishiben(){
this.setTitle("记事本");
this.setSize(500, 500);
this.setLayout(new BorderLayout());
JMenuItem open=new JMenuItem("打开");
open.addActionListener(new Open());
JMenuItem save=new JMenuItem("保存");
save.addActionListener(new Save());
JMenuItem exit=new JMenuItem("退出");
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
file.add(open);
file.add(save);
file.addSeparator();
file.add(exit);
menubar.add(file);
this.add(new JScrollPane(aa),BorderLayout.CENTER);
JMenuItem copy=new JMenuItem("复制");
JMenuItem past=new JMenuItem("粘贴");
JMenuItem delete=new JMenuItem("删除");
JMenuItem find=new JMenuItem("查找");
JMenuItem replace=new JMenuItem("替换");
copy.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jishiben.this.aa.copy();
}
});
past.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jishiben.this.aa.paste();
}
});
delete.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jishiben.this.aa.replaceSelection(null);
}
});
edit.add(copy);
edit.add(past);
edit.add(delete);
edit.add(find);
edit.add(replace);
menubar.add(edit);
help.add(new JMenuItem("帮助"));
menubar.add(help);
this.add(menubar,BorderLayout.NORTH);
this.setVisible(true);
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new jishiben();
}
};
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.PrintStream;
public class jishiben extends JFrame {
JPanel jp=new JPanel();
JFrame find_replace=new JFrame();
JMenu file=new JMenu("文件");
JMenu edit=new JMenu("编辑");
JMenu help=new JMenu("帮助");
JMenuBar menubar=new JMenuBar();
JTextArea aa=new JTextArea();
class Open implements ActionListener {
public void actionPerformed(ActionEvent e) {
JFileChooser jf= new JFileChooser();
jf.showOpenDialog(jishiben.this);
try {
PrintStream p=new PrintStream(jf.getSelectedFile().getPath());
} catch (Exception e2) {
}
}
}
class Save implements ActionListener {
public void actionPerformed(ActionEvent e) {
JFileChooser jf= new JFileChooser();
jf.showSaveDialog(jishiben.this);
try {
PrintStream p=new PrintStream(jf.getSelectedFile().getPath());
} catch (Exception e2) {
}
}
}
public jishiben(){
this.setTitle("记事本");
this.setSize(500, 500);
this.setLayout(new BorderLayout());
JMenuItem open=new JMenuItem("打开");
open.addActionListener(new Open());
JMenuItem save=new JMenuItem("保存");
save.addActionListener(new Save());
JMenuItem exit=new JMenuItem("退出");
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
file.add(open);
file.add(save);
file.addSeparator();
file.add(exit);
menubar.add(file);
this.add(new JScrollPane(aa),BorderLayout.CENTER);
JMenuItem copy=new JMenuItem("复制");
JMenuItem past=new JMenuItem("粘贴");
JMenuItem delete=new JMenuItem("删除");
JMenuItem find=new JMenuItem("查找");
JMenuItem replace=new JMenuItem("替换");
copy.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jishiben.this.aa.copy();
}
});
past.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jishiben.this.aa.paste();
}
});
delete.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jishiben.this.aa.replaceSelection(null);
}
});
edit.add(copy);
edit.add(past);
edit.add(delete);
edit.add(find);
edit.add(replace);
menubar.add(edit);
help.add(new JMenuItem("帮助"));
menubar.add(help);
this.add(menubar,BorderLayout.NORTH);
this.setVisible(true);
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new jishiben();
}
};
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询