菜鸟求大神指教啊~~~怎么实现记事本的剪切、复制和粘贴,不要改源程序...在上面加就可以了...

shitoucyz 2012-12-19 08:52:08
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class MyFrame extends JFrame{
public MyFrame(String arg0) throws HeadlessException{
super(arg0);
this.setBounds(20, 20, 400, 300);
JMenuBar jmb=new JMenuBar();

JMenu jm1=new JMenu("文件");
JMenu jm2=new JMenu("编辑");

JMenuItem jmi11=new JMenuItem("打开");
JMenuItem jmi12=new JMenuItem("保存");
JMenuItem jmi13=new JMenuItem("退出");
JMenuItem jmi14=new JMenuItem("剪切");
JMenuItem jmi15=new JMenuItem("复制");
JMenuItem jmi16=new JMenuItem("粘贴");

jm1.add(jmi11);
jm1.add(jmi12);
jm1.add(jmi13);

jm2.add(jmi14);
jm2.add(jmi15);
jm2.add(jmi16);

jmb.add(jm1);
jmb.add(jm2);

this.setJMenuBar(jmb);


jmi11.addActionListener(new ActionListener(){ //打开
public void actionPerformed(ActionEvent arg0){
JFileChooser jfc=new JFileChooser();
jfc.showOpenDialog(null);
}
});


jmi12.addActionListener(new ActionListener(){ //保存
public void actionPerformed(ActionEvent arg0){
JFileChooser jfc1=new JFileChooser();
jfc1.showSaveDialog(null);

}
});
jmi13.addActionListener(new ActionListener(){ //退出
public void actionPerformed(ActionEvent arg0){
JOptionPane.showMessageDialog(null, arg0.getActionCommand(), "exit", JOptionPane.QUESTION_MESSAGE);
}
});
jmi14.addActionListener(new ActionListener(){ //剪切
public void actionPerformed(ActionEvent arg0){


}
});
jmi15.addActionListener(new ActionListener(){ //复制
public void actionPerformed(ActionEvent arg0){

}
});
jmi16.addActionListener(new ActionListener(){ //粘贴
public void actionPerformed(ActionEvent arg0){

}
});


this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextArea jt=new JTextArea();
this.setLayout(new BorderLayout());
this.add(jt, BorderLayout.CENTER);
this.setVisible(true);

}
public static void main(String[] args) {
// TODO Auto-generated method stub
MyFrame a=new MyFrame("记事本");



}

}
...全文
112 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
shitoucyz 2012-12-19
  • 打赏
  • 举报
回复
引用 1 楼 liu4626846 的回复:
将你的JTextArea jt=new JTextArea();申明到全局作用域 jt.cut(); //剪切 jt.copy();//复制 jt.paste();//粘贴
谢谢啦~~~
shitoucyz 2012-12-19
  • 打赏
  • 举报
回复
引用 1 楼 liu4626846 的回复:
将你的JTextArea jt=new JTextArea();申明到全局作用域 jt.cut(); //剪切 jt.copy();//复制 jt.paste();//粘贴
还是不懂啊~~~怎么申明?
liu4626846 2012-12-19
  • 打赏
  • 举报
回复
将你的JTextArea jt=new JTextArea();申明到全局作用域 jt.cut(); //剪切 jt.copy();//复制 jt.paste();//粘贴

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧