博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Exec68

Posted on 2012-08-08 11:41  紫冰龙  阅读(138)  评论(0编辑  收藏  举报
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Exec68 extends JFrame{
    JTextField text;
    Boolean flag1,flag2;
    public Exec68() {
        setSize(400,500);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        setTitle("Exec68 test");
        JPanel panel = new JPanel();
        text = new JTextField(10);
        
        text.setFont(new Font(null,Font.PLAIN,60));
        text.setAlignmentX(CENTER_ALIGNMENT);
        final JButton bt1 = new JButton("打开体育之窗");
        final JButton bt2 = new JButton("打开音乐之窗");
        flag1 = true;
        flag2 = true;
        bt1.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                if (flag1)     {
                    text.setText("体育之窗");
                    bt1.setText("关闭体育之窗");
                    bt2.setText("打开音乐之窗");
                    flag2 = true;
                }
                else {
                    text.setText("");
                    bt1.setText("打开体育之窗");
                }
                flag1 = !flag1;
            }
        });
        bt2.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                if (flag2)     {
                    text.setText("音乐之窗");
                    bt2.setText("关闭音乐之窗");
                    bt1.setText("打开体育之窗");
                    flag1 = true;
                }
                else {
                    text.setText("");
                    bt2.setText("打开音乐之窗");
                }
                flag2 = !flag2;
            }
        });
        panel.add(bt1);
        panel.add(bt2);
        add(panel,BorderLayout.NORTH);
        add(text);
        setVisible(true);
        pack();
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        new Exec68();
    }

}