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);
    }
}

你可能感兴趣的:(ex07)