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

📄 note.java

📁 This is the complete Editor Using java
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.jeditor;
import java.awt.*;
import javax.swing.*;

import sun.swing.plaf.nimbus.NimbusLookAndFeel;

import java.io.*;
import java.awt.event.*;
class Note extends WindowAdapter implements ActionListener {
    private JFrame mainFrame;
    private String compileFileName;
    private JTextArea textAreaFile,textAreaOutput;    
    private JMenuBar menuBar;    
    private JMenuItem compileFile, runFile, newFile, openFile, saveFile,saveAsFile, exit;
    private JMenuItem cut, copy, paste, select, find, replace, aboutMe, help;
    private JTabbedPane tabePane;
    char []fileshort={'N','O','S','A','x'};
    char []editshort={'C','y','P','e',};
    char []findshort={'F','R'};    
    char []helpshort={'b','H'};
    private JSplitPane jsplitPane;    
    private JScrollPane scrollPaneFile;
    private JScrollPane scrollPaneOutput;
    private JToolBar jtoolBar;
    static String title, filetitle, dir, tmaintext, state;
    File filePath;
    public Note() {
        title="JEditor :: ";
        UIManager.put("swing.boldMetal", Boolean.FALSE);
        //JFrame.setDefaultLookAndFeelDecorated(true);
        Toolkit.getDefaultToolkit().setDynamicLayout(true);
        System.setProperty("sun.awt.noerasebackground","true");
        mainFrame=new JFrame(title);
        Toolkit theKit = mainFrame.getToolkit();
        Dimension dim = theKit.getScreenSize();
        mainFrame.setBounds(dim.width/4, dim.height/4, 600, 500);
        try {
            UIManager.setLookAndFeel(new NimbusLookAndFeel());
        }  
        catch ( UnsupportedLookAndFeelException e ) {
            System.out.println ("Program Terminated");
            System.exit(0);
        }
        menuBar=new JMenuBar();

        JMenu filemenu=new JMenu("File");
        JMenu editmenu=new JMenu("Edit");
        JMenu findmenu=new JMenu("Search");
        JMenu buildmenu=new JMenu("Build");
        JMenu helpmenu=new JMenu("Help");
        
        filemenu.setMnemonic('f');
        editmenu.setMnemonic('e');
        findmenu.setMnemonic('s');
        buildmenu.setMnemonic('b');
        helpmenu.setMnemonic('h');
        
        newFile=new JMenuItem("New",new ImageIcon("new.jpg"));
        openFile=new JMenuItem("Open",new ImageIcon("openFile.jpg"));
        saveFile=new JMenuItem("Save",new ImageIcon("saveFile.jpg"));
        saveAsFile=new JMenuItem("Save As",new ImageIcon("saveFile.jpg"));
        exit=new JMenuItem("Exit",new ImageIcon("error1.gif"));
        
        cut=new JMenuItem("Cut",new ImageIcon("cut.jpg"));
        copy=new JMenuItem("Copy",new ImageIcon("copy.jpg"));
        paste=new JMenuItem("Paste",new ImageIcon("paste.jpg"));
        select=new JMenuItem("Select All");
        
        find=new JMenuItem("Find",new ImageIcon("find.jpg"));
        replace=new JMenuItem("Find & Replace",new ImageIcon("replace.gif"));
        
        compileFile=new JMenuItem("Compile",new ImageIcon("compileFile.gif"));
        runFile=new JMenuItem("Execute",'t');
        
        aboutMe=new JMenuItem("About");
        help=new JMenuItem("Help",new ImageIcon("help.gif"));
        
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        filemenu.add(newFile);
        filemenu.add(openFile);
        filemenu.add(saveFile);
        filemenu.add(saveAsFile);
        filemenu.add(exit);
                
        editmenu.add(cut);
        editmenu.add(copy);
        editmenu.add(paste);
        editmenu.add(select);
        
        findmenu.add(find);
        findmenu.add(replace);
        
        buildmenu.add(compileFile,0);
        buildmenu.add(runFile,1);
        
        helpmenu.add(help);
        helpmenu.add(aboutMe);
        
        newFile.addActionListener(this);
        openFile.addActionListener(this);
        saveFile.addActionListener(this);
        saveAsFile.addActionListener(this);
        exit.addActionListener(this);
        
        cut.addActionListener(this);
        copy.addActionListener(this);
        paste.addActionListener(this);
        select.addActionListener(this);
        
        find.addActionListener(this);
        replace.addActionListener(this);
        
        compileFile.addActionListener(this);
        runFile.addActionListener(this);
        
        aboutMe.addActionListener(this);
        help.addActionListener(this);        
        
        newFile.setFont(new Font("Times new Roman",Font.ITALIC|Font.BOLD,15));
        openFile.setFont(new Font("Times new Roman",Font.ITALIC|Font.BOLD,15));
        saveFile.setFont(new Font("Times new Roman",Font.ITALIC|Font.BOLD,15));
        saveAsFile.setFont(new Font("Times new Roman",Font.ITALIC|Font.BOLD,15));
        exit.setFont(new Font("Times new Roman",Font.ITALIC|Font.BOLD,15));
        
        newFile.setMnemonic('n');
        openFile.setMnemonic('o');
        saveFile.setMnemonic('s');
        saveAsFile.setMnemonic('a');
        exit.setMnemonic('x');
        
        cut.setMnemonic('t');
        copy.setMnemonic('c');        
        paste.setMnemonic('p');
        select.setMnemonic('a');
        
        find.setMnemonic('f');
        replace.setMnemonic('r');
        
        compileFile.setMnemonic('c');
        runFile.setMnemonic('x');
        
        help.setMnemonic('h');
        aboutMe.setMnemonic('a');
        
        
        JCheckBoxMenuItem bld=new JCheckBoxMenuItem("Bold");
        JCheckBoxMenuItem itlc=new JCheckBoxMenuItem("Italic");
        
        bld.addActionListener(this);
        itlc.addActionListener(this);
        
        bld.setMnemonic('b');
        itlc.setMnemonic('i');
        
        editmenu.add(bld,0);
        editmenu.add(itlc,1);
        editmenu.insertSeparator(2);
        
        menuBar.add(filemenu);
        menuBar.add(editmenu);
        menuBar.add(findmenu);
        menuBar.add(buildmenu);
        menuBar.add(helpmenu);
        
        runFile.setEnabled(true);        
        
        textAreaFile=new JTextArea();       
        textAreaOutput=new JTextArea("");        
        
        scrollPaneFile=new JScrollPane(textAreaFile, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scrollPaneOutput=new JScrollPane(textAreaOutput, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        
        jsplitPane=new JSplitPane(JSplitPane.VERTICAL_SPLIT,scrollPaneFile,scrollPaneOutput);
        scrollPaneFile.setMinimumSize(new Dimension(800,300));
        scrollPaneOutput.setMinimumSize(new Dimension(800,150));
        scrollPaneFile.setPreferredSize(new Dimension(800,500));
        
        
        jtoolBar=new JToolBar("Tools", JToolBar.HORIZONTAL);
        
        mainFrame.getContentPane().add(jtoolBar);
        
        mainFrame.setJMenuBar(menuBar);
        mainFrame.getContentPane().add(jsplitPane);
        mainFrame.addWindowListener(this);
        mainFrame.setVisible(true);
    }
    public void actionPerformed(ActionEvent e) {
    	String event=e.getActionCommand();
    	/******************************		FIND	 ****************************/
    	if(event.equals("Find")) {
    		new Find(textAreaFile);
    	}
    	/**************************		FIND & REPLACE     **********************/
    	if(event.equals("Find & Replace")) {
    		new Replace(textAreaFile);
    	}
    	/******************************		COPY	 ****************************/    	
    	if(event.equals("Copy")) {
    		textAreaFile.copy();
    	}
    	/******************************		CUT 	 ****************************/    	
    	if(event.equals("Cut")) {
    		textAreaFile.cut();
    	}
    	/******************************		PASTE	 ****************************/
    	if(event.equals("Paste")) {
    		textAreaFile.paste();
    	}
    	/***************************   SELECT ALL	 ****************************/    	
    	if(event.equals("Select All")) {
    		textAreaFile.selectAll();
    	}
    	/**************************		SAVE    *******************************/
    	if(event.equals("Save")) {
    		if(mainFrame.getTitle().equals(title)) {  
    			MySave.getInstance().fileSave(textAreaFile, mainFrame, "Save");
    		}
    		else {
    			MySave.getInstance().fileSaveAlready(textAreaFile, mainFrame);
    		}
	    }
    	/*****************************	SAVE  AS  *****************************/    
	    if(event.equals("Save As")) {	
	    	MySave.getInstance().fileSave(textAreaFile, mainFrame, "SaveAs");
	    }
    	/***************************	NEW   *********************************/    
	    if(event.equals("New")) {
	    	if(mainFrame.getTitle().equals(title) && textAreaFile.getText().length()==0) {
	    		textAreaFile.setText(null);
	    	}
	    	if(mainFrame.getTitle().equals(title) && textAreaFile.getText().length()!=0) {
	    		int i = JOptionPane.showConfirmDialog(mainFrame, "The text in the new file has been changed " +
	    				"\n Do you want to saveFile the changes","Jogi Message", 
	    				JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE, new ImageIcon("warning.gif"));
	    		if(i==0) {
	    			MySave.getInstance().fileSave(textAreaFile, mainFrame, "Save");
	    		}
	    		else {
				   	textAreaFile.setText(null);
	    			mainFrame.setTitle(title);
	    		}	    		
	    	}
	    	if(textAreaFile.getText().length()==0) {
	    		/*tabePane = new JTabbedPane(SwingConstants.TOP);
	    		tabePane.addTab("One", textAreaFile);
	    		mainFrame.add(tabePane);
	    		System.out.println("Jogi");*/
	    	}
	    }
    	/****************************	OPEN   ********************************/    
	    if(event.equals("Open")) {
	    	
	    	JFileChooser fileChooser=new JFileChooser();
	    	fileChooser.setDialogTitle("Open");
	    	int alert = fileChooser.showOpenDialog(mainFrame);
	    	if(alert == JFileChooser.APPROVE_OPTION) {
	    		try {
	    			dir = fileChooser.getSelectedFile().getAbsolutePath();
	    			dir = "\""+dir+"\"";
			    	filetitle = fileChooser.getSelectedFile().getName();
			    	System.out.println(dir+" "+filetitle);
			    	File f = new File(dir);
			    	if(f.exists()) {
			    		System.out.println("Jogsdi");
			    	}
					FileInputStream fis = new FileInputStream(f);
					int b=0;
					while((b=fis.read())!=-1) {
						textAreaFile.append((char)b+"");
					}
					//tmaintext=tmain.getText();
					fis.close();
				}catch(Exception fe){}
			}
			else if(alert == JFileChooser.CANCEL_OPTION) {
				System.out.println("Open Canceled");
			}			
		}
    	/****************************	COMPILE   *****************************/
		if(event.equals("Compile")) {
			if(mainFrame.getTitle().equals(title) && textAreaFile.getText().length()==0) {
				JOptionPane.showMessageDialog(mainFrame, "Your file is blank ..... \nPlease type the program " +
						"& saveFile Then try again"," Compile Message", JOptionPane.ERROR_MESSAGE,
						new ImageIcon("error.gif"));
			}
			else if(tmaintext==null && mainFrame.getTitle().equals(title)) {
				JOptionPane.showMessageDialog(mainFrame,"You have not saveFile your file...... \nSave " +
						"the file then try again..... "," Compile Message",JOptionPane.ERROR_MESSAGE,
						new ImageIcon("error.gif"));
			}
			else if(tmaintext.compareTo(textAreaFile.getText())!=0) {
				JOptionPane.showMessageDialog(mainFrame,"The text of the file has been changed..... " +
						"\nSave the file then try again"," Compile Message",JOptionPane.ERROR_MESSAGE,
						new ImageIcon("error.gif"));
			}			
			else if(dir.equals(filePath.getPath())) {
				Runtime runTime = Runtime.getRuntime();

⌨️ 快捷键说明

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