java文本编辑器java jfilechooser 文本编辑器

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

麻烦高手推荐几款比较适合初学者编写JAVA程序的文本编辑器?

notepad++ //一个支持多种语言的文本编辑器,带有代码提示、语法高亮功能! editplus //支持Java语言。

有语法高亮功能。

没有代码提示! ultraedit //同editplus

用JAVA设计一个简单文本编辑器

import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.event.*; import java.util.*; //Date needed import java.io.PrintWriter; public class NotePad extends JFrame { JTextArea jta; class newl implements ActionListener { public void actionPerformed(ActionEvent e) { jta.setText(""); } } class openl implements ActionListener { public void actionPerformed(ActionEvent e) { JFileChooser jf=new JFileChooser(); jf.showOpenDialog(NotePad.this); } } //保存文件的监听 class savel implements ActionListener { public void actionPerformed(ActionEvent e) { JFileChooser jf = new JFileChooser(); jf.showSaveDialog(NotePad.this); } } //打印的监听 ? class printl implements ActionListener { public void actionPerformed(ActionEvent e) { // PrintWriter p = new PrintWriter(NotePad.this); } } //退出记事本的监听 class exitl implements ActionListener { public void actionPerformed(ActionEvent e) { System.exit(0);//退出 } } //拷贝的监听 class copyl implements ActionListener { public void actionPerformed(ActionEvent e) { jta.copy(); } } //粘贴的监听 class pastel implements ActionListener { public void actionPerformed(ActionEvent e) { jta.paste(); } } //剪切的监听 class cutl implements ActionListener { public void actionPerformed(ActionEvent e) { jta.cut(); } } //查找的监听 //添加日期的监听 class datel implements ActionListener { public void actionPerformed(ActionEvent e) { Date d=new Date(); jta.append(d.toString()); } } //构造函数 public NotePad() { jta=new JTextArea("",24,40); JScrollPane jsp=new JScrollPane(jta); JMenuBar jmb=new JMenuBar(); JMenu mFile=new JMenu("File"); JMenu mEdit=new JMenu("Edit"); JMenuItem mNew=new JMenuItem("New",KeyEvent.VK_N); mNew.addActionListener(new newl()); mFile.add(mNew); JMenuItem mOpen=new JMenuItem("Open",KeyEvent.VK_O); mOpen.addActionListener(new openl()); mFile.add(mOpen); JMenuItem mSave=new JMenuItem("Save"); mSave.addActionListener(new savel()); mFile.add(mSave); mFile.addSeparator(); //添加分割线 JMenuItem mPrint = new JMenuItem("Print"); mPrint.addActionListener(new printl()); mFile.add(mPrint); mFile.addSeparator(); //添加分割线 JMenuItem mExit=new JMenuItem("Exit"); mExit.addActionListener(new exitl()); mFile.add(mExit); mFile.setMnemonic(KeyEvent.VK_F); //编辑菜单的子菜单的处理 JMenuItem jmi; jmi=new JMenuItem("Copy"); jmi.addActionListener(new copyl()); mEdit.add(jmi); jmi=new JMenuItem("Cut"); jmi.addActionListener(new cutl()); mEdit.add(jmi); jmi=new JMenuItem("Paste"); jmi.addActionListener(new pastel()); mEdit.add(jmi); mEdit.addSeparator(); //添加分割线 jmi=new JMenuItem("Find"); mEdit.add(jmi); jmi=new JMenuItem("FindNext"); mEdit.add(jmi); mEdit.addSeparator(); jmi=new JMenuItem("Select All"); mEdit.add(jmi); jmi=new JMenuItem("Date/Time"); jmi.addActionListener(new datel()); mEdit.add(jmi); jmb.add(mFile); jmb.add(mEdit); this.setJMenuBar(jmb); this.getContentPane().add(jsp); this.setSize(200,200); this.setVisible(true); } //主函数,程序入口点 public static void main(String s[]) { new NotePad(); } }

求java做一个文本编辑器,要求如下,缺一不可,如果可以追加悬赏100分!!

public class MyEditor { public static void main(String[] args) { new EditorFrame(); } } import java.awt.Dimension; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.Reader; import java.util.StringTokenizer; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JScrollPane; import javax.swing.JTextArea; public class EditorFrame extends JFrame implements ActionListener{ private JMenuBar bar = null; private JMenu f = null; private JMenuItem newf = null; private JMenuItem openf = null; private JMenuItem savef = null; private JMenuItem saveAs = null; private JMenuItem exit = null; private JMenu tool = null; private JMenuItem edit = null; private JMenuItem run = null; private JMenu help = null; private JMenuItem about = null; private JTextArea txt = null; private File file = null; public EditorFrame(){ f = new JMenu("File"); newf = new JMenuItem("New"); newf.addActionListener(this); f.add(newf); openf = new JMenuItem("Open"); openf.addActionListener(this); f.add(openf); savef = new JMenuItem("Save"); savef.addActionListener(this); f.add(savef); saveAs = new JMenuItem("Save As"); saveAs.addActionListener(this); f.add(saveAs); exit = new JMenuItem("Exit"); exit.addActionListener(this); f.add(exit); tool = new JMenu("Tool"); edit = new JMenuItem("Edit"); edit.addActionListener(this); tool.add(edit); run = new JMenuItem("Run"); run.addActionListener(this); tool.add(run); help = new JMenu("Help"); about = new JMenuItem("About Java Text Editor"); about.addActionListener(this); help.add(about); bar = new JMenuBar(); bar.add(f); bar.add(tool); bar.add(help); txt = new JTextArea(); txt.setEditable(false); txt.setPreferredSize(new Dimension(780,600)); this.setTitle("Java Text Editor"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); this.setSize(800,700); Dimension displaySize = Toolkit.getDefaultToolkit().getScreenSize(); this.setLocation((displaySize.width - this.getWidth()) / 2, (displaySize.height - this.getHeight()) / 2); this.setJMenuBar(bar); this.add(new JScrollPane(txt)); } private void savefile(File fn){ String content = this.txt.getText(); try { PrintWriter writer = new PrintWriter(new FileWriter(fn)); StringTokenizer token = new StringTokenizer(content," "); while(token.hasMoreTokens()){ writer.println(token.nextToken()); writer.flush(); } writer.close(); } catch (IOException e1) { e1.printStackTrace(); } } private void saveFileAs(){ JFileChooser fc = new JFileChooser(); int flag = fc.showSaveDialog(this); if (flag == JFileChooser.APPROVE_OPTION) { String name = fc.getSelectedFile().getParent() + "\" + fc.getSelectedFile().getName() + ".txt"; System.out.println(name); this.file = new File(name); savefile(this.file); } } @Override public void actionPerformed(ActionEvent e) { this.txt.setEditable(false); if(e.getSource() == newf){ this.file = null; this.txt.setText(""); JOptionPane.showMessageDialog(this, "Please input your content in the text area."); this.txt.setEditable(true); } else if(e.getSource() == openf){ this.txt.setText(""); JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); int flag = fc.showOpenDialog(this); if(flag ==JFileChooser.APPROVE_OPTION){ this.file = fc.getSelectedFile(); try { Reader in = new InputStreamReader(new FileInputStream(this.file)); int tempbyte; String str = ""; while ((tempbyte = in.read()) != -1) { str += (char)tempbyte; } in.close(); this.txt.setText(str); } catch (IOException e1) { e1.printStackTrace(); } } }else if(e.getSource() == savef){ if(JOptionPane.showConfirmDialog(this, "Are you sure that you want to save the change?") == JOptionPane.YES_OPTION){ if(this.file == null){ saveFileAs(); }else{ savefile(this.file); } } }else if(e.getSource() == saveAs){ saveFileAs(); }else if(e.getSource() == exit){ this.dispose(); }else if(e.getSource() == edit){ this.txt.setEditable(true); }else if(e.getSource() == about){ AboutFrame.getFrame(); } } } import java.awt.Color; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import javax.swing.JFrame; import javax.swing.JLabel; public class AboutFrame extends JFrame implements WindowListener{ private JLabel lbl = null; private static AboutFrame instance = null; private AboutFrame(){ this.setTitle("About This Editor"); this.setSize(250,100); this.lbl = new JLabel("This is a text editor implemented by java."); this.lbl.setForeground(Color.BLUE); this.add(lbl); this.addWindowListener(this); //this.setVisible(true); } public static AboutFrame getFrame(){ if(instance == null){ instance = new AboutFrame(); } instance.setVisible(true); return instance; } @Override public void windowOpened(WindowEvent e) { } @Override public void windowClosing(WindowEvent e) { this.setVisible(false); } @Override public void windowClosed(WindowEvent e) { } @Override public void windowIconified(WindowEvent e) { } @Override public void windowDeiconified(WindowEvent e) { } @Override public void windowActivated(WindowEvent e) { } @Override public void windowDeactivated(WindowEvent e) { } }

java jfilechooser 文本编辑器

保存(另存)的话还是用FileDialog吧。

写个方法,在另存为时直接调用就OK了,如下: public void saveAs() { try { FileDialog fd = new FileDialog(frame, "另存为", FileDialog.SAVE);//frame为所依附的窗体 fd.setVisible(true); FileOutputStream out = new FileOutputStream(fd.getDirectory() + fd.getFile() + ".txt");//存为.txt格式,文件名为你输入的字符串 String str = ta.getText(); for (int n = 0; n < str.length(); n++) { out.write((byte) str.charAt(n)); } out.close(); } catch (Exception ess) { } }

小欢互联19元/月起, 即日起至10月底 美国CERA 促销活动 美国/香港八折

小欢互联成立于2019年10月,主打海外高性价比云服务器、CDN和虚拟主机服务。近期上线了自营美国CERA机房高速VPS,进行促销活动,为客户奉上美国/香港八折优惠码:Xxc1mtLB优惠码适用于美国CERA一区/二区以及香港一区/二区优惠时间:即日起至10月底优惠码可无限次使用,且续费同价!官网:https://idc.xh-ws.com购买地址:美国CERA一区:https://idc.xh-...

Hosteons:洛杉矶/纽约/达拉斯免费升级10Gbps端口,KVM年付21美元起

今年1月的时候Hosteons开始提供1Gbps端口KVM架构VPS,目前商家在LET发布消息,到本月30日之前,用户下单洛杉矶/纽约/达拉斯三个地区机房KVM主机可以从1Gbps免费升级到10Gbps端口,最低年付仅21美元起。Hosteons是一家成立于2018年的国外VPS主机商,主要提供VPS、Hybrid Dedicated Servers及独立服务器租用等,提供IPv4+IPv6,支持...

数脉科技8月促销,新客减400港币,BGP、CN2+BGP、阿里云线路低至350元

数脉科技(shuhost)8月促销:香港独立服务器,自营BGP、CN2+BGP、阿里云线路,新客立减400港币/月,老用户按照优惠码减免!香港服务器带宽可选10Mbps、30Mbps、50Mbps、100Mbps带宽,支持中文本Windows、Linux等系统。官方网站:https://www.shuhost.com* 更大带宽可在选购时选择同样享受优惠。* 目前仅提供HKBGP、阿里云产品,香港...

java文本编辑器为你推荐
rtfrtf是什么格式fast路由器FAST/迅捷无线路由器怎么设置win10发布win10发布到底是中国时间7月29号还是美国时间路由器映射路由器映射是什么意思教学视频网站谁有各种教学视频网站呀.?里程碑2求摩托罗拉里程碑2的优缺点,及性能简介java变量设置java的环境变量设置警告本网站内容如何去掉安全警告提示,是否只查看安全传送的网页内容安全网络攻防大赛CTF是什么意思fshow悬木铃是什么植物
com域名注册1元 vps虚拟服务器 n点虚拟主机管理系统 wordpress主机 westhost softlayer diahosting rackspace patcha 促正网秒杀 刀片服务器是什么 天翼云盘 我的世界服务器ip 独立主机 架设代理服务器 cx域名 hosting 免费服务器 日本小学生 shuangshiyi 更多