- //handel.java
- package abc.jdm;
- import abc.jdm.*;
- import java.awt.Color;
- import java.awt.PrintJob;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import java.io.*;
- import javax.print.*;
- import sun.rmi.runtime.GetThreadPoolAction;
- import java.awt.datatransfer.*;
- public class handel {
- public String test(String txt){
- return txt.toString();
- }
- }
- class newfile extends Thread implements ActionListener{
- public void actionPerformed(ActionEvent e){
- new newfile().start();
- }
- public void run(){
- new MyFrame();
- }
- }
- class savefile implements ActionListener{
- public void actionPerformed(ActionEvent e){
- JFileChooser jfile=new JFileChooser();
- jfile.setFileFilter(new javax.swing.filechooser.FileFilter() {
- public boolean accept(File f) { //设定可用的文件的后缀名
- if(f.getName().endsWith(".java")||f.isDirectory()){
- return true;
- }
- return false;
- }
- public String getDescription() {
- return "文本文件(*.txt)";
- }
- });
- int result=jfile.showSaveDialog(null);
- if(result==JFileChooser.APPROVE_OPTION){
- File dir=jfile.getCurrentDirectory();
- File file=jfile.getSelectedFile();
- write(new File(dir,file.getName()),MyFrame.mytext.getText());
- }
- if(result==JFileChooser.CANCEL_OPTION){
- }
- }
- public void write(File file,String str){
- try{
- PrintWriter write=new PrintWriter(new OutputStreamWriter(new FileOutputStream(file),"GBK"));
- write.println(str);
- write.close();
- }
- catch(IOException e){
- throw new RuntimeException(e);
- }
- }
- }
- //
- class quitframe implements ActionListener{
- public void actionPerformed(ActionEvent e){
- String a=MyFrame.mytext.getText();
- if(a==""){
- System.exit(0);}
- else{
- int result=JOptionPane.showConfirmDialog(null,"文件尚未保存,你决定要退出吗?");
- if(result==JOptionPane.OK_OPTION)
- System.exit(0);
- else
- MyFrame.mytext.setText(a);
- }
- }
- }
- //
- class about implements ActionListener{
- public void actionPerformed(ActionEvent e){
- JOptionPane.showMessageDialog(null,"该软件由java编写,开发平台为myeclipse /n 希望大家多多支持!/t 孟德军","关于",JOptionPane.INFORMATION_MESSAGE);
- }
- }
- //
- class openfile implements ActionListener{
- public void actionPerformed(ActionEvent e){
- JFileChooser jfile=new JFileChooser();
- jfile.setFileFilter(new javax.swing.filechooser.FileFilter() {
- public boolean accept(File f) { //设定可用的文件的后缀名
- if(f.getName().endsWith(".java")||f.isDirectory()){
- return true;
- }
- return false;
- }
- public String getDescription() {
- return "文本文件(*.txt)";
- }
- });
- int result=jfile.showOpenDialog(null);
- if(result==JFileChooser.APPROVE_OPTION){
- File dir=jfile.getCurrentDirectory();
- File file=jfile.getSelectedFile();
- MyFrame.mytext.setText(read(new File(dir,file.getName())));
- //new MyFrame().mytext.setText(t)
- }
- if(result==JFileChooser.CANCEL_OPTION){
- }
- }
- //
- public String read(File file){
- try{
- BufferedReader read=new BufferedReader(new InputStreamReader(new FileInputStream(file),"GBK"));
- String data=null;
- StringBuffer buffer=new StringBuffer();
- while((data==read.readLine())){
- buffer.append(data+"/n");
- read.close();
- }
- return buffer.toString();
- }
- catch(IOException e){
- throw new RuntimeException(e);
- }
- }
- }//
- //color set
- class colorset implements ActionListener{
- public void actionPerformed(ActionEvent e)
- {
- //显示颜色对话框
- Color newcolor=JColorChooser.showDialog(null, "颜色设置",null);
- MyFrame.mytext.setBackground(newcolor);
- }
- }
- class printframe implements ActionListener{
- public void actionPerformed(ActionEvent e){
- /*PrintService service;
- java.awt.PrintJob b;
- */
- }
- }
- class all extends Frame implements ActionListener{
- public void actionPerformed(ActionEvent e){
- Clipboard clipboard=null;
- clipboard=getToolkit().getSystemClipboard();//获取系统剪贴板。
- if(e.getActionCommand()=="复制"){
- String temp=MyFrame.mytext.getSelectedText(); //拖动鼠标选取文本。
- StringSelection text=new StringSelection(temp);
- clipboard.setContents(text,null);
- }
- else if(e.getActionCommand()=="粘贴"){
- Transferable contents=clipboard.getContents(this);
- DataFlavor flavor= DataFlavor.stringFlavor;
- if( contents.isDataFlavorSupported(flavor))
- try{ String str;
- str=(String)contents.getTransferData(flavor);
- MyFrame.mytext.append(str);
- }
- catch(Exception x){
- }
- //
- else if(e.getActionCommand()=="剪切"){
- String temp=MyFrame.mytext.getSelectedText(); //拖动鼠标选取文本。
- StringSelection text=new StringSelection(temp);
- clipboard.setContents(text,null);
- int start=MyFrame.mytext.getSelectionStart();
- int end =MyFrame.mytext.getSelectionEnd();
- MyFrame.mytext.replaceRange("",start,end) ; //从Text1中删除被选取的文本。
- }
- else if(e.getActionCommand()=="全选"){
- String alltemp=MyFrame.mytext.toString();
- StringSelection alltext=new StringSelection(alltemp);
- clipboard.getContents(alltext);
- }
- }
- }
- }
- class display implements ActionListener{
- public void actionPerformed(ActionEvent e){
- new search();
- }
- }
- class osinfo implements ActionListener{
- public void actionPerformed(ActionEvent e){
- Runtime rt = Runtime.getRuntime();
- JOptionPane.showConfirmDialog(null,"剩余内存: "+rt.freeMemory()+" KB"+"/n"+"总内存: "+rt.totalMemory()+" KB","系统信息",
- JOptionPane.OK_OPTION,
- JOptionPane.WARNING_MESSAGE);
- }
- }
java 记事本本源代码.
最新推荐文章于 2021-02-19 02:07:38 发布