java 记事本全选_java 编写的记事本程序怎么实现复制 黏贴 剪切 全选的功能 ?...
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
import javax.swing.*;import java.awt.event.*;import java.io.*;import java.awt.*;public class zuoye10_4_5{ public static void main(String args[]){ FirstWindow win=new FirstWindow(""); }}class FirstWindow extends JFrame implements ActionListener{ JMenuBar menubar; JMenu menu,menu1,menu2; JMenuItem dakai,baocun,quanxuan,tuichu,itemCopy,itemCut,itemPaste,zidonghuanhang,Backcolor,Forecolor; JTextArea text; JFileChooser fileChooser; FirstWindow(String s){ setSize(800,500); setLocation(120,120); setVisible(true); fileChooser=new JFileChooser("c:/"); //buttonFile=new JButton("打开文件"); menubar=new JMenuBar(); menu=new JMenu("文件"); dakai=new JMenuItem("打开"); baocun=new JMenuItem("保存"); quanxuan=new JMenuItem("全选"); tuichu=new JMenuItem("退出"); menu1=new JMenu("编辑"); itemCopy=new JMenuItem("复制"); itemCut=new JMenuItem("剪切"); itemPaste=new JMenuItem("粘贴"); menu2=new JMenu("格式"); zidonghuanhang=new JMenuItem("自动换行"); Backcolor=new JMenuItem("背景颜色"); Forecolor=new JMenuItem("字体颜色"); dakai.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,InputEvent.CTRL_MASK)); baocun.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK)); quanxuan.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A,InputEvent.CTRL_MASK)); itemCopy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK)); itemCut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,InputEvent.CTRL_MASK)); itemPaste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,InputEvent.CTRL_MASK)); text=new JTextArea(10,10); menu.add(dakai); menu.addSeparator(); menu.add(baocun); menu.addSeparator(); menu.add(quanxuan); menu.addSeparator(); menu.add(tuichu); menubar.add(menu); menu1.add(itemCopy); menu1.addSeparator(); menu1.add(itemCut); menu1.addSeparator(); menu1.add(itemPaste); menubar.add(menu1); menu2.add(zidonghuanhang); menu2.addSeparator(); menu2.add(Backcolor); menu2.addSeparator(); menu2.add(Forecolor); menubar.add(menu2); add(text); //add(buttonFile,BorderLayout.NORTH); add(new JScrollPane(text),BorderLayout.CENTER); setJMenuBar(menubar); dakai.addActionListener(this); baocun.addActionListener(this); quanxuan.addActionListener(this); tuichu.addActionListener(this); itemCopy.addActionListener(this); itemCut.addActionListener(this); itemPaste.addActionListener(this); zidonghuanhang.addActionListener(this); Backcolor.addActionListener(this); Forecolor.addActionListener(this); //buttonFile.addActionListener(this); validate(); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); } public void actionPerformed(ActionEvent e){ try{ if(e.getSource()==dakai){ text.setText(null); int n=fileChooser.showOpenDialog(null); if(n==JFileChooser.APPROVE_OPTION){ File file=fileChooser.getSelectedFile(); FileReader rfile=new FileReader(file); BufferedReader inTwo=new BufferedReader(rfile); String s=null; while((s=inTwo.readLine())!=null) //text.setText(s); text.append(s+'\n'); } } else if(e.getSource()==baocun){ //File file=new File("hello.text"); //FileWriter tofile=new FileWriter("hello.txt"); //char b[]=text.getText().toCharArray();//获取文本域中的内容并且存在数组B中; //tofile.write(b,0,b.length); //tofile.close(); int n=fileChooser.showSaveDialog(null); if(n==JFileChooser.APPROVE_OPTION){ File file=fileChooser.getSelectedFile(); FileWriter wFile=new FileWriter(file); wFile.write(text.getText()); wFile.close(); } } else if(e.getSource()==quanxuan) text.selectAll(); else if(e.getSource()==tuichu) System.exit(0); else if(e.getSource()==itemCopy) text.copy(); else if(e.getSource()==itemCut) text.cut(); else if(e.getSource()==itemPaste) text.paste(); else if(e.getSource()==zidonghuanhang) text.setLineWrap(true); else if(e.getSource()==Backcolor){ Color newColor=JColorChooser.showDialog(this,"调色板",Backcolor.getBackground()); if(newColor!=null) text.setBackground(newColor); } else if(e.getSource()==Forecolor){ Color newColor=JColorChooser.showDialog(this,"调色板",Forecolor.getBackground()); if(newColor!=null) text.setForeground(newColor); } } catch(IOException ee){} }
}
java 记事本全选_java 编写的记事本程序怎么实现复制 黏贴 剪切 全选的功能 ?...相关推荐
- java记事本课程设计_Java课程设计记事本的功能实现课程论文附代码
主要内容: 1设计背景 现在随着计算机科学日渐成熟,其强大的功能已经为人们深刻认识,它已经入人类社会的各个领域并发挥着越来越重要的作用,记事本是日常生活中常用到的工具,用户可以在其中方便地输入文字,从 ...
- java怎么实现购物车_java实现网上购物车程序
导读热词 用java代码写一个简单的网上购物车程序,供大家参考,具体内容如下 需求: 1.写一个商品类,有商品编号.商品名称.商品分类.商品单价属性. 2.写一个商品条目信息类,有商品和数量两个属性, ...
- linux qt应用程序全屏,QT中MDI应用程序中更改子窗口大小或是全屏显示子窗口的方法...
1.QT中窗口部件QWidget成员函数showFullScreen();是用于将窗口部件全屏显示. 但是他只对窗口模式的部件有用.子窗口的特征是 Qt::SubWindow,不是独立的窗口.因此对其 ...
- java数字计算结果_Java编写程序之输入一个数字实现该数字阶乘的计算
需求说明: 编写Java程序,输入一个数字,实现该数字阶乘的计算.一个数字的阶乘是所有小于及等于该数的正整数的积,自然数n的阶乘写作n! .例如,5的阶乘等于1*2*3*4*5,表示为5! = 120 ...
- java算术测试软件_Java——编写一个算术测试小软件
问题描述: 编写一个算术测试小软件,用来训练小学生的算术能力.程序由3个类组成,其中Teacher类对象负责给出算术题目,并判断回答者的答案是否正确:ComputerFrame类对象提供的GUI界面看 ...
- java计算器界面布局_java编写计算器界面
展开全部 以前32313133353236313431303231363533e78988e69d8331333262363038我自己的实验作业 import java.awt.*; import ...
- java词法分析器 c语言_Java编写的C语言词法分析器
这是java编写的C语言词法分析器,我也是参考很多代码,然后核心代码整理起来,放在QQ空间和博客上,目的是互相学习借鉴,希望可以得到高手改进.这个词法分析器实现的功能有打开文件.保存文件.打开帮助文档 ...
- java打印6个偶数_Java编写一个应用程序,打印所有偶数从2到100
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 public static void main(String[] args) throws IOException { File file=new Fil ...
- java 写一个计算器_java编写一个计算器类
展开全部 import java.awt.BorderLayout; import java.awt.Color; import java.awt.GridLayout; import java.aw ...
最新文章
- MYSQL连接一段时间不操作后出现异常的解决方案
- 转:罗永浩给俞敏洪写的求职信
- jmeter 多机负载压测与服务器性能监测
- python教程:函数递归与生成器教程
- ubuntu开启端口_RChain节点运行无门槛教程(二)--Windows-Ubuntu
- ASP.NET中常用功能代码总结(3)——上传图片到数据库
- my batis plus 小数没有0_Excel中的数据去掉小数点,教你3个函数解决!
- java 403怎么抛出_django主动抛出403异常的方法详解
- ImportError: cannot import name ‘joblib‘
- gitlab+jenkins+sonar做代码质量分析
- 租号平台正在把“未成年”变成“大人”
- c语言基础知识 面试,c语言面试最必考的十道试题,求职必看!!!
- QuickGUI编辑器系列---从文件中读取并解析
- 深度学习之神经网络(二)
- 松下plc编程线usb驱动
- 大学计算机vb基础知识6,计算机基础课-VB6选择题汇编(2011-2016)
- Python爬虫爬取中国电影票房排行榜
- springboot基于协同过滤算法的书籍推荐毕业设计源码101555
- Vue history模式添加前缀 Nginx配置
- 寒假自学数学建模(2)相关系数