日期:2014-05-20 浏览次数:20769 次
package com.lesson;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
import javax.swing.*;
public class JieMian1 {
public static void main(String[] args) {
tt t=new tt();
System.out.println(t.cn);
}
}
class tt extends JFrame implements ActionListener
{
long cn;
int pw;
JPanel jp1,jp2,jp3;
JButton jb1,jb2;
JLabel jl1,jl2;
JTextField jtf;
JPasswordField jpf;
public tt()
{
jp1=new JPanel();
jp2=new JPanel();
jp3=new JPanel();
jb1=new JButton("确认");
jb2=new JButton("取消");
jl1=new JLabel("账 号");
jl2=new JLabel("密 码");
jtf=new JTextField(10);
jtf.addActionListener(this);
jtf.setActionCommand("gettext");
jpf=new JPasswordField(10);
this.setLayout(new GridLayout(3,1));
jp1.add(jl1);
jp1.add(jtf);
jp2.add(jl2);
jp2.add(jpf);
jp3.add(jb1);
jp3.add(jb2);
this.add(jp1);
this.add(jp2);
this.add(jp3);
this.setSize(200,200);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals("gettext"))
{
cn=Long.parseLong(jtf.getText());
}
else
System.out.println("no");
}
}
public class JieMian1 {
static boolean flag=true;
public static void main(String[] args) {
tt t = new tt();
while(flag){
try {
Thread.sleep(10);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println(t.cn);
}
}
class tt extends JFrame implements ActionListener {
long cn;
int pw;
JPanel jp1, jp2, jp3;
JButton jb1, jb2;
JLabel jl1, jl2;
JTextField jtf;
JPasswordField jpf;
public tt() {
jp1 = new JPanel();
jp2 = new JPanel();
jp3 = new JPanel();
jb1 = new JButton("确认");
jb2 = new JButton("取消");
jl1 = new JLabel("账 号");
jl2 = new JLabel("密 码");
jtf = new JTextField(10);
jtf.setBackground(Color.BLACK);
jtf.addActionListener(this);
jtf.setActionCommand("gettext");
jpf = new JPasswordField(10);
this.setLayout(new GridLayout(3, 1));
jp1.add(jl1);
jp1.add(jtf);
jp2.add(jl2);
jp2.add(jpf);
jp3.add(jb1);
jp3.add(jb2);
this.add(jp1);
this.add(jp2);
this.add(jp3);
this.setSize(200, 200);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("dianji");
if (e.getActionCommand().equals("gettext")) {
cn = Long.parseLong(jtf.getText());
JieMian1.flag=false;//添加个这个
} else
System.out.println("no");
}
}