日期:2014-05-20 浏览次数:20686 次
package frameDemo;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.*;
public class calculator {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
calculator c=new calculator();
}
private JFrame _calculateJFrame;
private JButton _mutilJButten,_DivJButton,_AddJButton,_subJButton;
private JTextField jTextFileFirst,jTextFileSecond,jTextFileLast;
private JPanel jPanelFirst,jPanelSecond,jPanelThird,jPanelFour;
public calculator(){
//_calculateJFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
_calculateJFrame=new JFrame("Calculator");
_calculateJFrame.setLayout(new GridLayout(4,1));
_calculateJFrame.setBounds(40, 30, 400, 380);
_calculateJFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//注意这行代码,如果放到最后不会显示在画布上添加的东西
_calculateJFrame.setVisible(true);
//添加四个画布
jPanelFirst = new JPanel();
jPanelSecond=new JPanel();
jPanelThird=new JPanel();
jPanelFour=new JPanel();
_calculateJFrame.add(jPanelFirst);
_calculateJFrame.add(jPanelSecond);
_calculateJFrame.add(jPanelThird);
_calculateJFrame.add(jPanelFour);
//_calculateJFrame.setVisible(true);
jPanelFirst.setLayout(null);
jPanelFirst.setBackground(Color.yellow);
jTextFileFirst=new JTextField();
jPanelFirst.add(jTextFileFirst);
jTextFileFirst.setSize( jPanelFirst.getWidth(),jPanelFirst.getHeight());
//jTextFileFirst.setSize(100, 100);
//jTextFileFirst.setBackground(Color.black);
jPanelSecond.setLayout(null);
jPanelSecond.setBackground(Color.red);
jTextFileSecond=new JTextField();
jTextFileSecond.setSize( jPanelSecond.getWidth(),jPanelSecond.getHeight());
jPanelSecond.add(jTextFileSecond);
jPanelThird.setLayout(null);
jPanelThird.setBackground(Color.blue);
//添加+ - * /
_AddJButton=new JButton("+");
jPanelThird.add(_AddJButton);
//_AddJButton.setBounds(jPanelThird.getLocation().x,jPanelThird.getLocation().y,jPanelThird.getWidth()/4,jPanelThird.getHeight());