用java比较数字大小_JAVA比较2个数大小

packagezuoye1;importjava.awt.*;importjava.awt.event.*;publicclassActionEventDemolimplementsWindowListener{Framef=newFrame("ActionEventDemol");Labelmsg=newLabel("第一个数:...

package zuoye1;

import java.awt.*;

import java.awt.event.*;

public class ActionEventDemol implements WindowListener{

Frame f = new Frame("ActionEventDemol");

Label msg = new Label("第一个数:",Label.CENTER);

Label msg1 = new Label("第二个数:",Label.CENTER);

Label msg2 = new Label("大的数:",Label.CENTER);

Label msg3 = new Label("",Label.CENTER);

TextField name = new TextField(10);

TextField output = new TextField(10);

Button bConfirm = new Button("确定");

Button bReset = new Button("重置");

Listener lsn = new Listener(this);

public ActionEventDemol(){

f.setLayout(null);

f.add(msg);

f.add(msg2);

f.add(name);

f.add(output);

f.add(bConfirm);

f.add(bReset);

f.add(msg1);

msg.setBounds(20,40,120,10);

msg1.setBounds(20,60,120,10);

msg2.setBounds(20,90,120,10);

msg3.setBounds(50,90,120,10);

name.setBounds(140, 40, 140, 20);

output.setBounds(140, 60,140, 20);

bConfirm.setBounds(40, 110, 70, 20);

bReset.setBounds(190, 110, 70, 20);

f.setSize(300,150);

f.setVisible(true);

bConfirm.addActionListener(lsn);

bReset.addActionListener(lsn);

f.addWindowListener(this);

}

public static void main(String[] args){

new ActionEventDemol();

}

public void windowActivated(WindowEvent e){}

public void windowDeactivated(WindowEvent e){}

public void windowIconified(WindowEvent e){}

public void windowDeiconified(WindowEvent e){}

public void windowOpened(WindowEvent e){}

public void windowClosed(WindowEvent e){}

public void windowClosing(WindowEvent e){

System.exit(0);

}

class Listener implements ActionListener{

ActionEventDemol ob;

Listener(ActionEventDemol ob){

this.ob = ob;

}

public void actionPerformed(ActionEvent e){

if(e.getSource() == ob.bConfirm){

String s1 = name.getText();

String s2 = output.getText();

double d1;

double d2;

try{

d1 =Double.parseDouble(s1);

d2 =Double.parseDouble(s2);

if(d1>d2)

(msg3.setText(s1);)

else(msg3.setText(s2);)

}catch (NumberFormatException e1){

label4.setText("请输入数字");

}

else if(e.getSource()==ob.bReset)

{ob.name.setText("");

ob.output.setText("");

}

}

}

}

问题在那里?

展开

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值