代码如下:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TestCase extends JFrame {
private JPanel contentPane;
private BorderLayout borderLayout1 = new BorderLayout();
private JPanel jPanel1 = new JPanel();
private JPanel jPanel2 = new JPanel();
private JPanel jPanel3 = new JPanel();
private JLabel jLabel1 = new JLabel();
private JTextField url = new JTextField(30);
private JLabel jLabel2 = new JLabel();
private JTextField times = new JTextField(10);
private JButton jButton1 = new JButton(); //Construct the frame
public TestCase() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
//setIconImage(Toolkit.getDefaultToolkit().createImage(TestCase.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout1);
//this.setSize(new Dimension(400,200));
this.setSize(400,200);
this.setTitle("TestCase");
this.setVisible(true);
//this.show();
jLabel1.setText("HTTP:");
jLabel2.setText("Times:");
jButton1.setText("Execute");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
times.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(FocusEvent e) {
times_focusLost(e);
}
});
contentPane.add(jPanel1, BorderLayout.NORTH);
jPanel1.add(jLabel1, null);
jPanel1.add(url, null);
contentPane.add(jPanel2, BorderLayout.CENTER);
jPanel2.add(jLabel2, null);
jPanel2.add(times, null);
contentPane.add(jPanel3, BorderLayout.SOUTH);
jPanel3.add(jButton1, null);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
public static void main(String args[]){
new TestCase();
} void jButton1_actionPerformed(ActionEvent e) {
String http_url=null;
int count;
http_url = url.getText();
if (http_url.equals("")){
JOptionPane.showMessageDialog(this,"Please enter URL address!","Infromation",0);
return;
}
if (!times.getText().equals("")) {
count = Integer.parseInt(times.getText());
}
else{
JOptionPane.showMessageDialog(this,"Please enter Times!","Infromation",0);
return ;
}
String ls_command=null;
ls_command="C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE " + http_url;
try {
for (int i=0;i<count;i++){
Runtime.getRuntime().exec(ls_command);
}
}
catch (Exception ex){ex.printStackTrace();} } void times_focusLost(FocusEvent e) {
try{
Integer.parseInt(times.getText());
}
catch (NumberFormatException exx){ }
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TestCase extends JFrame {
private JPanel contentPane;
private BorderLayout borderLayout1 = new BorderLayout();
private JPanel jPanel1 = new JPanel();
private JPanel jPanel2 = new JPanel();
private JPanel jPanel3 = new JPanel();
private JLabel jLabel1 = new JLabel();
private JTextField url = new JTextField(30);
private JLabel jLabel2 = new JLabel();
private JTextField times = new JTextField(10);
private JButton jButton1 = new JButton(); //Construct the frame
public TestCase() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
//setIconImage(Toolkit.getDefaultToolkit().createImage(TestCase.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout1);
//this.setSize(new Dimension(400,200));
this.setSize(400,200);
this.setTitle("TestCase");
this.setVisible(true);
//this.show();
jLabel1.setText("HTTP:");
jLabel2.setText("Times:");
jButton1.setText("Execute");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
times.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(FocusEvent e) {
times_focusLost(e);
}
});
contentPane.add(jPanel1, BorderLayout.NORTH);
jPanel1.add(jLabel1, null);
jPanel1.add(url, null);
contentPane.add(jPanel2, BorderLayout.CENTER);
jPanel2.add(jLabel2, null);
jPanel2.add(times, null);
contentPane.add(jPanel3, BorderLayout.SOUTH);
jPanel3.add(jButton1, null);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
public static void main(String args[]){
new TestCase();
} void jButton1_actionPerformed(ActionEvent e) {
String http_url=null;
int count;
http_url = url.getText();
if (http_url.equals("")){
JOptionPane.showMessageDialog(this,"Please enter URL address!","Infromation",0);
return;
}
if (!times.getText().equals("")) {
count = Integer.parseInt(times.getText());
}
else{
JOptionPane.showMessageDialog(this,"Please enter Times!","Infromation",0);
return ;
}
String ls_command=null;
ls_command="C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE " + http_url;
try {
for (int i=0;i<count;i++){
Runtime.getRuntime().exec(ls_command);
}
}
catch (Exception ex){ex.printStackTrace();} } void times_focusLost(FocusEvent e) {
try{
Integer.parseInt(times.getText());
}
catch (NumberFormatException exx){ }
}
}
解决方案 »
- JNI实现监听全局鼠标事件,钩子需编译成64位dll,但在CodeBlocks下编译出是32位的,用VS编译显示“发现重复定义”,请教错误原因或帮忙编译一下谢谢
- 求助求助,递归问题
- 有没有专门解析Schema的API?
- java 新手问题
- 问个题外话,校内是通过什么手段判断照片是不是真人的?
- 呵呵,考考大家算法。某工程公司面试题。
- toAyyay()方法怎么用?
- java char String 问题
- JAVA的 类,接口,抽象类 一般是怎么互相调用的?
- Graphics.drawLine方法出现异常NullPointerException
- setDefaultCloseOperation是做什么用的
- 字符串处理难题?
怎么show被注释掉了?
contentPane.add(jPanel3, BorderLayout.SOUTH);
jPanel3.add(jButton1, null);
this.show();
.......
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout1);
jLabel1.setText("HTTP:");
jLabel2.setText("Times:");
jButton1.setText("Execute");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
times.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(FocusEvent e) {
times_focusLost(e);
}
});
contentPane.add(jPanel1, BorderLayout.NORTH);
jPanel1.add(jLabel1, null);
jPanel1.add(url, null);
contentPane.add(jPanel2, BorderLayout.CENTER);
jPanel2.add(jLabel2, null);
jPanel2.add(times, null);
contentPane.add(jPanel3, BorderLayout.SOUTH);
jPanel3.add(jButton1, null);
this.setSize(400,200);
this.setTitle("TestCase");
this.setVisible(true);
this.show();
}