JAVA 输入流 窗体 按钮 文本域 运行系统命令
/**
* @JAVA04.For.java
* @author 当前用户:Endless作者 :Endless
* @version 创建时间:2017年7月27日 下午2:22:33
*
*/
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;
public class Test {
static JFrame f;
static JButton b;
public static void main(String [] args){
f =new JFrame("按钮");
f.setSize(500, 335);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setResizable(true);
f.setLocationRelativeTo(null);
f.setVisible(true);
f.setLayout(new FlowLayout(FlowLayout.LEFT,10,10));
f.add(b =new JButton("Exit"));
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
f.add(b =new JButton("执行"));
JTextArea text1 =new JTextArea(10,50);
text1.setSize(100, 50);
JTextArea text2 =new JTextArea(1,10);
text2.setSize(1, 30);
text2.setText("ipconfig");
f.add(text2);
f.add(text1);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
BufferedReader br=
new BufferedReader(
new InputStreamReader(
Runtime.getRuntime().exec(
text2.getText()).getInputStream()));
String tem ="";
String line = null;
while((line= br.readLine())!=null)
{
tem+=line+"\n";
}
text1.setText(tem);
} catch (IOException e1) {
}
}
});
}
}