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

📄 jeditor.java

📁 This is the complete Editor Using java
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
					System.out.println(filePath.getPath());
					System.out.println(filetitle);				
					FileOutputStream fileOutputStream = new FileOutputStream(ftemp);					
					for(int ii=0;ii<tmaintext.length();ii++) {
		    			fileOutputStream.write((byte)tmaintext.charAt(ii));
		    		}
		    		fileOutputStream.close();
		    	}catch(Exception ooe){System.out.println("File Not Found");}
		    	
		    	Runtime runTime = Runtime.getRuntime();
				Process process = null;
				InputStream in = null;
				textAreaOutput.setText("");
				try {
					process = runTime.exec("javac"+" "+filetitle);
					System.out.println("Compile 2");
					in=process.getErrorStream();			
					int b=0;
					b=in.read();
					if(b==-1) {
						textAreaOutput.setText("Peocess Completed.......");
						runFile.setEnabled(true);
					}					
					else {					
						in = process.getErrorStream();
						textAreaOutput.append((char)b+"");
						while((b = in.read())!= -1) {
							textAreaOutput.append((char)b+"");	
							System.out.println(b+ "      "+(char)b);
						}	
					}
					
					String match = "Note: "+filetitle+" uses or overrides a deprecated API. \n" +
					"Note: Recompile with -Xlint:deprecation for details. ";
					//System.out.println(textAreaOutput.getText()+"   "+match);
					
					if(textAreaOutput.getText() == match) {
						System.out.println(match+runFile);
						runFile.setEnabled(true);
					}
				}
				catch(Exception re){}
				ftemp.delete();				
			}
		}
    	/****************************	EXECUTE  ******************************/			
		if(event.equals("Execute")) {
			if(dir.equals(filePath.getPath())) {
				Runtime runTime = Runtime.getRuntime();
				Process process = null;
				InputStream in = null;
				textAreaOutput.setText("");
				try {
					int index1 = 0;
					index1 = filetitle.indexOf('.'+"");				
					String name = filetitle.substring(0,index1);				
					process = runTime.exec("java"+" "+name);
					int b=0;
					in = process.getInputStream();
					while((b = in.read())!= -1) {
						textAreaOutput.append((char)b+"");
					}		
					in = process.getErrorStream();				
					while((b=in.read())!=-1) {
						textAreaOutput.append((char)b+"");
					}			
				}
				catch(Exception re){}
			}
			else {
				System.out.println("Run");
				Runtime runTime = Runtime.getRuntime();
				Process process = null;
				InputStream in = null;
				textAreaOutput.setText("");
				try {
					int index1 = 0;
					index1 = filetitle.indexOf('.'+"");				
					String name = filetitle.substring(0,index1);
					File ftemp = new File(filePath,name+".class");
					File f3 = new File(dir,name+".class");
					process = runTime.exec("java"+" "+name);
					int b = 0;
					in = process.getInputStream();
					while((b = in.read())!= -1) {
						textAreaOutput.append((char)b+"");
					}		
					in = process.getErrorStream();				
					while((b = in.read())!= -1) {
						textAreaOutput.append((char)b+"");
					}
					try {
						FileOutputStream fos2=new FileOutputStream(f3);
						for(int ii=0;ii<tmaintext.length();ii++) {
		    				fos2.write((byte)tmaintext.charAt(ii));
		    			}
		    			fos2.close();
		    		}catch(Exception ooe){System.out.println("File Not Found");}
					ftemp.delete();
				}
				catch(Exception re){}
			}	
		}
    	/****************************	BOLD	 ******************************/
		if(event.equals("Bold")) {
			if(textAreaFile.getFont().isBold()) {				
				textAreaFile.setFont(new Font("Arial",Font.PLAIN,12));
			}
			else {
				textAreaFile.setFont(new Font("Arial",Font.BOLD|Font.ITALIC,12));
			}
		}
    	/****************************	ITALIC	 ******************************/
		if(event.equals("Italic")) {
			if(textAreaFile.getFont().isItalic()) {
				textAreaFile.setFont(new Font("Arial",Font.PLAIN,12));				
			}
			else {
				textAreaFile.setFont(new Font("Arial",Font.ITALIC,12));
			}
		}
    	/****************************	EXIT	 ******************************/
    	if(event.equals("Exit")) {
    		if(mainFrame.getTitle().equals(title) && textAreaFile.getText().length()==0) {				
				mainFrame.dispose();
				System.exit(1);
			}
			else if(mainFrame.getTitle().equals(filetitle+title)) {
				if((tmaintext!=null) && (tmaintext.compareTo(textAreaFile.getText()))!=0) {
					int i=JOptionPane.showConfirmDialog(mainFrame,"The text in the"+dir+"\\"
							+filetitle+" has been changed \n Do you want to saveFile the changes",
							"Jogi Message",JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);
					if(i==0) {
						try {
							tmaintext = textAreaFile.getText();
							File file = new File(dir, filetitle);
							FileOutputStream fos = new FileOutputStream(file);
							for(int ii=0;ii<tmaintext.length();ii++) {
								fos.write((byte)tmaintext.charAt(ii));
							}
							fos.close();
							System.out.println("In Open Save 1");
							System.out.print(dir+"\\"+filetitle);
						}
						catch(Exception ef){textAreaOutput.append("FileNotFound");}
					}
					else {
						mainFrame.dispose();
						System.exit(1);
					}
				}
				else {
					mainFrame.dispose();
					System.exit(1);
				}
			}
			else 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);
				if(i==0) {
					JFileChooser fileChooser = new JFileChooser();
					fileChooser.setDialogTitle("Save");
					int alert = fileChooser.showSaveDialog(mainFrame);
					if(alert == JFileChooser.APPROVE_OPTION) {
						try {
				    		tmaintext = textAreaFile.getText();
				    		filetitle = fileChooser.getSelectedFile().getName();
				    		dir = fileChooser.getSelectedFile().getParent();
				    		File file = new File(dir, filetitle);
				    		System.out.println("Path of File"+file.getPath());
				    		mainFrame.setTitle(filetitle+title);
				    		//fileChooser.setCurrentDirectory(file);
				    		FileOutputStream fos = new FileOutputStream(file);
				    		for(int ii=0;ii<tmaintext.length();ii++) {
				    			fos.write((byte)tmaintext.charAt(ii));
				    		}
				    		fos.close();
				    		System.out.println("In Save 1");	    		
		    			}catch(Exception ef){}
		    		}	    	
		    		else if(alert==JFileChooser.CANCEL_OPTION) {
		    			System.out.println("Save As Canceled");
		    		}
				}
				else {
					mainFrame.dispose();
					System.exit(1);
				}
			}
    	}   	
    }
    	/************************  WINDOW CLOSE  ******************************/
	public void windowClosing(WindowEvent we) {
		if(mainFrame.getTitle().equals(title) && textAreaFile.getText().length()==0) {
			Window myWindow= we.getWindow();
			myWindow.setVisible(false);
			myWindow.dispose();
			System.exit(1);
		}
		else if(mainFrame.getTitle().equals(filetitle+title)) {
			if((tmaintext!=null) && (tmaintext.compareTo(textAreaFile.getText()))!=0) {
				int i=JOptionPane.showConfirmDialog(mainFrame,"The text in the"+dir+"\\"+filetitle+
						" has been changed \n Do you want to saveFile the changes","Jogi Message",
						JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);
				if(i==0) {
					try {
						tmaintext = textAreaFile.getText();
						File file = new File(dir, filetitle);
						FileOutputStream fos = new FileOutputStream(file);
						for(int ii=0;ii<tmaintext.length();ii++) {
							fos.write((byte)tmaintext.charAt(ii));
						}
						fos.close();
						System.out.println("In Open Save 1");
						System.out.print(dir+"\\"+filetitle);
					}
					catch(Exception ef){textAreaOutput.append("FileNotFound");}
				}
				else {
					Window myWindow = we.getWindow();
					myWindow.setVisible(false);
					myWindow.dispose();
					System.exit(1);
				}
			}
			else {
				Window myWindow = we.getWindow();
				myWindow.setVisible(false);
				myWindow.dispose();
				System.exit(1);
			}
		}
		else 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);			
			if(i==0) {
				JFileChooser fileChooser=new JFileChooser();
				fileChooser.setDialogTitle("Save");
				int alert=fileChooser.showSaveDialog(mainFrame);
				if(alert==JFileChooser.APPROVE_OPTION) {
					try {
			    		tmaintext = textAreaFile.getText();
			    		filetitle = fileChooser.getSelectedFile().getName();
			    		dir = fileChooser.getSelectedFile().getParent();
			    		File file = new File(dir, filetitle);
			    		System.out.println("Path of File"+file.getPath());
			    		mainFrame.setTitle(filetitle+title);
			    		//fileChooser.setCurrentDirectory(file);
			    		FileOutputStream fos=new FileOutputStream(file);
			    		for(int ii=0;ii<tmaintext.length();ii++) {
			    			fos.write((byte)tmaintext.charAt(ii));
			    		}
			    		fos.close();
			    		System.out.println("In Save 1");	    		
	    			}catch(Exception ef){}
	    		}	    	
	    		else if(alert==JFileChooser.CANCEL_OPTION) {
	    			System.out.println("Save As Canceled");
	    		}
			}
			else {
				Window myWindow = we.getWindow();
				myWindow.setVisible(false);
				myWindow.dispose();
				System.exit(1);
			}
		}
	}
    
	public static void main(String args[]) {
		new JEditor();
	}
}

⌨️ 快捷键说明

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