aide java if_else答案_【图片】小白求教 if else明明判断对了 为什么输出的答案是else里的【java吧】_百度贴吧...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

package text1;

import java.awt.*;

import java.awt.event.*;

public class Example {

static TextField tf1, tf2;

static Label label;

public static void main(String[] args) {

Frame f = new Frame("我的窗口");

f.setLayout(null);

f.setSize(400,300);

f.setLocation(300,200);

f.setVisible(true);

MyWindowListerner mw= new MyWindowListerner();

f.addWindowListener(mw);

/*Label*/label =new Label();

f.add(label);

label.setBounds(40,200,150,30);

String s = "欢迎~";

label.setText(s);

/*TextField*/ tf1 = new TextField(30);

tf1.setBounds(40,60,150,30);

f.add(tf1);

/*TextField*/ tf2 = new TextField(30);

tf2.setBounds(40,100,150,30);

f.add(tf2);

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

f.add(button1);

button1.setBounds(40,150,50,30);

button1.addMouseListener(new MouseAdapter(){

public void mouseClicked(MouseEvent e){

String s1 = tf1.getText();

String s2 = tf2.getText();

if (s1 == "111" && s2 == "123")

label.setText("登录成功");

else

label.setText("登录失败");

}

});

Button button2 =new Button("取消");

f.add(button2);

button2.setBounds(100,150,50,30);

button2.addMouseListener(new MouseAdapter(){

public void mouseClicked(MouseEvent e){

System.exit(0);

}

});

f.setVisible(true);

}

}

class MyWindowListerner implements WindowListener{

public void windowClosing(WindowEvent e){

Window window = e.getWindow();

window.setVisible(false);

window.dispose();

}

public void windowActivated(WindowEvent e){

}

public void windowClosed(WindowEvent e){

}

public void windowDeactivated(WindowEvent e){

}

public void windowDeiconified(WindowEvent e){

}

public void windowIconified(WindowEvent e){

}

public void windowOpened(WindowEvent e){

}

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值