package bbb;
import javax.swing.*;
public class MyFrame {
    JFrame f;
    JPanel p;
    JButton b1,b2;
    JTextField t1,t2,t3,t4,t5,t6;
    JLabel l1,l2,l3,l4,l5,l6,l7,l8,l9;
    public MyFrame(){
        f=new JFrame();
        p=new JPanel();
        l1=new JLabel("当前时间:");
        l2=new JLabel("时");
        l3=new JLabel("分");
        l4=new JLabel("秒");
        l5=new JLabel("闹钟时间:");
        l6=new JLabel("闹钟设置");
        l7=new JLabel("时");
        l8=new JLabel("分");
        l9=new JLabel("秒");
        t1=new JTextField(4);
        t2=new JTextField(4);
        t3=new JTextField(4);
        t4=new JTextField(4);
        t5=new JTextField(4);
        t6=new JTextField(4);
        b1=new JButton("开");
        b2=new JButton("关");
        p.add(l1);
        p.add(t1);
        p.add(l2);
        p.add(t2);
        p.add(l3);
        p.add(t3);
        p.add(l4);
        p.add(l5);
        p.add(t4);
        p.add(l7);
        p.add(t5);
        p.add(l8);
        p.add(t6);
        p.add(l9);
        p.add(l6);
        p.add(b1);
        p.add(b2);
        f.setSize(300,150);
        f.setVisible(true);
        f.add(p);
    }
    public static void main(String[] args){
        new MyFrame();
    }
}

package bbb;
import java.awt.*;
import javax.swing.*;
public class MyFrame2 {
    JFrame f;
    JPanel p;
    JButton b1,b2;
    JTextField t1,t2;
    JLabel l1,l2;
    public MyFrame2(){
        f=new JFrame();
        p=new JPanel();
        l1=new JLabel("用户名:");
        l2=new JLabel("口令:");
        t1=new JTextField(5);
        t2=new JTextField(5);
        b1=new JButton("确定");
        b2=new JButton("取消");
        p.add(l1);
        p.add(t1);
        p.add(l2);
        p.add(t2);
        p.add(b1);
        p.add(b2);
        f.add(p);
        p.setLayout(new GridLayout(3, 2,20,20));
        f.setSize(300,150);
        f.setVisible(true);
    }
    public static void main(String[] args) {
        new MyFrame2();
    }
}

 

package bbb;
import java.awt.BorderLayout;
import java.awt.GridLayout;

import javax.swing.*;
public class MyFrame {
JFrame f;
JPanel p;
JTextField t;
JButton[] b;
String[] a={"7","8","9","/",
"4","5","6","*",
"1","2","3","-",
"0",".","=","+"};
public MyFrame(){
f=new JFrame("计算器");
f.setLayout(new BorderLayout());
p=new JPanel();
p.setLayout(new GridLayout(4, 4));
t=new JTextField(10);
b=new JButton[16];
for(int i=0;i<16;i++){
b[i]= new JButton(a[i]);
p.add(b[i]);
}
f.setSize(400, 300);
f.setVisible(true);
f.add(t,BorderLayout.NORTH);
f.add(p,BorderLayout.CENTER);
}
public static void main(String[] args) {
new MyFrame();
}
}

package bbb;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
public class MyFrame2 {
    JFrame f;
    JPanel p1,p2;
    JButton b1,b2,b3;
    public MyFrame2(){
        f=new JFrame();
        f.setLayout(new BorderLayout());
        p1=new JPanel();
        p2=new JPanel();
        b1=new JButton("红色");
        b1.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                p2.setBackground(Color.red);
                
            }
        });
        b2=new JButton("绿色");
        b2.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                p2.setBackground(Color.green);
                
            }
        });
        b3=new JButton("蓝色");
        b3.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                p2.setBackground(Color.BLUE);
                
            }
        });
        p1.add(b1);
        p1.add(b2);
        p1.add(b3);
        
        f.setSize(400, 300);
        f.setVisible(true);
        f.add(p1,BorderLayout.NORTH);
        f.add(p2,BorderLayout.CENTER);
    }
    public static void main(String[] args) {
        new MyFrame2();
    }
}

 

package swing;
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()) + "";
                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();
    }
}