用户图形界面的实现

package work_15;


import java.awt.Button;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.TextField;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;


public class lalala extends Frame implements WindowListener, ActionListener {
private Button b1,b2,b3,b4,b5;
private Label L1,L2,L3,L4,L5;
private TextField t1,t2,t3;


public void actionPerformed(ActionEvent xpp) 
{
String n;
n=xpp.getActionCommand();
if(n.equals("连接"))
{
String m=t1.getText().concat(t2.getText());
t3.setText(m);
}
if(n.equals("加"))
{
String a=t1.getText();
String b=t2.getText();
double c=Double.parseDouble(a)+Double.parseDouble(b);
t3.setText(c+"");
}
if(n.equals("乘"))
{
String a=t1.getText();
String b=t2.getText();
double c=Double.parseDouble(a)*Double.parseDouble(b);
t3.setText(c+"");
}
if(n.equals("减"))
{
String a=t1.getText();
String b=t2.getText();
double c=Double.parseDouble(a)-Double.parseDouble(b);
t3.setText(c+"");
}
if(n.equals("除"))
{
String a=t1.getText();
String b=t2.getText();
double c=Double.parseDouble(a)+Double.parseDouble(b);
t3.setText(c+"");
}
else if(n.equals("清除"))
{
t1.setText("");
t2.setText("");
t3.setText("");
}
}
public void windowActivated(WindowEvent e) {}
public void windowClosed(WindowEvent xpp) 
{

}
public void windowClosing(WindowEvent xpp) 
{
Window f=(Window)xpp.getSource();
f.setVisible(false);
f.dispose();
}
public void windowDeactivated(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowOpened(WindowEvent e) {}
public lalala()
{
super("基本运算");
setLocation(300,500);
setSize(600,200);
setLayout(new GridLayout(3,5,5,5));//行列水平竖直间距
Font f=new Font("宋体",Font.ITALIC,25);//字体型号
setFont(f);
setForeground(Color.yellow);
setBackground(Color.darkGray);
b1=new Button("连接");
b2=new Button("清除");
b3=new Button("加");
b4=new Button("乘");
b5=new Button("减");
L1=new Label("+");
L2=new Label("=");
L3=new Label("第一个数");
L4=new Label("第二个数");
L5=new Label("结果");
t1=new TextField();
t2=new TextField();
t3=new TextField();
add(L3);
add(new Label());
add(L4);
add(new Label());
add(L5);
add(t1);
add(L1);
add(t2);
add(L2);
add(t3);
add(b1);
add(b4);
add(b3);
add(b5);
add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
addWindowListener(this);//关闭窗口

}

public static void main(String[] args) {
lalala w=new lalala();
w.setVisible(true);



}


}




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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值