- 时间:2021-02-11 21:22 编辑:鲍嘉诚 来源:蚂蚁资源 阅读:234
- 扫一扫,手机访问
摘要:大家好,今天给大家介绍关于记事本源码(java记事本源代码)的相关内容,详细讲解如何用浏览器打开用记事本编写的代码,用html5编写手机记事本的纯代码文档,求简短vbs代码三个等,希望可以帮助到您。
如何用浏览器打开用记事本编写的代码,1.打开计算机,单击桌面上的鼠标,在菜单栏中选择“新建”,然后选择“文本文档”,创建“文本文档”; 2.右键单击新的“文本文档”文档后的文本,在菜单栏中的“打开模式”中,“使用记事本打开”,或将默认打开模式设置为“记事本”;想要编辑Web代码; 4.输入要编辑的Web代码后,可以单击“保存”按钮(您也可以按Ctrl + S快捷方式),或“另存为”; 5,在计算机桌面上找到编辑器已保存的文本文档,在右键单击菜单栏中选择“重命名”,将文档末尾的“.txt”格式更改为“.html”格式; 6,“.txt”格式在文档结束时更改为“.html”在“格式之后,文本文档图标将成为Web模式; 7.打开文本文本ENT转变为网页,您可以实现文本以编辑浏览器中的HTML。
用html5编写手机记事本的纯代码文档,单击Windows桌面上的[开始] - >选择[所有程序] - > [附件] - > [记事本],打开一个记事本。在打开的记事本中输入HTML代码,如下所示:编辑HTML文件后,选择[文件] - > [保存]或按Ctrl + S键键选择弹出窗口中的[保存为]对话框[保存“对话框类型]是[所有文件],然后将文件扩展名设置为.html或.htm。如下所示:步骤读取4单击[保存]以保存文件。浏览器预览,请移动另一个共享体验[使用浏览器查看HTML5文件]
求简短vbs代码三个,wscript.createobject(“sapi.spvoice”)。说“我爱你”wscript.createobject(“wscript.shell”)。运行“notepad.exe”msgbox“弹出提示”
责任编辑(
鲍嘉诚)
以上就是关于**记事本源码,java记事本源代码**的全部内容,了解更多请关注蚂蚁资源网。
- 郭大帅
- 求知道的大神告诉我该怎么用记事本输入代码,输入什么代码啊网页的吗???<html><head></head><body>hello word</body></html>这段代码复制到记事本,文件改成html或者直接用浏览器打开,就是一个网页
- 2021-02-11 21:22:45
- 远古
- 以下代码是一个完整的实现,你只要复制过去就可以了~~import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.*; import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.*; import java.text.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.undo.*; import javax.swing.text.*; public class Start { public static void main(String args[]) { new TextPad(); } } class TextPad extends JFrame implements ActionListener { JTextArea jta=new JTextArea("小廖记事本:)",18,52); JCheckBoxMenuItem mto1=new JCheckBoxMenuItem("自动换行",true); String ss1=jta.getText(); UndoableEditListener ue=new UndoHander(); UndoManager undo = new UndoManager(); int StartFindPos=0,a=0,b=0; GridBagConstraints gbc=new GridBagConstraints(); //Dimension dd=new Dimension(); // jta.getDocument().addUndoableEditListener(ue); public TextPad() { //MyMenuListener ml=new MyMenuListener(); //JTextArea jta=new JTextArea("This is my textpad",18,52); //System.out.println(dd.getHeight()); //System.out.println(dd.getWidth()); //System.out.println(this.getHeight()); //System.out.println(this.getWidth()); //System.out.println("OK"); this.setTitle("一个功能比较齐全的JAVA记事本"); this.setLocation(180,100); jta.setLineWrap(true); jta.setWrapStyleWord(true); JPanel jp=new JPanel(); JScrollPane jsp=new JScrollPane(jta); jp.add(jsp); //Rectangle rt=new Rectangle(0,0,this.getWidth(),this.getHeight()); //jsp.setBounds(rt); //System.out.println(this.getHeight()); //System.out.println(this.getWidth()); JMenu mf=new JMenu("文件(F)"); JMenuItem mtf1=new JMenuItem("新建"); mtf1.addActionListener(this); JMenuItem mtf2=new JMenuItem("打开"); //mtf2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,InputEvent.CTRL_MASK)); mtf2.addActionListener(this); JMenuItem mtf3=new JMenuItem("保存"); //mtf3.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK)); mtf3.addActionListener(this); JMenuItem mtf4=new JMenuItem("另存为"); mtf4.addActionListener(this); JMenuItem mtf5=new JMenuItem("退出"); mtf5.addActionListener(this); JMenu me=new JMenu("编辑(E)"); JMenuItem mte1=new JMenuItem("撤消"); mte1.addActionListener(this); jta.getDocument().addUndoableEditListener(ue); if(undo.canUndo()) { mte1.setEnabled(false); } JMenuItem mte2=new JMenuItem("剪切"); mte2.addActionListener(this); JMenuItem mte3=new JMenuItem("复制"); mte3.addActionListener(this); JMenuItem mte4=new JMenuItem("粘贴"); mte4.addActionListener(this); //JMenuItem mte5=new JMenuItem("删除"); //mte5.addActionListener(this); JMenuItem mte6=new JMenuItem("查找"); mte6.addActionListener(this); //JMenuItem mte7=new JMenuItem("查找下一个"); JMenuItem mte8=new JMenuItem("替换"); mte8.addActionListener(this); //JMenuItem mte9=new JMenuItem("转到"); JMenuItem mte10=new JMenuItem("全选"); mte10.addActionListener(this); JMenuItem mte11=new JMenuItem("日期/时间"); mte11.addActionListener(this); JMenu mo=new JMenu("格式(O)"); //JCheckBoxMenuItem mto1=new JCheckBoxMenuItem("自动换行(W)"); mto1.addActionListener(this); JMenuItem mto2=new JMenuItem("字体"); mto2.addActionListener(this); JMenu mv=new JMenu("查看(V)"); JMenuItem mtv1=new JMenuItem("状态栏"); mtv1.setEnabled(false); JMenu mh=new JMenu("帮助(H)"); JMenuItem mth1=new JMenuItem("关于记事本"); mth1.addActionListener(this); JMenuBar mb=new JMenuBar(); this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } ); mb.add(mf); mb.add(me); mb.add(mo); mb.add(mv); mb.add(mh); this.setJMenuBar(mb); mf.add(mtf1); mf.add(mtf2); mf.add(mtf3); mf.add(mtf4); mf.addSeparator(); mf.add(mtf5); me.add(mte1); me.addSeparator(); me.add(mte2); me.add(mte3); me.add(mte4); //me.add(mte5); me.addSeparator(); me.add(mte6); //me.add(mte7); me.add(mte8); //me.add(mte9); me.addSeparator(); me.add(mte10); me.add(mte11); mo.add(mto1); mo.add(mto2); mv.add(mtv1); mh.add(mth1); this.getContentPane().add(jsp); this.setSize(600,400); this.setResizable(true); this.setVisible(true); } public void actionPerformed(ActionEvent e) { if(e.getActionCommand().equals("打开")) { try { Frame f=new Frame(); FileDialog fd=new FileDialog(f,"打开文件",FileDialog.LOAD); fd.setVisible(true); String fpath=fd.getDirectory(); String fname=fd.getFile(); BufferedReader br=new BufferedReader(new FileReader(fpath+fname)); jta.setText(""); String s=br.readLine(); while(s!=null) { jta.append(s+"\n"); s=br.readLine(); } br.close(); } catch(Exception ex) { } } if(e.getActionCommand().equals("保存")) { String fns=null; Frame f=new Frame("保存"); FileDialog fd=new FileDialog(f,"保存文件",FileDialog.SAVE); fd.setFile("*.txt"); fd.setVisible(true); try { String savepath=fd.getDirectory(); String savename=fd.getFile(); if(savename!=null) { PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter(savepath+savename))); pw.write(jta.getText(),0,jta.getText().length()); pw.flush(); } } catch(Exception esave) { } } if(e.getActionCommand().equals("新建")) { jta.setText(""); } if(e.getActionCommand().equals("另存为")) { Frame f=new Frame("保存"); FileDialog fd=new FileDialog(f,"文件另存为",FileDialog.SAVE); fd.setVisible(true); try { String savepath=fd.getDirectory(); String savename=fd.getFile(); if(savename!=null) { PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter(savepath+savename))); pw.write(jta.getText(),0,jta.getText().length()); pw.flush(); } } catch(Exception esave) { } } if(e.getActionCommand().equals("退出")) { String ss2=jta.getText(); if(!ss1.equals(ss2)) { System.out.println("File is changed."); } System.exit(0); } if(e.getActionCommand().equals("撤消")) { try { undo.undo(); //System.out.println(undo.canUndo()); } catch(Exception eundo) { } } if(e.getActionCommand().equals("剪切")) { jta.cut(); } if(e.getActionCommand().equals("复制")) { jta.copy(); } if(e.getActionCommand().equals("粘贴")) { jta.paste(); } if(e.getActionCommand().equals("删除")) { } if(e.getActionCommand().equals("全选")) { jta.selectAll(); } if(e.getActionCommand().equals("查找")) { try { final JDialog jd=new JDialog(this,"查找",true); GridBagLayout gbl=new GridBagLayout(); GridBagConstraints gbc=new GridBagConstraints(); gbc.weightx=0.5; gbc.weighty=0.5; gbc.gridwidth=1; gbc.gridheight=1; jd.getContentPane().setLayout(gbl); jd.setSize(380,100); jd.setResizable(false); //jd.setDefaultLookAndFeelDecorated(true); final JTextField jtf=new JTextField(15); JLabel jlFind=new JLabel("查找内容:"); jd.getContentPane().add(jlFind); JButton jbFind=new JButton("查找"); jbFind.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent efind) { String strA=jta.getText(); String strB=jtf.getText(); if(a>=0) { a=strA.indexOf(strB,StartFindPos); b=strB.length(); StartFindPos=a+b; if(a==-1) { JOptionPane.showMessageDialog(null, "没有您要查找的信息", "查找结果",1); a=0; StartFindPos=0; } jta.select(a,StartFindPos); } } } ); JButton jbCancel=new JButton("取消"); jbCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ejb) { jd.dispose(); } } ); jd.getContentPane().add(jtf); jd.getContentPane().add(jbFind); jd.getContentPane().add(jbCancel); //jd.setResizable(false); jd.setLocation(240,200); jd.setDefaultCloseOperation(DISPOSE_ON_CLOSE); jd.setVisible(true); } catch(Exception efind) { } } if(e.getActionCommand().equals("替换")) { final JDialog jd=new JDialog(this,"替换",true); GridBagLayout gbl=new GridBagLayout(); GridBagConstraints gbc=new GridBagConstraints(); gbc.weightx=1; gbc.weighty=1; gbc.gridwidth=1; gbc.gridheight=1; JLabel jlFind=new JLabel("查找:"); JLabel jp=new JLabel("替换内容:"); final JTextField jtf=new JTextField(15); final JTextField jtf1=new JTextField(15); jd.getContentPane().setLayout(gbl); jd.setSize(330,150); jd.setResizable(false); final JButton jbReplace=new JButton("替换"); final JButton jbReplaceAll=new JButton("替换所有"); final JButton jbCancel=new JButton("取消"); final JButton jbFind=new JButton("查找"); gbc.gridx=0; gbc.gridy=0; jd.getContentPane().add(jlFind,gbc); gbc.gridx=1; gbc.gridy=0; jd.getContentPane().add(jtf1,gbc); gbc.gridx=2; gbc.gridy=0; jd.getContentPane().add(jbFind,gbc); gbc.gridx=0; gbc.gridy=1; jd.getContentPane().add(jp,gbc); gbc.gridx=1; gbc.gridy=1; jd.getContentPane().add(jtf,gbc); gbc.gridx=2; gbc.gridy=1; jd.getContentPane().add(jbReplace,gbc); gbc.gridx=2; gbc.gridy=2; jd.getContentPane().add(jbReplaceAll,gbc); gbc.gridx=2; gbc.gridy=3; jd.getContentPane().add(jbCancel,gbc); jbFind.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent efind) { String strA=jta.getText(); String strB=jtf1.getText(); if(a>=0) { a=strA.indexOf(strB,StartFindPos); //System.out.println(a+b); b=strB.length(); StartFindPos=a+b; if(a==-1) { JOptionPane.showMessageDialog(null, "没有您要查找的信息", "查找结果",1); a=0; StartFindPos=0; } jta.select(a,StartFindPos); //System.out.println(StartFindPos); } } } ); jbReplace.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if(e.getActionCommand().equals("替换")) { String strRepleace=jtf.getText(); jta.replaceSelection(strRepleace); } } } ); jbReplaceAll.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { while(a>-1) { String strA=jta.getText(); String strB=jtf1.getText(); a=strA.indexOf(strB,StartFindPos); if(a==-1) { break; } //System.out.println(a+b); b=strB.length(); StartFindPos=a+b; //System.out.println(StartFindPos); jta.select(a,StartFindPos); //System.out.println(StartFindPos); String strRepleaceAll=jtf.getText(); jta.replaceSelection(strRepleaceAll); StartFindPos=a+b; } JOptionPane.showMessageDialog(null, "全部替换完毕", "替换内容",1); a=0; StartFindPos=0; } } ); jbCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ejb) { jd.dispose(); } } ); jd.setLocation(240,200); jd.setVisible(true); jd.setDefaultCloseOperation(DISPOSE_ON_CLOSE); } if(e.getActionCommand().equals("日期/时间")) { final JDialog jd=new JDialog(this,"插入日期"); JPanel jp1=new JPanel(); jp1.setLayout(new FlowLayout(FlowLayout.LEFT)); final JTextField jtf=new JTextField(10); JButton jbOK=new JButton("确定"); JButton jbCancel=new JButton("取消"); //Calendar cl=Calendar.getInstance(); //DateFormat df=DateFormat.getInstance(); //String sdate1=df.format(cl.getTime()); //jtf.setText(sdate1); jp1.add(jtf); jp1.add(jbOK); jp1.add(jbCancel); jd.getContentPane().add(jp1,"North"); JPanel jp2=new JPanel(); jp2.setLayout(new FlowLayout(FlowLayout.LEFT)); final JCheckBox jcb1=new JCheckBox("格式一"); final JCheckBox jcb2=new JCheckBox("格式二"); final JCheckBox jcb3=new JCheckBox("格式三"); jp2.add(jcb1); jp2.add(jcb2); jp2.add(jcb3); jd.getContentPane().add(jp2,"Center"); jd.setSize(220,120); jd.setResizable(false); jd.setLocation(240,200); final SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); Calendar cl=Calendar.getInstance(); DateFormat df=DateFormat.getInstance(); final String sdate=df.format(cl.getTime()); jcb1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if(e.getActionCommand().equals("格式一")) { if(jcb1.isSelected()) { try { SimpleDateFormat sdf1=new SimpleDateFormat("yy年MM月dd日"); Date d=sdf.parse(sdate); jtf.setText(sdf1.format(d)); jcb2.setEnabled(false); jcb3.setEnabled(false); } catch(Exception estyle1) { estyle1.printStackTrace(); } } else { jcb2.setEnabled(true); jcb3.setEnabled(true); } try { System.out.println(jta.getLineStartOffset(3)); //System.out.println(jta.getLineOfOffset(346)); } catch(Exception eee) { } } } } ); jcb2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if(e.getActionCommand().equals("格式二")) { if(jcb2.isSelected()) { try { SimpleDateFormat sdf1=new SimpleDateFormat("yy/MM/dd"); Date d=sdf.parse(sdate); jtf.setText(sdf1.format(d)); jcb1.setEnabled(false); jcb3.setEnabled(false); } catch(Exception estyle2) { estyle2.printStackTrace(); } } else { jcb1.setEnabled(true); jcb3.setEnabled(true); } //System.out.println(jcb1.isSelected()); } } } ); jcb3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if(e.getActionCommand().equals("格式三")) { if(jcb3.isSelected()) { jtf.setText(sdate); jcb1.setEnabled(false); jcb2.setEnabled(false); } else { jcb1.setEnabled(true); jcb2.setEnabled(true); } //System.out.println(jcb1.isSelected()); } } } ); jbOK.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if(e.getActionCommand().equals("确定")) { int pos=jta.getCaretPosition(); jta.insert(jtf.getText(),pos); } } } ); jbCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ejb) { jd.dispose(); } } ); jd.setVisible(true); jd.setDefaultCloseOperation(DISPOSE_ON_CLOSE); } if(e.getActionCommand().equals("自动换行")) { if(mto1.getState()) { jta.setLineWrap(true); jta.setWrapStyleWord(true); } else { jta.setLineWrap(false); jta.setWrapStyleWord(false); } //System.out.println("OK"); } if(e.getActionCommand().equals("字体")) { final JDialog jd=new JDialog(this,"字体设置"); jd.setLocation(240,200); //final JFrame jfontview=new JFrame(); GridBagLayout gbl=new GridBagLayout(); GridBagConstraints gbc=new GridBagConstraints(); JButton jbOK=new JButton("确定"); JButton jbCancel=new JButton("取消"); JTextField jtf1=new JTextField(6); final JTextArea jtaview=new JTextArea(4,8); //jfontview.getContentPane().add(jtaview); final JTextField jtf2=new JTextField(6); final JTextField jtf3=new JTextField(3); JComboBox jcb1=new JComboBox(); final JComboBox jcb2=new JComboBox(); jcb2.addItem("BOLD"); jcb2.addItem("ITALIC"); jcb2.addItem("PLAIN"); //jcb2.addItem("BOLDITALIC"); jcb2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jtf2.setText((String)jcb2.getSelectedItem()); } } ); final JComboBox jcb3=new JComboBox(); jcb3.addItem("14"); jcb3.addItem("18"); jcb3.addItem("22"); jcb3.addItem("26"); jcb3.addItem("30"); jcb3.addItem("34"); jcb3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jtf3.setText((String)jcb3.getSelectedItem()); //jtaview.setText("SS"); // int fontsizeview=Integer.parseInt((String)jcb3.getSelectedItem()); //Font fontview=new Font("字体预览",Font.BOLD,fontsizeview); //jtaview.setFont(fontview); //jtaview.setEditable(false); } } ); gbc.gridheight=1; gbc.gridwidth=1; //gbc.gridx=1; //gbc.gridy=0; gbc.weightx=0.5; gbc.weighty=0.5; jd.getContentPane().setLayout(gbl); //JLabel jl1=new JLabel("预览:"); JLabel jl2=new JLabel("字型:"); JLabel jl3=new JLabel("大小:"); gbc.gridx=0; gbc.gridy=0; jd.getContentPane().add(jl2,gbc); gbc.gridx=2; gbc.gridy=0; jd.getContentPane().add(jl3,gbc); //gbc.gridx=4; //gbc.gridy=0; //jd.getContentPane().add(jl3,gbc); gbc.gridx=0; gbc.gridy=1; jd.getContentPane().add(jtf2,gbc); gbc.gridx=2; gbc.gridy=1; jd.getContentPane().add(jtf3,gbc); //gbc.gridx=4; // gbc.gridy=1; //jd.getContentPane().add(jtf3,gbc); gbc.gridx=0; gbc.gridy=2; jd.getContentPane().add(jcb2,gbc); gbc.gridx=2; gbc.gridy=2; jd.getContentPane().add(jcb3,gbc); //gbc.gridx=4; //gbc.gridy=2; //jd.getContentPane().add(jcb3,gbc); gbc.gridx=4; gbc.gridy=1; jd.getContentPane().add(jbOK,gbc); gbc.gridx=4; gbc.gridy=2; jd.getContentPane().add(jbCancel,gbc); jbOK.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if(jtf2.getText().equals("PLAIN")) { int fontsize=Integer.parseInt(jtf3.getText()); int fontstyle=0; Font f=new Font("字体设置",fontstyle,fontsize); jta.setFont(f); // System.out.println(f.getFont("楷体_GB2312").getFontName()); } if(jtf2.getText().equals("BOLD")) { int fontsize=Integer.parseInt(jtf3.getText()); int fontstyle=1; Font f=new Font("字体设置",fontstyle,fontsize); jta.setFont(f); } if(jtf2.getText().equals("ITALIC")) { int fontsize=Integer.parseInt(jtf3.getText()); int fontstyle=2; Font f=new Font("字体设置",fontstyle,fontsize); jta.setFont(f); } jd.dispose(); //System.out.println(fontstyle); } } ); jbCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jd.dispose(); } } ); jd.setSize(200,120); jd.setResizable(false); jd.setVisible(true); jd.setDefaultCloseOperation(DISPOSE_ON_CLOSE); } if(e.getActionCommand().equals("关于记事本")) { JOptionPane jop=new JOptionPane(null,JOptionPane.INFORMATION_MESSAGE); jop.showMessageDialog(null,"小廖记事本","关于记事本",JOptionPane.OK_OPTION); //System.out.println("OK"); } } class UndoHander implements UndoableEditListener { public void undoableEditHappened(UndoableEditEvent eundo) { undo.addEdit(eundo.getEdit()); } } }
- 2021-02-11 21:22:45
- 大少爷
- 我的小型applet,你看好不 import java.io.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class TextEditor extends JApplet{ private JMenuItem jmiOpen=new JMenuItem("Open"); private JMenuItem jmiSave=new JMenuItem("Save"); private JMenuItem jmiClear=new JMenuItem("Clear"); private JMenuItem jmiExit=new JMenuItem("Exit"); private JMenuItem jmiForeground=new JMenuItem("Foreground"); private JMenuItem jmiBackground=new JMenuItem("Background"); private JLabel jlblStatus=new JLabel(); private JTextArea jta=new JTextArea(); private JFileChooser jFileChooser=new JFileChooser(new File(".")); public TextEditor() { JMenu jMenu1=new JMenu("File"); jMenu1.add(jmiOpen); jMenu1.add(jmiSave); jMenu1.add(jmiClear); jMenu1.addSeparator(); jMenu1.add(jmiExit); JMenu jMenu2=new JMenu("Edit"); jMenu2.add(jmiForeground); jMenu2.add(jmiBackground); JMenuBar jMenuBar1=new JMenuBar(); jMenuBar1.add(jMenu1); jMenuBar1.add(jMenu2); setJMenuBar(jMenuBar1); jmiOpen.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evet) { open(); } } ); jmiSave.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evet) { save(); } } ); jmiClear.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evet) { jta.setText(null); } } ); jmiExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evet) { System.exit(0); } } ); jmiForeground.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evet) { Color selectedColor=JColorChooser.showDialog(null,"Choose Foreground color",jta.getForeground()); if(selectedColor!=null) jta.setForeground(selectedColor); } } ); jmiBackground.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evet) { Color selectedColor=JColorChooser.showDialog(null,"Choose Background color",jta.getBackground()); if(selectedColor!=null) jta.setBackground(selectedColor); } } ); getContentPane().add(jlblStatus,BorderLayout.SOUTH); getContentPane().add(new JScrollPane(jta),BorderLayout.CENTER);} private void open() { if(jFileChooser.showOpenDialog(this)==JFileChooser.APPROVE_OPTION) open(jFileChooser.getSelectedFile()); } private void open(File file) { try { BufferedInputStream in=new BufferedInputStream(new FileInputStream(file)); byte[]b=new byte[in.available()]; in.read(b,0,b.length); jta.append(new String(b,0,b.length)); in.close(); jlblStatus.setText(file.getName()+"Opened"); } catch(IOException ex) { jlblStatus.setText("Error opening"+file.getName()); } } private void save() { if(jFileChooser.showSaveDialog(this)==JFileChooser.APPROVE_OPTION) save(jFileChooser.getSelectedFile()); } private void save(File file) { try { BufferedOutputStream out=new BufferedOutputStream(new FileOutputStream(file)); byte[]b=jta.getText().getBytes(); out.write(b,0,b.length); out.close(); } catch(IOException ex) { jlblStatus.setText("Error saving"+file.getName()); } }}
- 2021-02-22 16:25:01