java 变量监听_java main函数里面的变量i怎么获取addActionListener监听里jtf_username.getText()的值?...

java main函数里面的变量i怎么获取addActionListener监听里jtf_username.getText()的值?0

00e27ab806e4881f8254fe7ae8741834.pngwzprf2013.10.11浏览198次分享举报

public class ShowMian extends JFrame {

JFrame lockjf;// 锁屏界面

boolean isexit = false;

JPanel lockjp = new JPanel();;

JLabel jl_username;

JLabel jl_password;

JButton jb_ensure;// 确定按钮

JButton jb_result;// 撤消按钮

JTextField jtf_username;// 用户名

JPasswordField jtf_password;// 用户密码

// 用来得到屏幕的分辨率

Toolkit toolkit;

// 用来接受屏幕返回的分辨率

int xscreen;// 屏幕的x坐标

int yscreen;// 屏幕的y坐标

// 定义线程让窗体每秒获得一次焦点

Thread thread;

String username;

public ShowMian() {

// TODO Auto-generated constructor stu

// 初始化界面

lockjp = new driver();

lockjf = this;

jl_username = new JLabel("用户名:");

jl_password = new JLabel("密 码:");

jtf_username = new JTextField();

jtf_password = new JPasswordField();

jb_ensure = new JButton("确定");

jb_result = new JButton("取消");

// 得到当前的分辨率

toolkit = this.getToolkit();

final Dimension dimension = toolkit.getScreenSize();

xscreen = dimension.width;

yscreen = dimension.height;

//System.out.println(xscreen + ":" + yscreen);

// 设置主窗体的大小

// 把各个组件注册到jframe

add(lockjp);

lockjp.setLayout(null);

lockjp.add(jl_username);

lockjp.add(jl_password);

lockjp.add(jtf_username);

lockjp.add(jtf_password);

lockjp.add(jb_ensure);

lockjp.add(jb_result);

// 设置各个组件的位置

。。。

// lable的设置

。。。

// textare的设置

jtf_username.setBounds(jl_username.getX() + 60, jl_username.getY(), 140, 20);

// button的设置

jb_ensure.setBounds(jl_username.getX(), jl_username.getY() + 110, 60, 30);

jb_result.setBounds(jb_ensure.getX() + 140, jb_ensure.getY(), 60, 30);

// 设置按钮事

jb_ensure.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {

// System.out.println(jtf_username.getText().equals("wayking")+":"+jtf_password.getText().equals("2925138"));

// TODO Auto-generated method stub

//System.out.println(jtf_username.getText());

//System.out.println(jtf_password.getPassword());

username = jtf_username.getText();

System.out.println(username);

char[] password=jtf_password.getPassword();

System.out.println(password);

if (jtf_username.getText().equalsIgnoreCase("1")

&& jtf_password.getText().equalsIgnoreCase("1")) {

// System.out.println("11111111111111111111111111");

System.exit(1);

} else if (jtf_username.getText().equalsIgnoreCase("fangguangzhi")

&& jtf_password.getText().equalsIgnoreCase("1234")) {

// System.out.println("11111111111111111111111111");

System.exit(1);

} else {

jtf_username.setText("");

jtf_password.setText("");

}

}

});

jb_result.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {

// TODO Auto-generated method stub

jtf_username.setText("");

jtf_password.setText("");

}

});

。。。

public static void main(String[] args) throws IOException {

new ShowMian();

String i ="";

//System.out.println(i);

String j ="";

new TxtWirte().DOWriteTxt("D://问好.txt", i,j);

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值