777777777777777777777


import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import javax.swing.*;
import java.awt.BorderLayout;
public class bbb implements ActionListener {
    JFrame f;
    JPanel p1,p2;
    JLabel[] bq;
    JTextField[]t;
    JButton b,j,y,u,c;
    String l[]={"当前时间:","年","月","日","时","分","秒"};
    public bbb(){
        GridLayout g1;
         g1= new GridLayout(1,4);
         f= new JFrame("时钟");
         p1=new JPanel();
         bq=new JLabel[l.length];
         t= new JTextField[6];
         b=new JButton("确定");
         b.addActionListener(this);
         for(int i=0;i<7;i++){
             bq[i]= new JLabel(l[i]);
             p1.add(bq[i]);
             if(i==6)
                 break;
             t[i]=new JTextField(4);
             p1.add(t[i]);
         }
         p1.add(b);
         f.add(p1);
         f.setSize(300,300);
         f.setVisible(true);
         p2.setLayout(g1);
         f.add(p1,BorderLayout.NORTH);
         f.add(p2,BorderLayout.CENTER);
         p2.add(b);
         p2.add(y);
         p2.add(u);
         p2.add(c);
    }
    public static void main(String[] args) {
        new bbb();
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        Calendar ca1 = Calendar.getInstance();
        t[0].setText(String.valueOf(Integer.toString(ca1.get(Calendar.YEAR))));
        t[1].setText(String.valueOf(Integer.toString(ca1.get(Calendar.MARCH)+1)));
        t[2].setText(String.valueOf(Integer.toString(ca1.get(Calendar.DATE))));
        t[3].setText(String.valueOf(Integer.toString(ca1.get(Calendar.HOUR))));
        t[4].setText(String.valueOf(Integer.toString(ca1.get(Calendar.MINUTE))));
        t[5].setText(String.valueOf(Integer.toString( ca1.get(Calendar.SECOND))));
        p1.setBackground(Color.pink);
        b.setBackground(Color.green);
        t[0].setBackground(Color.CYAN);
        t[1].setBackground(Color.yellow);
        t[2].setBackground(Color.LIGHT_GRAY);
        t[3].setBackground(Color.ORANGE);
        t[4].setBackground(Color.magenta);
        t[5].setBackground(Color.red);
        b=new  JButton("我");
    }
}


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

}

public class Yanse {
JFrame f;
JPanel p1;
JPanel p2;
JButton a[]=new JButton[3];
    public Yanse(){
        f=new JFrame();
        p1=new JPanel();
        p2=new JPanel();
        a[0]=new JButton("红色");
        a[1]=new JButton("绿色");
        a[2]=new JButton("蓝色");
        f.add(p1);f.add(p2);
        f.add(p1,BorderLayout.NORTH);
        f.add(p2,BorderLayout.CENTER);
          for(int i=0;i<3;i++){
                p1.add(a[i]);
            }
              f.setSize(400,300);
            f.setVisible(true);
    }
    public static void main(String[] args) {
        new Yanse();}}

 

原文地址:https://www.cnblogs.com/luli1220/p/10904967.html