百度空间 | 百度首页 
 
查看文章
 
FirstFest -festcode -hxzon
2009年10月27日 星期二 09:05 A.M.

FirstFest -festcode -hxzon
-------------------------
package com.hxzon.firstfest;

import org.fest.swing.fixture.FrameFixture;
import org.junit.After;
import org.junit.Before; //import org.junit.Test;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

//import org.testng.annotations.Test;

public class FirstFest {
    private FrameFixture firstFrame;

    @BeforeMethod
    @Before
    public void setUp() {
        firstFrame = new FrameFixture(new FirstFrame());
        // firstFrame.show();
    }

    @org.junit.Test
    @org.testng.annotations.Test
    public void copyText() {
        firstFrame.textBox("input").setText("hxzon");
        delay();
        firstFrame.button("copy").click();
        delay();
        firstFrame.label("ouput").requireText("hxzon");
    }

    @org.junit.Test
    @org.testng.annotations.Test
    public void showLoginDialog() {
        firstFrame.button("loginBt").click();
        delay();
        firstFrame.dialog("loginDialog").requireVisible();
    }

    @org.junit.Test
    @org.testng.annotations.Test
    public void login() {
        firstFrame.button("loginBt").click();
        delay();
        firstFrame.dialog("loginDialog").button("login").click();
        delay();
        firstFrame.dialog("loginDialog").label("message").requireText("login ok");
    }

    @AfterMethod
    @After
    public void tearDown() {
        firstFrame.cleanUp();
    }

    private void delay() {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
-------------------
package com.hxzon.firstfest;

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class FirstFrame extends JFrame{

    public FirstFrame(){
        setBackground(Color.red);
        setLayout(new GridLayout());
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(400,300);
        final JLabel output=new JLabel("");
        output.setName("ouput");
        final JTextField input=new JTextField();
        input.setName("input");
        add(output);
        add(input);
        JButton copy=new JButton();
        copy.setName("copy");
        copy.setAction(new AbstractAction("copy"){

            @Override
            public void actionPerformed(ActionEvent e) {
                output.setText(input.getText());
            }
           
        });
        JButton loginBt=new JButton();
        loginBt.setName("loginBt");
        loginBt.setAction(new AbstractAction("login"){

            @Override
            public void actionPerformed(ActionEvent e) {
                new LoginDialog().setName("loginDialog");
//                new LoginDialog().setName("loginDialog2");
            }
           
        });
        add(copy);
        add(loginBt);
        pack();
        setVisible(true);
    }
}
-----------------------
package com.hxzon.firstfest;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class LoginDialog extends JDialog{

    public LoginDialog(){
        setName("loginDialog");
        setBounds(300,300,800,400);
        setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        setLayout(new GridLayout(1, 1));
        final JTextField username=new JTextField("username");
        username.setName("username");
        final JTextField password=new JTextField("password");
        password.setName("password");
        final JLabel message=new JLabel("");
        message.setName("message");
        add(username);
        add(password);
        JButton login=new JButton();
        login.setName("login");
        add(message);
        login.setAction(new AbstractAction("login"){

            @Override
            public void actionPerformed(ActionEvent e) {
                message.setText("login ok");
            }
           
        });
        add(login);
        pack();
        setVisible(true);
    }
   
    public static void main(String args[]){
        new LoginDialog();
    }
}


类别:语法示例代码 | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu