📄 javaedit.java
字号:
import java.awt.*;
import java.io.*;
import java.awt.event.*;
public class JavaEdit
{
public static void main(String args[])
{
JDK f=new JDK();
}
}
class JDK extends Frame
implements ActionListener,Runnable
{
Thread compiler=null;
Thread run_prom=null;
boolean bn=true;
CardLayout mycard;
Panel p=new Panel();
File file_saved=null;
TextArea input_text=new TextArea(),
compiler_text=new TextArea(),
dos_out_text=new TextArea();
Button button_input_text,button_compiler_text,
button_compiler,button_run_prom,button_see_doswin;
TextField input_file_name_text=new TextField("输入被编译的文件名字.java");
TextField run_file_name_text=new TextField("输入应用程序主类的名字");
JDK()
{
super("JAVA集成环境 烂尾楼工作室 ver1.0");
mycard=new CardLayout();
compiler=new Thread(this);
run_prom=new Thread(this);
button_input_text=new Button("代码编辑区");
button_compiler_text=new Button("编译结果区");
button_compiler=new Button("编译");
button_run_prom=new Button("运行");
button_see_doswin=new Button("查看流输出信息");
p.setLayout(mycard);
p.add("input",input_text);
p.add("compiler",compiler_text);
p.add("dos",dos_out_text);
add(p,"Center");
add(button_see_doswin,"South");
compiler_text.setBackground(Color.white);
Panel p1=new Panel();
p1.setLayout(new GridLayout(4,2));
p1.add(new Label("输入代码:"));
p1.add(button_input_text);
p1.add(new Label("编译:"));
p1.add(button_compiler_text);
p1.add(input_file_name_text);
p1.add(button_compiler);
p1.add(run_file_name_text);
p1.add(button_run_prom);
add(p1,BorderLayout.NORTH);
button_input_text.addActionListener(this);
button_compiler_text.addActionListener(this);
button_compiler.addActionListener(this);
button_run_prom.addActionListener(this);
button_see_doswin.addActionListener(this);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
setBounds(100,120,700,360);
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button_input_text)
{
mycard.show(p,"input");
}
else if(e.getSource()==button_compiler_text)
{
mycard.show(p,"compiler");
}
else if(e.getSource()==button_see_doswin)
{
mycard.show(p,"dos");
}
else if(e.getSource()==button_compiler)
{
if(!(compiler.isAlive()))
{
compiler=new Thread(this);
}
try
{
compiler.start();
}
catch(Exception eee){}
mycard.show(p,"compiler");
}
else if(e.getSource()==button_run_prom)
{
if(!(run_prom.isAlive()))
{
run_prom=new Thread(this);
}
try
{
run_prom.start();
}
catch(Exception eee){}
mycard.show(p,"dos");
}
}
public void run()
{
if(Thread.currentThread()==compiler)
{
compiler_text.setText(null);
String temp=input_text.getText().trim();
byte buffer[]=temp.getBytes();
int b=buffer.length;
String file_name=input_file_name_text.getText().trim();
try
{
file_saved=new File(file_name);
FileOutputStream writefile=new FileOutputStream(file_saved);
writefile.write(buffer,0,b);
writefile.close();
}
catch(IOException e5)
{
System.out.println("Error ");
}
try
{
Runtime ce=Runtime.getRuntime();
InputStream in=ce.exec("javac "+file_name).getErrorStream();
BufferedInputStream bin=new BufferedInputStream(in);
byte shuzu[]=new byte[100];
int n;
boolean bn=true;
while((n=bin.read(shuzu,0,100))!=-1)
{
String s=null;
s=new String(shuzu,0,n);
compiler_text.append(s);
if(s!=null)
bn=false;
}
if(bn)
{
compiler_text.append("编译成功");
}
}
catch(IOException e1){}
}
else if(Thread.currentThread()==run_prom)
{
dos_out_text.setText(null);
try
{
Runtime ce=Runtime.getRuntime();
String path=run_file_name_text.getText().trim();
InputStream in=ce.exec("java "+path).getInputStream();
BufferedInputStream bin=new BufferedInputStream(in);
byte zu[]=new byte[150];
int m;
String s=null;
while((m=bin.read(zu,0,150))!=-1)
{
s=new String(zu,0,m);
dos_out_text.append(s);
}
}
catch(IOException e1){}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -