import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Timer;
import java.util.TimerTask;import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;public class FindFileTest { private static JButton button;
private static JTextField text;
private static JTextArea ta; public static void main(String[] args) { button = new JButton("运行");
button.addActionListener(new BAction());
text = new JTextField("net user", 30);
ta = new JTextArea(5, 40); ta.setEditable(false); JPanel panel = new JPanel();
JPanel panel1 = new JPanel(); JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, panel,
panel1);
split.setContinuousLayout(true);
split.setOneTouchExpandable(true); panel.add(text, BorderLayout.NORTH);
panel.add(button, BorderLayout.SOUTH);
panel.setBorder(BorderFactory.createTitledBorder("RunSystem")); panel1.add(new JScrollPane(ta)); panel1.setBorder(BorderFactory.createTitledBorder("SplitPane")); JFrame frame = new JFrame("Button"); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(split, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true); } static class BAction implements ActionListener { @Override
public void actionPerformed(ActionEvent e) {
Timer time = new Timer();
time.schedule(new TimeMack(), 1000); } static class TimeMack extends TimerTask { BufferedReader br = null; String s = ""; public void run() { // TODO Auto-generated method stub
try {
String str = text.getText().toLowerCase().toString();
Process p = Runtime.getRuntime().exec(str); InputStream in = p.getInputStream();
br = new BufferedReader(new InputStreamReader(in)); while ((s = br.readLine()) != null) {
ta.setText(s);
System.out.println(s);
s = br.readLine();
} } catch (IOException e) { // TODO Auto-generated catch block
JOptionPane.showMessageDialog(null,
"Please Input aEffective String!!"); } finally {
try {
if (br != null) {
br.close();
}
} catch (IOException e) {
e.printStackTrace();
}
} } } }
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Timer;
import java.util.TimerTask;import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;public class FindFileTest { private static JButton button;
private static JTextField text;
private static JTextArea ta; public static void main(String[] args) { button = new JButton("运行");
button.addActionListener(new BAction());
text = new JTextField("net user", 30);
ta = new JTextArea(5, 40); ta.setEditable(false); JPanel panel = new JPanel();
JPanel panel1 = new JPanel(); JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, panel,
panel1);
split.setContinuousLayout(true);
split.setOneTouchExpandable(true); panel.add(text, BorderLayout.NORTH);
panel.add(button, BorderLayout.SOUTH);
panel.setBorder(BorderFactory.createTitledBorder("RunSystem")); panel1.add(new JScrollPane(ta)); panel1.setBorder(BorderFactory.createTitledBorder("SplitPane")); JFrame frame = new JFrame("Button"); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(split, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true); } static class BAction implements ActionListener { @Override
public void actionPerformed(ActionEvent e) {
Timer time = new Timer();
time.schedule(new TimeMack(), 1000); } static class TimeMack extends TimerTask { BufferedReader br = null; String s = ""; public void run() { // TODO Auto-generated method stub
try {
String str = text.getText().toLowerCase().toString();
Process p = Runtime.getRuntime().exec(str); InputStream in = p.getInputStream();
br = new BufferedReader(new InputStreamReader(in)); while ((s = br.readLine()) != null) {
ta.setText(s);
System.out.println(s);
s = br.readLine();
} } catch (IOException e) { // TODO Auto-generated catch block
JOptionPane.showMessageDialog(null,
"Please Input aEffective String!!"); } finally {
try {
if (br != null) {
br.close();
}
} catch (IOException e) {
e.printStackTrace();
}
} } } }
}
解决方案 »
- javamail转发邮件,No MimeBodyPart content错误
- gwt-designer的使用问题
- 求助,字符串截取 不同操作系统上,显示不同结果!
- 一个菜鸟问题,还请各位大大不吝告知,如何获得org.eclipse包?
- 我想学JAVA,各位老兄可否给点建议?拜托!
- 请问如何用 Applet 调用 JavaScript 的函数?
- 各位老兄,请问在java中怎么解决这样<Node Name="N1" Value="1" />的XML
- 一个不可能解决的问题。。。
- 怎样把TextField里面的值用'*'来显示?
- 这种写法是否正确?JAVA语法问题!
- 要打包发布java程序了,遇到了问题
- 对象名.class什么意思啊?
while ((s = br.readLine()) != null) { System.out.println(text);
ta.setText(s);
} 如果需要换行在text.append(s);后面做处理
while ((s = br.readLine()) != null) {
text.append(s);
System.out.println(text);
ta.setText(s);
}
try {
String str = text.getText().toLowerCase().toString();
Process p = Runtime.getRuntime().exec(str); InputStream in = p.getInputStream();
br = new BufferedReader(new InputStreamReader(in)); String temp = new String("");
while ((s = br.readLine()) != null) {
// ta.setText(s); // ta中的数据每次循环都发生变化,在最后一次循环之后,s是一个空值,所以在最后什么都没输出
temp += s + "\n";
System.out.println(s);
// s = br.readLine(); // 楼主之前在这里多读了一行。
}
ta.setText(temp); } catch (IOException e) { // TODO Auto-generated catch block
JOptionPane.showMessageDialog(null, "Please Input a Effective String!!"); } finally {
try {
if (br != null) {
br.close();
}
} catch (IOException e) {
e.printStackTrace();
}
} } }
输出结果(输入netuser):
Administrator ASPNET Guest
HelpAssistant IUSR_43DB0D5296634EC IWAM_43DB0D5296634EC
SUPPORT_388945a0
命令成功完成。