ex07

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JToggleButton;
import static net.mindview.util.SwingConsole.*;

public class ex07 extends JFrame {

    JTextArea text = new JTextArea(20, 40);

    JButton button = new JButton("button");
    JCheckBox checkBox = new JCheckBox("checkBox");
    JCheckBoxMenuItem checkBoxMenuItem = new JCheckBoxMenuItem(
            "checkBoxMenuItem");
    JMenu menu = new JMenu("menu");
    JMenuItem menuItem = new JMenuItem("menuitem");
    JPasswordField password = new JPasswordField(20);
    JRadioButton radioButton = new JRadioButton("radiobutton");
    JRadioButtonMenuItem radionbuttonmenuitem = new JRadioButtonMenuItem(
            "radiobuttonmenuitem");
    JTextField textfield = new JTextField(20);
    JFormattedTextField formattedTextField = new JFormattedTextField();
    JToggleButton toggle = new JToggleButton("toggle");

    public ex07() {

        textfield.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                text.append(((JTextField) e.getSource()).getText() + "\n");
            }
        });
        formattedTextField.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                text.append(((JFormattedTextField) e.getSource()).getText() + "\n");
            }
        });
        toggle.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                text.append(((JToggleButton) e.getSource()).getText() + "\n");
            }
        });
        button.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                text.append(((JButton) e.getSource()).getText() + "\n");
            }
        });
        checkBox.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                text.append(((JCheckBox) e.getSource()).getText() + "\n");
            }
        });
        checkBoxMenuItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                text.append(((JCheckBoxMenuItem) e.getSource()).getText() + "\n");
            }
        });
        button.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                text.append(((JButton) e.getSource()).getText() + "\n");
            }
        });
        menu.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                text.append(((JMenu) e.getSource()).getText() + "\n");
            }
        });
        menuItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                text.append(((JMenuItem) e.getSource()).getText() + "\n");
            }
        });
        password.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                text.append(((JPasswordField) e.getSource()).getText() + "\n");
            }
        });
        radioButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                text.append(((JRadioButton) e.getSource()).getText() + "\n");
            }
        });
        radionbuttonmenuitem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                text.append(((JRadioButtonMenuItem) e.getSource()).getText() + "\n");
            }
        });
        radioButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                text.append(((JRadioButton) e.getSource()).getText() + "\n");
            }
        });

        setLayout(new FlowLayout());
        add(text);
        add(button);
        add(checkBox);
        add(checkBoxMenuItem);
        add(menu);
        add(menuItem);
        add(password);
        add(radioButton);
        add(radionbuttonmenuitem);
        add(textfield);
        add(formattedTextField);
        add(toggle);
    }

    public static void main(String[]args){

        run(new ex07(),800,600);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值