- 论坛徽章:
- 0
|
0.10
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JOptionPane;
public class PlusFrame extends Frame {
private static final long serialVersionUID = 1L;
// 定义三个输入框
TextField num1, num2, num3;
// 定义一个=按钮
Button btnEquals;
// 定义+标签
Label lblPlus;
//加法运算结果
Integer n3;
// 构造函数,初始化界面上的组件以及响应界面上的X按钮
public PlusFrame() {
num1 = new TextField(10);
num1.setName("bbbbb");
num2 = new TextField(10);
num2.setName("ccccc");
num3 = new TextField(15);
num3.setName("ddddd");
btnEquals = new Button("=");
btnEquals.setName("equal");
btnEquals.addActionListener(new PlusListener());
lblPlus = new Label("+");
// 响应界面上的X关闭按钮
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
this.showFrame();
}
// 显示整个界面
public void showFrame() {
setLayout(new FlowLayout());
add(num1);
add(lblPlus);
add(num2);
add(btnEquals);
add(num3);
pack();
setVisible(true);
}
//判断输入的数字是否合法
public boolean numIsRight(TextField num1,TextField num2){
if(num1.getText().equals("")||num2.getText()==null){
JOptionPane.showMessageDialog(null, "输入的数字必须在0-10之间", "数字验证出错",
JOptionPane.ERROR_MESSAGE);
return false;
}
int n1 = Integer.parseInt(num1.getText());
if (n1 > 10 || n1 10 || n2
import java.awt.Button;
import java.awt.TextField;
import junit.extensions.abbot.ComponentTestFixture;
import abbot.script.ComponentReference;
import abbot.tester.ComponentTester;
public class TestAbbot {
public PlusFrame calc = new PlusFrame(); // The GUI to be tested
Button button2 = null;
TextField display = null;
TextField ab = null;
TextField cd = null;
ComponentTester testBasic = null;
public TestAbbot() throws Exception
{ GuiTest test = new GuiTest("PlusFrame");
test.setUp();
}
class GuiTest extends ComponentTestFixture // From Abbot's JUnit extensions
{ public GuiTest(String name)
{ super(name);
}
public void setUp() throws Exception
{
ComponentReference ref = new ComponentReference("equalButton", Button.class, "equal", "=");
button2 = (Button)getFinder().findComponent(ref);
testBasic = new ComponentTester();
ref = new ComponentReference("display", TextField.class, "bbbbb", null);
display = (TextField)getFinder().findComponent(ref);
//display.setText("5");
ref = new ComponentReference("ab", TextField.class, "ccccc", null);
ab = (TextField)getFinder().findComponent(ref);
//display.setText("5");
ref = new ComponentReference("cd", TextField.class, "ddddd", null);
cd = (TextField)getFinder().findComponent(ref);
//System.out.println(display.getText());
}
}
private int delay = 0;
public void delay(int d) // Control the speed of the "robot".
{ delay = d;
}
private void click(Button button)
{ testBasic.actionClick(button); // robot clicks the button, firing action events
testBasic.actionDelay(delay);
}
public void two() throws Exception
{ click(button2);
}
public void abb(String a) throws Exception
{ ab.setText(a);
}
public void dis(String a) throws Exception
{ display.setText(a);
}
public String value() throws Exception
{ testBasic.actionDelay(delay);
return cd.getText();
}
public static void main(String args[]) {
try {
TestAbbot a = new TestAbbot();
a.dis("4");
a.abb("6");
a.two();
System.out.println(a.value());
} catch (Exception e) {
e.printStackTrace();
}
}
}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/76927/showart_2045765.html |
|