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) { } }

Virmach:1核/512M1核M1核512M/夏季美国vps促销,年付$7.2,9月更换AMD平台

virmach怎么样?virmach家这几年非常火,从商家的黑五闪购开始,以超低的价格吸引了大批的国人客户,而且商家的机器还是非常稳定的,站长手里的4.75刀年付已经用了两年了,非常稳定,不过商家到国内的线路一般,目前商家新上了夏季优惠促销,价格低到发指,年付7.2美元起,商家反馈将在9月开始更换AMD+NVMe平台,这个消息从年初就有了,不过一直没有更换,目前这个时间也不确定是否准确。点击进入:...

TMTHosting:夏季优惠,美国西雅图VPS月付7折,年付65折,美国服务器95折AS4837线路

tmthosting怎么样?tmthosting家本站也分享过多次,之前也是不温不火的商家,加上商家的价格略贵,之到斯巴达商家出现,这个商家才被中国用户熟知,原因就是斯巴达家的机器是三网回程AS4837线路,而且也没有多余的加价,斯巴达家断货后,有朋友发现TMTHosting竟然也在同一机房,所以大家就都入手了TMTHosting家的机器。目前,TMTHosting商家放出了夏季优惠,针对VPS推...

CloudCone:$17.99/年KVM-1GB/50GB/1TB/洛杉矶MC机房

CloudCone在月初发了个邮件,表示上新了一个系列VPS主机,采用SSD缓存磁盘,支持下单购买额外的CPU、内存和硬盘资源,最低年付17.99美元起。CloudCone成立于2017年,提供VPS和独立服务器租用,深耕洛杉矶MC机房,最初提供按小时计费随时退回,给自己弄回一大堆中国不能访问的IP,现在已经取消了随时删除了,不过他的VPS主机价格不贵,支持购买额外IP,还支持购买高防IP。下面列...

java文本编辑器为你推荐
大牛网大牛网怎么样a8处理器AMD A8处理器与I5比怎么样路由器映射路由器的端口映射是干嘛的,怎么使用?教育城域网怎样进入寿光教育城域网网站支付宝账单查询支付宝电子账单怎么查询小项目如何搞小工程招行信用卡还款招商银行信用卡有哪几个还款方式呢?摇一摇周边微信摇一摇周边红包设置code查询手机CODE查询海淀区公司注册在北京海淀区注册的有限责任公司,要增加自然人股东,需要准备哪些材料?
深圳域名空间 免费linux主机 5折 国外私服 wordpress技巧 2017年黑色星期五 dropbox网盘 合肥鹏博士 e蜗牛 网站木马检测工具 赞助 1g内存 卡巴斯基免费试用版 域名和主机 好看的空间 腾讯云平台 accountsuspended reboot paypal登陆 tracert 更多