日期:2014-05-20 浏览次数:20811 次
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class UsernameAndPassword{
public static void main(String[] args){
JFrame frame = new JFrame();
final JLabel label1 = new JLabel("name", SwingConstants.RIGHT);
final JLabel label2 = new JLabel("password", SwingConstants.RIGHT);
final JTextField jtf1 = new JTextField(15);
final JPasswordField jpf2 = new JPasswordField(15);
//final char[] pw;
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
panel.add(label1);
panel.add(jtf1);
panel.add(label2);
panel.add(jpf2);
JButton button = new JButton("登录");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
char[] pw = jpf2.getPassword();
String passWord = new String(pw);
//if(nameField.getText()=="")
if(jtf1.getText().equals("")){
JOptionPane.showMessageDialog(null, "用户名不能为空!");