📄 jeditor.java
字号:
}
/*************************** 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) {
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");
}
//textAreaFile.setText(null);
//mainFrame.setTitle(title);
}
else {
textAreaFile.setText(null);
mainFrame.setTitle(title);
}
}
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();
//textAreaOutput.setText(dir+filetitle);
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();
}
catch(Exception ef){textAreaOutput.append("FileNotFound");}
textAreaFile.setText(null);
mainFrame.setTitle(title);
}
else {
textAreaFile.setText(null);
mainFrame.setTitle(title);
}
}
else {
textAreaFile.setText(null);
mainFrame.setTitle(title);
}
}
}*/
/**************************** OPEN ********************************/
if(event.equals("Open")) {
if(mainFrame.getTitle().equals(title) && textAreaFile.getText().length()==0) {
JFileChooser fileChooser=new JFileChooser();
fileChooser.setDialogTitle("Open");
int alert = fileChooser.showOpenDialog(mainFrame);
if(alert == JFileChooser.APPROVE_OPTION) {
try {
System.out.println("OPEN");
filetitle=fileChooser.getSelectedFile().getName();
dir=fileChooser.getSelectedFile().getParent();
System.out.println(dir+filetitle);
File file = new File(dir, filetitle);
FileInputStream fis = new FileInputStream(file);
int b=0;
while((b=fis.read())!=-1) {
textAreaFile.append((char)b+"");
}
tmaintext = textAreaFile.getText();
fis.close();
mainFrame.setTitle(title+filetitle);
}
catch(Exception fe){}
}
else if(alert == JFileChooser.CANCEL_OPTION) {
System.out.println("Open Canceled");
}
}
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 {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle("Open");
int alert=fileChooser.showOpenDialog(mainFrame);
if(alert==JFileChooser.APPROVE_OPTION) {
try {
System.out.println("OPEN1");
filetitle = fileChooser.getSelectedFile().getName();
dir = fileChooser.getSelectedFile().getParent();
File file = new File(dir,filetitle);
FileInputStream fis = new FileInputStream(file);
int b=0;
while((b=fis.read())!=-1) {
textAreaFile.append((char)b+"");
}
tmaintext=textAreaFile.getText();
fis.close();
mainFrame.setTitle(filetitle+title);
}
catch(Exception fe){}
}
else if(alert==JFileChooser.CANCEL_OPTION) {
System.out.println("Open Canceled");
}
}
}
else {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle("Open");
int alert=fileChooser.showOpenDialog(mainFrame);
if(alert==JFileChooser.APPROVE_OPTION) {
try {
System.out.println("OPEN1");
filetitle = fileChooser.getSelectedFile().getName();
dir=fileChooser.getSelectedFile().getParent();
File file=new File(dir, filetitle);
FileInputStream fis=new FileInputStream(file);
int b=0;
while((b=fis.read())!=-1) {
textAreaFile.append((char)b+"");
}
tmaintext=textAreaFile.getText();
fis.close();
mainFrame.setTitle(filetitle+title);
}
catch(Exception fe){}
}
else if(alert==JFileChooser.CANCEL_OPTION)
{
System.out.println("Open Canceled");
}
}
}
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 {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle("Open");
int alert = fileChooser.showOpenDialog(mainFrame);
if(alert == JFileChooser.APPROVE_OPTION) {
try {
System.out.println("OPEN1");
filetitle = fileChooser.getSelectedFile().getName();
dir = fileChooser.getSelectedFile().getParent();
File file=new File(dir,filetitle);
FileInputStream fis=new FileInputStream(file);
int b=0;
while((b=fis.read())!=-1) {
textAreaFile.append((char)b+"");
}
tmaintext=textAreaFile.getText();
fis.close();
mainFrame.setTitle(filetitle+title);
}
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())) {
System.out.println("Compile 1"+filetitle);
Runtime runTime = Runtime.getRuntime();
Process process = null;
InputStream in = null;
textAreaOutput.setText("");
try {
System.out.println(filePath.getAbsolutePath());
process = runTime.exec("javac"+" "+filetitle);
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+"");
}
}
}
catch(Exception re){System.out.println(re.getMessage());}
}
else {
File ftemp = new File(filePath, filetitle);
try {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -