java main函数里面的变量i怎么获取addActionListener监听里jtf_username.getText()的值?0
wzprf2013.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);
}