免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1349 | 回复: 0
打印 上一主题 下一主题

eee [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-09-04 19:31 |只看该作者 |倒序浏览
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
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP