ui的java代码 ui写代码( 三 )


panel add(new JScrollPane(textArea_ ) BorderLayout CENTER);
final JPanel panel_ = new JPanel();
panel_ setLayout(new BorderLayout());
panel_ setBorder(new EtchedBorder(EtchedBorder LOWERED));
panel_ setForeground(Color BLUE);
panel_ setBounds( );
getContentPane() add(panel_ );
textArea = new JTextArea();
panel_ add(new JScrollPane(textArea) BorderLayout CENTER);
try {
UIManager setLookAndFeel( sun java swing plaf nimbus NimbusLookAndFeel );
} catch (Exception ex ) {
try {
UIManager setLookAndFeel( sun java swing plaf windows WindowsClassicLookAndFeel );
} catch (Exception ex ) {
UIManager setLookAndFeel( sun java swing plaf windows WindowsLookAndFeel );
}
}
SwingUtilities updateComponentTreeUI(this);
textField = new JTextField();
textField setToolTipText( 不填自动从Java代码中提取类名 );
textField setBounds( );
getContentPane() add(textField);
final JLabel label = new JLabel();
label setText( 类名: );
label setBounds( );
getContentPane() add(label);
setResizable(false);// 屏蔽最大化按钮
textField_ = new JTextField();
textField_ setBounds( );
textField_ setToolTipText( 可以和Java交互信息 );
getContentPane() add(textField_ );
final JButton button_ = new JButton();
button_ addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent arg ) {
cmd = textField_ getText();
}
});
button_ setText( CMD命令发送 );
button_ setBounds( );
getContentPane() add(button_ );
final JButton button_ = new JButton();
button_ addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent arg ) {
String name = textField getText();
if (name trim() length() == ) {
textField setText(getName(textArea_ getText()));
}
FileOut(textField getText() + java textArea_ getText());
File file = new File(url + textField getText() + class );
if (file exists()) {
file delete();
}
String exe = cmd ;
try {
pro = Runtime getRuntime() exec(exe);
if (InPutThread != null)InPutThread stop();
if (OutPutThread != null)InPutThread stop();
if (ErrorThread != null)InPutThread stop();
InPutThread = new Thread(new RunTimeInput());
OutPutThread = new Thread(new RunTimeOutput(new InputStreamReader(pro getInputStream())));
ErrorThread = new Thread(new RunTimeOutput(new InputStreamReader(pro getErrorStream())));
InPutThread start();
OutPutThread start();
ErrorThread start();
exec( javac + textField getText() + java );
Thread sleep( );
exec( java + textField getText() + );
} catch (Exception e) {
e printStackTrace();
}
}
});
button_ setText( 编译/运行 );
button_ setBounds( );
getContentPane() add(button_ );
}
public void FileOut(String name String Content) {
File file = new File(url + name);
if (file exists())
file delete();
try {
file createNewFile();
FileOutputStream out = new FileOutputStream(file);
byte buf[] = Content getBytes();
out write(buf);
out flush();
out close();
} catch (Exception ex) {
ex printStackTrace();
}
}
public class RunTimeInput implements Runnable {
private BufferedWriter bw = null;
public void run() {
bw = new BufferedWriter(new OutputStreamWriter(pro getOutputStream()));
while (true) {
try {
if (cmd != nullcmd length()) {
bw write(cmd + \n\n );
bw flush();
cmd = null;
}
Thread sleep( );
} catch (Exception e) {
e printStackTrace();
}
}

推荐阅读