Eighth training

package bbb;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
public class MyFrame {
    JFrame f;
    JPanel p;
    JTextField t1,t2,t3;
    JButton b1,b2;
    JLabel l1,l2,l3,l4;
    public MyFrame(){
        f=new JFrame();
        p=new JPanel();
        p.setLayout(new GridLayout(3, 3));
        t1=new JTextField(8);
        t2=new JTextField(8);
        t3=new JTextField(8);
        b1=new JButton("求和");
        b2=new JButton("清除");
        l1=new JLabel("加数1");
        l2=new JLabel("加数2");
        l3=new JLabel();
        l4=new JLabel();
        b1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String s = Integer.parseInt(t1.getText()) + Integer.parseInt(t2.getText()) + "";
                String a,b,c;
                a=t1.getText();
                b=t2.getText();
                c=a+b;
                t3.setText(s);
            }
        });
        b2.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                t1.setText(" ");
                t2.setText(" ");
                t3.setText(" ");
            }
        });
        p.add(l1);
        p.add(t1);
        p.add(l3);
        p.add(l2);
        p.add(t2);
        p.add(l4);
        p.add(b1);
        p.add(t3);
        p.add(b2);
        f.add(p);
        f.setSize(300,200);
        f.setVisible(true);
    }
    public static void main(String[] args) {
        new MyFrame();
    }
}
package bbb;
import java.awt.GridLayout;

import javax.swing.*;
public class MyFrame2 {
    JFrame f;
    JPanel p,p1,p2,p3,p4,p5;
    JLabel l1,l2,l3,l4;
    JTextField t;
    JButton b;
    JRadioButton r1,r2;
    JCheckBox c1,c2,c3;
    JComboBox<String> e;
    JTextArea a;
    public MyFrame2(){
        f=new JFrame();
        p=new JPanel();
        p1=new JPanel();
        p2=new new JPanel (); 
        p3 = new new JPanel (); 
        P4 = new new JPanel (); 
        P5 = new new JPanel (); 
        L1 = new new the JLabel ( "Name:" ); 
        L2 = new new the JLabel ( "Sex:" ); 
        L3 = new new the JLabel ( "hobby:" ); 
        L4 = new new the JLabel ( "origin:" ); 
        T = new new the JTextField (10 ); 
        B = new new the JButton ( "OK" ); 
        R1=new JRadioButton("男");
        r2=new JRadioButton("女");
        c1=new JCheckBox("体育");
        c2=new JCheckBox("音乐");
        c3=new JCheckBox("美术");
        String data[]={"A","B","C","D"};
        e=new JComboBox<String>(data);
        e.setMaximumRowCount(4);
        e.setEditable(true);
        a=new JTextArea();
        a.setEditable(true);
        p1.add(l1);
        p1.add(t);
        p2.add(l2);
        p2.add(r1);
        p2.add(r2);
        p3.add(l3);
        p3.add(c1);
        p3.add(c2);
        p3.add(c3);
        p4.add(l4);
        p4.add(e);
        p5.add(b);
        p.add(p1);
        p.add(p2);
        p.add(p3);
        p.add(p4);
        p.add(p5);
        f.setLayout(new GridLayout(2, 1));
        f.add(p);
        f.add(a);
        f.setVisible(true);
        f.setSize(240, 500);
    }
    public static void main(String[] args) {
        new MyFrame2();
    }
}

 

Guess you like

Origin www.cnblogs.com/chenfengdian/p/10954579.html