j**a编的简单文本编辑器!!急求!!!不要网上随便搜的复制粘贴的!!!

求婚策划师Kiki 2024-05-24 09:46:22
最佳回答
import j**a.awt.*;import j**a.awt.event.*;import j**a.io.bufferedreader;import j**a.io.file;import j**a.io.filenotfoundexception;import j**a.io.filereader;import j**a.io.filewriter;import j**a.io.ioexception;import j**ax.swing.*;import j**ax.swing.filechooser.filenameextensionfilter;public class editorjframe extends jframe implements actionl**tener, mousel**tener{ private jcombobox combox_name, combox_size; //字体、字号组合框 private jradiobutton radiob_color[]; //颜色单选按钮 private jtextarea text; //文本区 private color color; //text的当前文本色 private jpopupmenu popupmenu; //快捷菜单 private **utton bopen,bs**e; //保存和打开 private jfilechooser fchooser; private object file; public editorjframe() { super("文本编辑器"); //默认borderlayout布局 dimension dim = gettoolkit().getscreensize(); //获得屏幕分辨率 th**.setbounds(dim.width/4,dim.height/4,dim.width/2,dim.height/4); //窗口居中 text = new jtextarea("welcome"); text.addmousel**tener(th**); //文本区注册鼠标事件** th**.getcontentpane().add(new jscrollpane(text)); //文本区添加到滚动窗格,滚动窗格添加到框架内容窗格中部 j** **=new j**(); //创建工具栏,默认水平方向 th**.getcontentpane().add(**,"north"); //工具栏添加到框架内容窗格北部 **utton bopen=new **utton("打开",new imageicon("open.txt"));//添加 bopen.addactionl**tener(th**); **.add(bopen); **utton bs**e=new **utton("保存",new imageicon("s**e.txt")); bs**e.addactionl**tener(th**); **.add(bs**e); //th**.file=**; string sizestr[]={"20","30","40","50","60","70"}; combox_size = new jcombobox(sizestr); //字号组合框 combox_size.addactionl**tener(th**); //组合框注册单击事件** **.add(combox_size); graphicsenvironment ge=graphicsenvironment.getlocalgraphicsenvironment(); string[] fontsname=ge.get**ailablefontfamilynames(); //获得系统字体 combox_name = new jcombobox(fontsname); //组合框显示系统字体 combox_name.addactionl**tener(th**); //组合框注册单击事件** **.add(combox_name); string colorstr[]={"红","绿","蓝","黑"}; buttongroup bgroup_color = new buttongroup(); //按钮组 radiob_color = new jradiobutton[colorstr.length]; //颜色单选按钮数组 for (int i=0; i<radiob_color.length; i++) { radiob_color[i]=new jradiobutton(colorstr[i]); //颜色单选按钮 radiob_color[i].addactionl**tener(th**); bgroup_color.add(radiob_color[i]); //单选按钮添加到按钮组 **.add(radiob_color[i]); //单选按钮添加到工具栏 } radiob_color[0].setselected(true); //设置单选按钮的选中状态 th**.addmymenu(); //调用自定义方法,添加菜单 th**.setv**ible(true); } private void addmymenu() //添加主菜单、快捷菜单、对话框 { jmenubar menubar = new jmenubar(); //菜单栏 th**.setjmenubar(menubar); //框架上添加菜单栏 string menustr[]={"文件","编辑"}; jmenu menu[]=new jmenu[menustr.length]; for (int i=0; i<menustr.length; i++) { menu[i] = new jmenu(menustr[i]); //菜单 menubar.add(menu[i]); //菜单栏中加入菜单 } jmenuitem menuitem_exit = new jmenuitem("新建"); menu[0].add(menuitem_exit); menuitem_exit.addactionl**tener(th**); jmenuitem menuitem_exit1 = new jmenuitem("打开"); menu[0].add(menuitem_exit1); //生成菜单项并加入到菜单 menuitem_exit1.addactionl**tener(th**); jmenuitem menuitem_exit2 = new jmenuitem("保存"); menu[0].add(menuitem_exit2); menuitem_exit2.addactionl**tener(th**); jmenuitem menuitem_exit3 = new jmenuitem("剪切"); menu[1].add(menuitem_exit3); //生成菜单项并加入到菜单 menuitem_exit3.addactionl**tener(th**); jmenuitem menuitem_exit4 = new jmenuitem("复制"); menu[1].add(menuitem_exit4); //生成菜单项并加入到菜单 menuitem_exit4.addactionl**tener(th**); jmenuitem menuitem_exit5 = new jmenuitem("粘贴"); menu[1].add(menuitem_exit5); //生成菜单项并加入到菜单 menuitem_exit5.addactionl**tener(th**); } public void actionperformed(actionevent e) //单击事件处理方法 { if(e.getactioncommand().equals("新建")) { th**.file=**; th**.text.settext(""); } if( e.getactioncommand().equals("打开"))//打开文件时操作 { try { jfilechooser choosefile=new jfilechooser("d:\\"); filenameextensionfilter filefilter=new filenameextensionfilter(".txt","txt"); choosefile.setfilefilter(filefilter);//文件过滤器 int re=choosefile.showopendialog(**); if(re==jfilechooser.approve_option) { string iorecord=""; file file=choosefile.getselectedfile(); if(filefilter.accept(file)) { filereader readfile=new filereader(file); bufferedreader readfile_ln=new bufferedreader(readfile); iorecord = readfile_ln.readline(); string s=""; while(iorecord!=**){ s+=iorecord+"\n"; iorecord=readfile_ln.readline(); } text.settext(s); }else joptionpane.show**dialog(**, "选择文件类型不正确"); } } catch (filenotfoundexception q) {q.printstacktrace();} catch(ioexception q){ q.printstacktrace(); } } if (e.getsource() instanceof jradiobutton) //选择一个颜色复选框 { if (e.getsource()==radiob_color[0]) color = new color(255,0,0); if (e.getsource()==radiob_color[1]) color = new color(0,255,0); if (e.getsource()==radiob_color[2]) color = new color(0,0,255); if (e.getsource()==radiob_color[3]) color = new color(0,0,0); text.setforeground(color); //设置文本区颜色 return; } if (e.getsource() instanceof jmenuitem) //单击菜单项 { if (e.getactioncommand()=="剪切") text.cut(); //将选中文本剪切送系统剪贴板 if (e.getactioncommand()=="复制") text.copy(); //将选中文本复制送系统剪贴板 if (e.getactioncommand()=="粘贴") text.paste(); //将剪贴板的文本粘贴在当前位置 return; } if (e.getactioncommand()=="保存") { //保存非空文件,不显示保存文件对话框 try{ filewriter out=new filewriter("d:\\l**t.txt"); out.write(text.gettext()); out.close(); joptionpane.show**dialog(**,"文件已经保存!"); system.exit(0); } catch(exception e1){ joptionpane.show**dialog(**, "文件 io 异常!"); } } if (e.getsource() instanceof jcombobox || e.getsource() instanceof jcheckbox ) { //组合框、复选框 int size=0; string fontname = (string)combox_name.getselecteditem();//获得字体名 size = integer.parseint((string)combox_size.getselecteditem());//获得字号 j**a.awt.font font = text.getfont(); //获得文本区的当前字体对象 int style = font.getstyle(); //获得字形 text.setfont(new font(fontname, style, size)); //设置文本区字体 } } //保存 public void mouseclicked(mouseevent mec) //鼠标事件处理方法,实现mousel**tener接口 { if (mec.getmodifiers()==mouseevent.button3_mask) //单击的是鼠标右键 popupmenu.show(text,mec.getx(),mec.gety()); //在鼠标单击处显示快捷菜单 } public void mousepressed(mouseevent mep) {} public void mousereleased(mouseevent mer) {} public void mouseentered(mouseevent mee) {} public void mouseexited(mouseevent mex) {} public void mousedragged(mouseevent med) {} public static void main(string arg[]) { new editorjframe(); }} 20210311
汇率兑换计算器

类似问答
  • 简易实用的视频编辑教程
    • 2024-05-24 06:35:28
    • 提问者: 未知
    1平时大家制作视频,不外乎就是把几个视频做成一个视频,或者给视频加个字幕,这两种需求在美册短视频专区都有对应的制作入口。比如“拼接视频”,就可以连接多段视频,在功能内,导入你要连接的视频,一次最多导入四段,底部可以剪切掉多余的部分,点击右上角对勾进入编辑页面。2编辑页面,导入的视频在屏幕上显示是上下拼接在一起的,点击模板,改为依次播放,视频就前后连在了一起,点击音量调整声音高低。编辑完成,点击合成...
  • 一位学生写了一首诗,送给慕名已久的编辑,但恰巧编辑不在家,于是他给编辑写了个便条...
    • 2024-05-24 23:09:19
    • 提问者: 未知
    市委采取有力措施,制止了群众揭发少数单位违反财经制度请客送礼的不良现象。b.现在市场...小说第四自然段看似闲笔,其实承上启下,引导故事情节自然发展,引发阅读兴趣。...
  • 本科生论文初稿很多复制粘贴,怎么降重?
    • 2024-05-24 03:38:16
    • 提问者: 未知
    初稿这样可以交吗?很高兴受邀请回答问题,我想从下面几方面进行介绍: 一、查重原理 1、知网学位论文检测为整篇上传,格式对检测结果可能会造成影响,需要将最终交稿格式提交检测,将影响降到...
  • 求j**a编程 二进制十进制互相转化
    • 2024-05-24 14:37:09
    • 提问者: 未知
    下面是十进制转换成二进制和二进制转换成十进制 根据你自己的需求选择 //10进制->2进制string a = "-1195";//输入数值biginteger src = new biginteger(a);//转换为biginteger类型system.out.println(src.tostring(2));//转换为2进制并输出结果//2进制->10进制st...
  • linux的vi编辑器
    • 2024-05-24 17:14:31
    • 提问者: 未知
    如果你现在还没有退出终端的话,你试一下通过按上下键返回到你使用vi的那个时候,再通过vi进去看一下,好像你编的东西还在里面
  • 如何使用led 图文**编辑软件创建节目?
    • 2024-05-24 05:08:15
    • 提问者: 未知
    1安装 打开安装文件夹,双击“setup.exe”,开始安装 ledshow 2011选择需要安装的语言,如选择中文(**)。进入下一步。2 可在“选择安装文件夹”界面选择程序安装的文件夹。可通过“浏览”按钮进行文件夹的选择,点击“上一步”退回到安装向导欢迎界面,点击“下一步”进入“准备安装界面,继续安装3安装完成,点击“完成”按键退出安装向导。4打开桌面快捷方式,启动软件。《...
  • 标准编写的编写标准的基本要求
    • 2024-05-24 10:28:16
    • 提问者: 未知
    各类标准的编写方法是不相同的,但下列一些基本要求都必须遵循的,否则就不能保证标准的编写质量。标准中规定的技术指标、参数、公式以及其他内容都要正确可靠。规定的指标必须是以现代科学技术的综合成果和先进经验为基础,并经过严格的科学验证,精确的数学计算而得出的数据编写时,必须...
  • 编制审计报告的基本要求
    • 2024-05-24 22:04:23
    • 提问者: 未知
    1、审计报告应当内容完整,结构合理,观点明确,条理清楚,用词恰当,格式规范。2、审计组应当根据审计工作底稿以及相关资料,在综合分析、归类、整理、核对的基础上,编制审计报告征求意见稿。3、审计组组长应当对提出的审计报告的真实性负责。审计人员和审计组组长均不得将审计过程中查出的...
  • 报销单据粘贴要求
    • 2024-05-24 21:35:03
    • 提问者: 未知
    1一、**或原始单据从右到左,先小张后大张粘贴。粘贴时请切勿使用双面胶。2二、 粘贴的**与粘贴单上下、左右对齐,不可超过贴贴单上下及左右边界,每张**约错开1厘米左右的距离,**呈鱼鳞状分布。3三、每张粘贴单粘贴**10-15张左右(餐费和车费可适当增加到15-20张),粘贴**或原始单据总的要求是分类粘贴,粘贴单整齐、平整、均匀。4四、当遇到**面积较大,超过粘贴单上下限或左右限,则以可见**...
  • 急!!! 求一篇中小企业人资经理的职位说明书,不要复制粘贴的啊!!
    • 2024-05-24 08:47:19
    • 提问者: 未知
    工作内容:制定并提交本部门年度工作计划、人员计划;负责本部门员工的考评,培训指导、选拔人才;编制公司人力资源战略规划,审核年度招聘计划并监督落实健全公司人力资源管理制度并监督实施;组织对公司各部门的定岗定编工作;参加对应聘人员的面试并签署部门意见;指导各对外投资控股企业招聘计划的的实施;建立公司内部人才的分类及梯队体系,制定员工职业生涯发展计划;负责公司紧缺人才的考察和引进工作;建立员工的综合考察...
汇率兑换计算器

热门推荐
热门问答
最新问答
推荐问答
新手帮助
常见问题
房贷计算器-九子财经 | 备案号: 桂ICP备19010581号-1 商务联系 企鹅:2790-680461

特别声明:本网为公益网站,人人都可发布,所有内容为会员自行上传发布",本站不承担任何法律责任,如内容有该作者著作权或违规内容,请联系我们清空删除。