计算器、换颜色窗口

package cuko;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class 计算机界面 {
JFrame f;
JButton b[];
JPanel p;
GridLayout g;
JTextField t;
String a[]= {"7","8","9","/","4","5","6","*","1","2","3","-","0",".","=","+"};
   public 计算机界面() {
	  f=new JFrame("计算器");
	  
	  t=new JTextField();
	  
	  p=new JPanel();
	  p.setBackground(Color.GRAY);
	  
	   g=new   GridLayout(4,4);
	   p.setLayout(g);
	   b=new JButton[a.length];
	  for(int i=0;i<16;i++)
		  
	  {b[i]=new JButton(a[i]);
		 // p.add(a[i]);
	  p.add(b[i]);//把吧b[]加入面板p中
	  }		  
	  f.add(t,BorderLayout.NORTH);//设置一个分格的,作用把文本框放在最上面
	  f.add(p,BorderLayout.CENTER);//把网格布局放在下面,实现计算器的分布
	   
	   f.setSize(300,280);
	   f.setVisible(true); 
	   
	   p.setLayout(g);
	   
	   f.add(p);

   }
public static void main(String[] args) {
	 new 计算机界面();
}

}

  

package cuko;



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

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class 换颜色的窗体 {
    JFrame jf;
    JPanel[] jp;
    JButton[] jb;
    public 换颜色的窗体()
    {
        jf = new JFrame();
        jp = new JPanel[2];
        for(int i =0; i 
 

  我也不知道

你可能感兴趣的:(计算器、换颜色窗口)