java中的控件_java窗体中,控件的外观是怎么绘制的?

packagetest;importjava.awt.Button;importjava.awt.Color;importjava.awt.FlowLayout;importjava.awt.Frame;importjava.awt.Label;importjava.awt.TextField;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.WindowAdapter;importjava.awt.event.WindowEvent;public class Round extends Frame implementsActionListener {

TextField t1, t2, t3, t4;

Button b1;

Button btnExit;publicRound() {

setLayout(newFlowLayout());

t1= new TextField(20);

t1.setBackground(Color.orange);

t2= new TextField(20);

t2.setBackground(Color.orange);

t3= new TextField(20);

t3.setBackground(Color.orange);

t4= new TextField(20);

t4.setBackground(Color.orange);

b1= new Button("计算");

btnExit= new Button("退出");

add(new Label("输入圆的半径:"));

add(t1);

add(new Label("得出圆的直径:"));

add(t2);

add(new Label("得出圆的面积:"));

add(t3);

add(new Label("得出圆的周长:"));

add(t4);

add(b1);

add(btnExit);

addWindowListener(newWindowAdapter() {public voidwindowClosing(WindowEvent e) {

System.exit(0);

}

});

b1.addActionListener(this);

btnExit.addActionListener(this);

setVisible(true);

setBounds(200, 200, 200, 300);

validate();

}public voidactionPerformed(ActionEvent e) {if (e.getSource() ==b1) {doubletemp, r, a, c;

temp=Float.parseFloat(t1.getText());

r= 2 *temp;

a= 3.14 * temp *temp;

c= 2 * 3.14 *temp;

t2.setText(String.valueOf(r));

t3.setText(String.valueOf(a));

t4.setText(String.valueOf(c));

}if (e.getSource() ==btnExit) {

System.exit(0);

}

}public static voidmain(String args[]) {newRound();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值