⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jsb.java~8~

📁 和微软记事本一样的java小程序
💻 JAVA~8~
📖 第 1 页 / 共 2 页
字号:
str="记事本"+str;}this.setTitle(str);this.repaint();}//文件关闭void FileClose(){if(!bsaved){if(toExit()){FileSave();}else {System.exit(0);}}else{System.exit(0);}}//调用编辑剪切void FileCut (ActionEvent e){try{String str=this.jTextArea1.getSelectedText();if(str.length()!=0){StringSelection s = new StringSelection(str);cb.setContents(s,s);this.jTextArea1.replaceRange("",this.jTextArea1.getSelectionStart(),this.jTextArea1.getSelectionEnd());bsaved =false;}}catch(Exception ex){this.statubar.setText("剪切出错:"+ex.getMessage());}}//调用编辑复制void FileCopy(ActionEvent e){try{String str=this.jTextArea1.getSelectedText();if(str.length()!=0){StringSelection s = new StringSelection(str);cb.setContents(s,s);}}catch(Exception ex){this.statubar.setText("复制出错!"+ex.getMessage());}}//调用编辑粘贴void FilePaste(ActionEvent e){try{Transferable tr =cb.getContents(this);if (tr != null){String s = (String)tr.getTransferData(DataFlavor.stringFlavor);if(s!=null)jTextArea1.replaceRange(s,jTextArea1.getSelectionStart(),jTextArea1.getSelectionEnd());bsaved =false;}}catch (Exception err){err.printStackTrace();}}//调用编辑删除void FileDel(ActionEvent e){jTextArea1.replaceRange("",jTextArea1.getSelectionStart(),jTextArea1.getSelectionEnd());bsaved =false;}//调用编辑查找void FileFindNext(ActionEvent e){new Frame1(jTextArea1);}//时间void FileTime(ActionEvent e){SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");jTextArea1.append("\r\n当前时间:"+sdf.format(new Date()));bsaved =false;}//全选void AllSelect(ActionEvent e){jTextArea1.setSelectionStart(0);jTextArea1.setSelectionEnd(this.jTextArea1.getText().length());}//换行void FileLine(ActionEvent e){if(!jTextArea1.getLineWrap()){jTextArea1.setLineWrap(true);}else{jTextArea1.setLineWrap(false);}}// 颜色public void fcolor(ActionEvent e){Color bcolor=jTextArea1.getForeground();jColor.setColor(bcolor);jTextArea1.setForeground(jColor.showDialog(jTextArea1,"选择颜色",bcolor));}//调用关于对话框void HelpAboutDialog(ActionEvent e){JOptionPane.showMessageDialog(this,"金鑫 岳鹏飞 刘志昶 马飞 朱鹏涛 张莉 霍娜","小组成员",JOptionPane.INFORMATION_MESSAGE);}//行为事件public void actionPerformed(ActionEvent e){if (e.getSource() == jMenuFileCut){FileCut(e);}else if (e.getSource() == jMenuFileCopy){FileCopy(e);}else if (e.getSource() == jMenuFilePaste){FilePaste(e);}else if (e.getSource() == jMenuFileDel){FileDel(e);}else if (e.getSource()==jMenuMouseCut){FileCut(e);}else if (e.getSource()==jMenuMouseCopy){FileCopy(e);}else if (e.getSource()==jMenuMousePaste){FilePaste(e);}else if (e.getSource()==jMenuMouseDel){FileDel(e);}else if (e.getSource() == jMenuFileFindNext){FileFindNext(e);}else if(e.getSource() ==jMenuFileSelect){AllSelect(e);}else if (e.getSource() ==jMenuFileTime){FileTime(e);}else if(e.getSource()==jMenuCheckBox){if(check){FileLine(e);}}else if (e.getSource() == jcolor){fcolor(e);}else if (e.getSource() == jMenuHelpAbout){HelpAboutDialog(e);}}//主函数public static void main(String args[]){new jsb();}class File_new_actionAdapter implements ActionListener {public void actionPerformed(ActionEvent e){File_new_actionPerformed(e);}}class File_open_actionAdapter implements ActionListener {public void actionPerformed(ActionEvent e){File_open_actionPerformed(e);}}class File_save_actionAdapter implements ActionListener {public void actionPerformed(ActionEvent e){File_save_actionPerformed(e);}}class File_saveto_actionAdapter implements ActionListener {public void actionPerformed(ActionEvent e){File_saveto_actionPerformed(e);}}class File_close_actionAdapter implements ActionListener {public void actionPerformed(ActionEvent e){File_close_actionPerformed(e);}}//查找类class Frame1 extends JDialog implements ActionListener {JButton jButton1 = new JButton();JButton jButton2 = new JButton();JButton jButton3 = new JButton();JLabel jLabel1 = new JLabel();JLabel jLabel2 = new JLabel();JTextField jTextField1 = new JTextField();JTextField jTextField2 = new JTextField();JCheckBox jCheckBox1 = new JCheckBox("区分大小写",true);JRadioButton[] teams = new JRadioButton[2];ButtonGroup jj=new ButtonGroup();String findstr;public Frame1(JTextArea jTextArea1) {try {findstr=jTextArea1.getText();jbInit();}catch(Exception e) {e.printStackTrace();}}public void jbInit() throws Exception {this.getContentPane().setLayout(null);this.setBounds(120,120,380, 150);this.setTitle("查找");this.setModal(true);jButton1.setText("下一个");jButton1.setBounds(new Rectangle(273, 7, 91, 20));Button1Listener next=new Button1Listener();jButton1.addActionListener(next);jButton3.setText("替换");jButton3.setBounds(new Rectangle(273, 36, 91, 20));Button3Listener replace =new Button3Listener();jButton3.addActionListener(replace);jButton2.setText("取消");jButton2.setBounds(new Rectangle(273, 65, 91, 20));Button2Listener cancel=new Button2Listener();jButton2.addActionListener(cancel);jLabel1.setText("查找内容 :");jLabel1.setBounds(new Rectangle(7, 10, 72, 19));jTextField1.setBounds(new Rectangle(78, 12, 182, 19));jLabel2.setText("替换为 :");jLabel2.setBounds(new Rectangle(7, 36, 72, 19));jTextField2.setBounds(new Rectangle(78, 36, 182, 19));jCheckBox1.setBounds(new Rectangle(7, 85, 89, 25));jCheckBox1.addActionListener(this);teams[0]=new JRadioButton("向上",false);teams[0].setBounds(new Rectangle(98, 85, 68, 22));teams[0].addActionListener(this);teams[1]=new JRadioButton("向下",true);teams[1].setBounds(new Rectangle(178, 85, 62, 25));teams[1].addActionListener(this);jj.add(teams[0]);jj.add(teams[1]);this.getContentPane().add(jButton1, null);this.getContentPane().add(jButton2, null);this.getContentPane().add(jButton3, null);this.getContentPane().add(jLabel1, null);this.getContentPane().add(jLabel2, null);this.getContentPane().add(jTextField1, null);this.getContentPane().add(jTextField2, null);this.getContentPane().add(jCheckBox1, null);this.getContentPane().add(teams[0], null);this.getContentPane().add(teams[1], null);show();}public void actionPerformed(ActionEvent e){if (e.getSource() == jCheckBox1){if(check){findstr=findstr.toLowerCase();}elsefindstr=jTextArea1.getText();check=!check;}}public void processWindowEvent(WindowEvent e) {super.processWindowEvent(e);if(e.getID() == WindowEvent.WINDOW_CLOSED) {System.exit(0);}}public void find(){String text1=jTextField1.getText();if(check){text1=text1.toLowerCase();}int index,i=jTextArea1.getSelectionStart();t=jTextArea1.getSelectionEnd();if(teams[0].isSelected()){String ftp=findstr.substring(0,i);index = ftp.lastIndexOf(text1);if(index!=-1){i=index-1;jTextArea1.select(index,index+text1.length());}elseJOptionPane.showMessageDialog(this,"找不到"+text1,"提示",JOptionPane.INFORMATION_MESSAGE);}else {index = findstr.indexOf(text1,t);if(index!=-1){t=index+text1.length();jTextArea1.select(index,index+text1.length());}elseJOptionPane.showMessageDialog(this,"找不到"+text1,"提示",JOptionPane.INFORMATION_MESSAGE);}this.repaint();}//替换public void replace(){String text2=jTextField2.getText();int star=jTextArea1.getSelectionStart();int end=jTextArea1.getSelectionEnd();if(star!=end){jTextArea1.replaceRange(text2,star,end);}elseJOptionPane.showMessageDialog(this,"请确定要查找的内容","提示",JOptionPane.INFORMATION_MESSAGE);}class Button1Listener implements ActionListener {public void actionPerformed(ActionEvent e){find();}}class Button2Listener implements ActionListener {public void actionPerformed(ActionEvent e){hide();}}class Button3Listener implements ActionListener {public void actionPerformed(ActionEvent e){replace();}}}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -