java swing 计算器的代码,java swing计算器

[java]代码库import java.awt.*;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

public class CalFrame extends Frame {

//http://www.2cto.com/kf/201405/298165.html

public void launchFrame() {

this.setTitle("test");

this.setBounds(20, 20, 300, 450);

this.setMaximumSize(null);

this.setVisible(true);

this.setResizable(false);

this.addWindowListener(new WindowAdapter() {

@Override

public void windowClosing(WindowEvent e) {

System.exit(0);

}

});

MenuBar menu = new MenuBar();

Menu file = new Menu("File");

Menu edit = new Menu("Edit");

Menu source = new Menu("Source");

Menu refa = new Menu("Refactor");

menu.add(file);

menu.add(edit);

menu.add(source);

menu.add(refa);

this.setMenuBar(menu);

Panel p = new Panel();

p.setLayout(new BorderLayout(5, 5));

p.setBackground(Color.LIGHT_GRAY);

this.add(p);

TextArea t = new TextArea("0", 2, 1, TextArea.SCROLLBARS_NONE);

t.setBounds(new Rectangle(280, 40));

t.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

t.setEditable(false);

System.out.println(t.getWidth() + "----" + t.getHeight());

p.add(t, BorderLayout.NORTH);

Panel sub = new Panel();

sub.setBackground(Color.GRAY);

sub.setBounds(new Rectangle(280, (p.getHeight() - t.getHeight())));

p.add(sub, BorderLayout.CENTER);

sub.setLayout(new GridLayout(6, 5, 5, 5));

for (int i = 0; i < 5; i++) {

for (int j = 0; j < 6; j++) {

Button b = new Button("i");

int width = sub.getWidth() / 5;

int height = sub.getHeight() / 6;

b.setSize(width, height);

b.setBackground(Color.LIGHT_GRAY);

sub.add(b);

}

}

}

public static void main(String[] args) {

new CalFrame().launchFrame();

}

}

[源代码打包下载]

694748ed64b9390909c0d88230893790.png

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值