java文本编辑器用java编写一个体现菜单功能的文本编辑器。

java文本编辑器  时间:2021-09-15  阅读:()

JAVA什么可以编辑文本和图片

Java Swing里面有富文本编辑器 JTextPane,不过用法比JTextArea复杂多了, 能够插入图片,设置字体属性之类了。

至于要插入Flash的话,单独的一个组件是可以做到的,建议去网上搜索一下JDIC,是Sun针对Windows开发的一个组件包,其中包括一个Web Browser,是一个组件,设置他的html内容就能显示出来,是使用IE内核的。

将flash嵌入网页的代码使用,具体的语法自己查下吧。

文本编辑器(手机)Java

自己写的,能实现基本功能: import java.awt.BorderLayout; import java.awt.FileDialog; import java.awt.Font; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.Transferable; import java.awt.datatransfer.UnsupportedFlavorException; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.border.TitledBorder; /*因为根据个人的电脑路径可能有所偏差,没有源路径的情况下,设置默认保存路径为D盘根目录下 * 若要选择保存其他地方,可以选择 另存为*/ public class TestDemo extends JFrame { private static final long serialVersionUID = -5355432125621015300L; private String url = null;//文件路径 private String str=null;//复制或剪切 的字符串 private StringSelection stringSelection=null; private Clipboard clipboard=new Clipboard(str); private Transferable transferable=null; private DataFlavor flavor=null; public TestDemo() { init(); } private void init() { setTitle("我的记事本"); setSize(500, 600); setContentPane(createContentPane());//添加主面板 } /*创建主面板*/ private JPanel createContentPane() { JPanel pane = new JPanel(new BorderLayout()); pane.add(BorderLayout.NORTH, createChocePane());//添加菜单栏 pane.add(createAreaPane());//添加文本编辑区域 return pane; } /*创建菜单栏,以及实现功能*/ private JPanel createChocePane() { JPanel pane = new JPanel(); JMenuBar menuBar1 = new JMenuBar(); JMenu menu = new JMenu("文件"); menuBar1.add(menu); JMenuItem menuIt1 = new JMenuItem("新建"); JMenuItem menuIt2 = new JMenuItem("打开"); JMenuItem menuIt3 = new JMenuItem("保存"); JMenuItem menuIt4 = new JMenuItem("另存为"); menu.add(menuIt1); menu.add(menuIt2); menu.add(menuIt3); menu.add(menuIt4); JMenuBar menuBar2 = new JMenuBar(); JMenu menu2 = new JMenu("编辑"); menuBar2.add(menu2); JMenuItem menuIt5 = new JMenuItem("复制"); JMenuItem menuIt6 = new JMenuItem("剪切"); JMenuItem menuIt7 = new JMenuItem("粘帖"); menu2.add(menuIt5); menu2.add(menuIt6); menu2.add(menuIt7); JMenuBar menuBar3 = new JMenuBar(); JMenu menu3 = new JMenu("帮助"); menuBar3.add(menu3); JMenuItem menuIt8 = new JMenuItem("关于记事本"); menu3.add(menuIt8); pane.add(menuBar1); pane.add(menuBar2); pane.add(menuBar3); menuIt1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { testArea.setText(null); } }); menuIt2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { final FileDialog fd = new FileDialog(new JFrame(), "查找文件", FileDialog.LOAD); fd.setVisible(true); if (fd.getDirectory() != null && fd.getFile() != null) { testArea.setText(null); url = fd.getDirectory() + fd.getFile(); try { BufferedReader in = new BufferedReader(new FileReader( url)); for (int i = 0;; i++) { testArea.append(in.readLine()); if (in.read() == -1) { break; } else continue; } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } }); menuIt3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (url==null) { url="D:\新建 文本文档.txt"; } File f = new File(url); BufferedWriter out = null; try { out = new BufferedWriter(new FileWriter(url)); f.createNewFile(); out.append(testArea.getText()); out.flush(); } catch (IOException e1) { e1.printStackTrace(); } finally { try { out.close(); } catch (IOException e1) { e1.printStackTrace(); } } } }); menuIt4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { FileDialog fd = new FileDialog(new JFrame(), "保存文本", FileDialog.SAVE); fd.setVisible(true); if (url!=null) { File f = new File(url); BufferedWriter out = null; try { f.createNewFile(); out = new BufferedWriter(new FileWriter(url)); out.append(testArea.getText()); out.flush(); } catch (IOException e) { e.printStackTrace(); } finally { try { out.close(); } catch (IOException e) { e.printStackTrace(); } } } } }); menuIt5.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { str=testArea.getSelectedText(); stringSelection=new StringSelection(str); clipboard.setContents(stringSelection, null); } }); menuIt6.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { str=testArea.getSelectedText(); stringSelection=new StringSelection(str); clipboard.setContents(stringSelection, null); int start=testArea.getSelectionStart(); int end=testArea.getSelectionEnd(); testArea.replaceRange( null,start,end); } }); menuIt7.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { transferable=clipboard.getContents(this); flavor=DataFlavor.stringFlavor; if (transferable.isDataFlavorSupported(flavor)) { int start=testArea.getSelectionStart(); int end=testArea.getSelectionEnd(); testArea.replaceRange( null,start,end); int pos=testArea.getCaretPosition(); try { str=(String)transferable.getTransferData(flavor); testArea.insert(str, pos); } catch (UnsupportedFlavorException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } } } }); menuIt8.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null,"功能简单,绝对原创 "); } }); return pane; } JTextArea testArea; private JScrollPane createAreaPane() { JScrollPane pane = new JScrollPane(); pane.setBorder(new TitledBorder("编辑区域")); testArea = new JTextArea(); testArea.setFont(new Font("宋体", Font.BOLD, 13)); testArea.setLineWrap(true); pane.getViewport().add(testArea); return pane; } public static void main(String[] args) { TestDemo td = new TestDemo(); td.setVisible(true); } }

用java编写一个体现菜单功能的文本编辑器。

import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; public class MyTextEditor extends JFrame implements ActionListener,ItemListener,MouseListener { private File file; private JTextArea textarea; private JRadioButtonMenuItem rbmi_red,rbmi_blue,rbmi_green; private JMenuItem menuitem_copy,menuitem_cut,menuitem_paste,menuitem_seek; private JMenuItem menuitem_song,menuitem_fang,menuitem_kai;//字体变量 private JMenuItem menuitem_normal,menuitem_bold,menuitem_italic;//字形变量 private JMenuItem menuitem_20,menuitem_30,menuitem_40;//字号变量 private JMenuItem menuitem_exit,menuitem_infor; private JPopupMenu popupmenu; private JMenuItem menuitem_red,menuitem_green,menuitem_blue; private JDialog dialog,dialog1; private JButton button_seek; private JTextField textfield_seek; private JLabel label_seek,label_infor; String seek; public MyTextEditor() { super("文本编辑器"); this.setSize(400,300); this.setLocation(360,300); this.setDefaultCloseOperation(HIDE_ON_CLOSE); Container ss=this.getContentPane(); this.textarea = new JTextArea(); JScrollPane dd=new JScrollPane(textarea); ss.add(dd); textarea.addMouseListener(this); this.addMenu(); this.setVisible(true); this.Dialog(); this.Dialog1(); this.file = null; } public MyTextEditor(String filename) { this(); if (filename!=null) { this.file = new File(filename); this.setTitle(filename); this.textarea.setText(this.readFromFile()); } } public MyTextEditor(File file) { this(); if (file!=null) { this.file = file; this.setTitle(this.file.getName()); this.textarea.setText(this.readFromFile()); } } public void Dialog() //建立对话框的方法 { dialog=new JDialog(this,"查找",true); dialog.setLayout(new FlowLayout()); dialog.setSize(200,90); label_seek=new JLabel("查找内容"); dialog.add(label_seek); textfield_seek=new JTextField(10); dialog.add(textfield_seek); button_seek=new JButton("查找"); dialog.add(button_seek); button_seek.addActionListener(this); } public void Dialog1() { dialog1=new JDialog(this,"专利",true); dialog1.setLayout(new FlowLayout()); dialog1.setSize(200,100); label_infor=new JLabel("刘同虎制作"); dialog1.add(label_infor); } public void addMenu() { JMenuBar menubar = new JMenuBar(); this.setJMenuBar(menubar); JMenu menu_file = new JMenu("文件"); //文件菜单 menubar.add(menu_file); JMenuItem menuitem_open = new JMenuItem("打开"); menu_file.add(menuitem_open); menuitem_open.addActionListener(this); JMenuItem menuitem_save = new JMenuItem("保存"); menu_file.add(menuitem_save); menuitem_save.addActionListener(this); JMenuItem menuitem_saveas = new JMenuItem("另存为"); menu_file.add(menuitem_saveas); menuitem_saveas.addActionListener(this); menuitem_exit=new JMenuItem("退出" ); menu_file.add(menuitem_exit); menuitem_exit.addActionListener(this); menuitem_infor=new JMenuItem("信息"); menu_file.add(menuitem_infor); menuitem_infor.addActionListener(this); JMenu menu_editor=new JMenu("编辑");//编辑菜单 menubar.add(menu_editor); menuitem_seek=new JMenuItem("查找"); menu_editor.add(menuitem_seek); menuitem_seek.addActionListener(this); menuitem_copy=new JMenuItem("复制"); menuitem_copy.addActionListener(this); menu_editor.add(menuitem_copy); menuitem_cut=new JMenuItem("剪切"); menu_editor.add(menuitem_cut); menuitem_cut.addActionListener(this); menuitem_paste=new JMenuItem("粘贴"); menu_editor.add(menuitem_paste); menuitem_paste.addActionListener(this); JMenuItem menu_color=new JMenu("颜色");//颜色菜单 menu_editor.add(menu_color); ButtonGroup buttongroup=new ButtonGroup(); rbmi_red=new JRadioButtonMenuItem("红",true); buttongroup.add(rbmi_red); menu_color.add(rbmi_red); rbmi_red.addItemListener(this); rbmi_blue=new JRadioButtonMenuItem("蓝",true); buttongroup.add(rbmi_blue); menu_color.add(rbmi_blue); rbmi_blue.addItemListener(this); rbmi_green=new JRadioButtonMenuItem("绿",true); buttongroup.add(rbmi_green); menu_color.add(rbmi_green); rbmi_green.addItemListener(this); JMenu menu_font=new JMenu("设置字体");//设置字体菜单 menubar.add(menu_font); menuitem_song=new JMenuItem("宋体"); menu_font.add(menuitem_song); menuitem_song.addActionListener(this); menuitem_fang=new JMenuItem("仿宋"); menu_font.add(menuitem_fang); menuitem_fang.addActionListener(this); menuitem_kai=new JMenuItem("楷体"); menu_font.add(menuitem_kai); menuitem_kai.addActionListener(this); JMenu menu_style=new JMenu("设置字形");//设置字形菜单 menubar.add(menu_style); menuitem_bold=new JMenuItem("粗体"); menu_style.add(menuitem_bold); menuitem_bold.addActionListener(this); menuitem_italic=new JMenuItem("斜体"); menu_style.add(menuitem_italic); menuitem_italic.addActionListener(this); JMenu menu_size=new JMenu("设置字号"); //设置字号菜单 menubar.add(menu_size); menuitem_20=new JMenuItem("20"); menu_size.add(menuitem_20); menuitem_20.addActionListener(this); menuitem_30=new JMenuItem("30"); menu_size.add(menuitem_30); menuitem_30.addActionListener(this); menuitem_40=new JMenuItem("40"); menu_size.add(menuitem_40); menuitem_40.addActionListener(this); popupmenu=new JPopupMenu(); //快捷菜单 JMenuItem menuitem_red=new JMenuItem("红色"); popupmenu.add(menuitem_red); menuitem_red.addActionListener(this); JMenuItem menuitem_green=new JMenuItem("绿色"); popupmenu.add(menuitem_green); menuitem_green.addActionListener(this); menuitem_blue=new JMenuItem("蓝色"); popupmenu.add(menuitem_blue); menuitem_blue.addActionListener(this); textarea.add(popupmenu); //向文本区内添加快捷菜单 } public void writeToFile(String lines) //写文件 { try { FileWriter fout = new FileWriter(this.file); fout.write(lines+" "); fout.close(); } catch (IOException ioex) { return; } } public String readFromFile() //读文件 { try { FileReader fin = new FileReader(this.file); BufferedReader bin = new BufferedReader(fin); String aline="", lines=""; do { aline = bin.readLine(); if (aline!=null) lines += aline + " "; } while (aline!=null); bin.close(); fin.close(); return lines; } catch (IOException ioex) { return null; } }

BuyVM($5/月),1Gbps不限流量流媒体VPS主机

BuyVM针对中国客户推出了China Special - STREAM RYZEN VPS主机,带Streaming Optimized IP,帮你解锁多平台流媒体,适用于对于海外流媒体有需求的客户,主机开设在拉斯维加斯机房,AMD Ryzen+NVMe磁盘,支持Linux或者Windows操作系统,IPv4+IPv6,1Gbps不限流量,最低月付5加元起,比美元更低一些,现在汇率1加元=0.7...

Megalayer新加坡服务器国际带宽线路测评

前几天有关注到Megalayer云服务器提供商有打算在月底的时候新增新加坡机房,这个是继美国、中国香港、菲律宾之外的第四个机房。也有工单询问到官方,新加坡机房有包括CN2国内优化线路和国际带宽,CN2优化线路应该是和菲律宾差不多的。如果我们追求速度和稳定性的中文业务,建议还是选择CN2优化带宽的香港服务器。这里有要到Megalayer新加坡服务器国际带宽的测试服务器,E3-1230配置20M国际带...

艾云年付125元圣何塞GTT,洛杉矶vps年付85元

艾云怎么样?艾云是一家去年年底成立的国人主机商家,商家主要销售基于KVM虚拟架构的VPS服务,机房目前有美国洛杉矶、圣何塞和英国伦敦,目前商家推出了一些年付特价套餐,性价比非常高,洛杉矶套餐低至85元每年,给500M带宽,可解奈飞,另外圣何塞也有特价机器;1核/1G/20G SSD/3T/2.5Gbps,有需要的朋友以入手。点击进入:艾云官方网站艾云vps促销套餐:KVM虚拟架构,自带20G的防御...

java文本编辑器为你推荐
信件格式书信格式hotfix请问WINDOWS MEDIA PLAYER HOTFIX是什么程序,怎么无法卸载模糊数学模糊数学与人们常说的数学有何差别?谢谢按键精灵教程学按键精灵需要学些什么基础知识eofexceptionjava.io.EOFException这是个什么异常应该怎么解决开发者账号如何申请企业开发者账号nvidia官方网站N卡的官网是什么?0x800ccc0f错误号: 0x800CCC0F 这个是虾米意思?t320平板电脑三星 galaxy tab pro t320怎么样code查询怎么查code?
免费云主机 汉邦高科域名注册 唯品秀 特价空间 一点优惠网 建站代码 日本空间 e蜗牛 中国智能物流骨干网 免费申请网站 100mbps 如何建立邮箱 lick 免费的域名 浙江服务器 稳定空间 阿里云邮箱申请 asp空间 privatetracker 512内存 更多