计算器的 窗口 来自 ------想飞的菜鸟

package love;

import java.awt.*;
import java.awt.event.*;

public class count0 //extends Frame //implements ActionListener
{
boolean prev=true;
boolean repeat = true;
private Frame frame;
private TextField tf;
// 声明 啊别扭数组
Button b[] = new Button[16];


//private String b1;

// 构造函数
public count0()
{
// frame 框架
frame = new Frame("我的计算器");
// 设置 布局管理器
frame.setLayout(new BorderLayout());

// 添加 监听事件 之后可以退出来
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
System.exit(0);
}

});




}



public void doit()
{
// 声明 面板 panel
Panel panel1 = new Panel();
Panel panel2 = new Panel();
//panel1.setLayout(new FlowLayout(FlowLayout.CENTER,5,5));
// 在这里 用 GridLauout() 效果更好!
panel1.setLayout(new GridLayout(4,4,5,5));


// 定义按钮数组名
String[] buttonname={"1","2","3","+","4","5","6","-","7","8","9","*",".","0","=","/"};

// 定义按钮 通过循环的方法
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
{
// 定义按钮
b[i*4+j] = new Button(buttonname[i*4+j]);

// 注册监听器
b[i*4+j].addMouseListener(new myMouselistener());

// 将按钮 添加至panel1 中
panel1.add(b[i*4+j]);

}


/*
// 定义 组件 按钮和 文本框
Button b1 = new Button("1");
Button b2 = new Button("2");
Button b3 = new Button("3");
Button b4 = new Button("+");
Button b5 = new Button("4");
Button b6 = new Button("5");
Button b7 = new Button("6");
Button b8 = new Button("-");
Button b9 = new Button("7");
Button b10 = new Button("8");
Button b11 = new Button("9");
Button b12 = new Button("*");
Button b13 = new Button(".");
Button b14 = new Button("0");
Button b15 = new Button("=");
Button b16 = new Button("/");

// 将 按钮添加至 panel1 中
// 注册 监听器
panel1.add(b1);
// 注册监听器
b1.addActionListener( new myactionlistener());

panel1.add(b2);
panel1.add(b3);
panel1.add(b4);
panel1.add(b5);
panel1.add(b6);
panel1.add(b7);
panel1.add(b8);
panel1.add(b9);
panel1.add(b10);
panel1.add(b11);
panel1.add(b12);
panel1.add(b13);
panel1.add(b14);
panel1.add(b15);
panel1.add(b16);
*/
// 用内部类 实现监听器



// 定义文本框

tf = new TextField("0",10);
tf.setEditable(true);

// 将文本框 添加至 Panel 2

panel2.add(tf);




// 将 面板 添加至窗体 frame中
frame.add("Center",panel1);
frame.add("North",panel2);



// 设置擦混个体不可变
frame.setResizable(false);
// 设置 窗体的大小 和 显示

frame.setBounds(400,200,300,400);
//frame.setSize(60,80);
frame.setVisible(true);



}



public void pressNumber(String s)
{
if(prev)
{
tf.setText(s);
prev = false;
}
else
{

}
}



//


class myMouselistener extends MouseAdapter
{
public void mousePressed(MouseEvent e)
{

Object source = e.getSource();

if(source == b[0])
{
pressNumber("1");



return;

}



if(source == b[1])
{

pressNumber("2");
return;

}
}

}

//public Strign(button)



/**
* 在主函数湖中仅仅 创建一个对象 和电泳 doit() 函数!
* 施主函数 简介!
* 拜年语查看!
*
* */
public static void main(String[] args)
{
count0 lov = new count0();
lov.doit();



// TODO Auto-generated method stub

}


}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值