登录界面

1.组合框(JComboBox):addItem(Object item):向选项列表尾部添加选项。
setMaximumRoxCount(int count):设置选项最大的显示行数,默认为八行。(name.setMaximumRowCount(4);我设置的是四行)
setEditable:设置选择框可否编辑,默认为不可编辑,即false。 (name.setEditable(true);)
2.标签(JLabel):private JLabel nameLbl,styleLbl,sizeLbl;
JLabel user = new JLabel("用户名 :");
3.文本框(JTextField):private JTextField nameText,styleText,sizeText;
JTextField mimaText = new JTextField();

import java.awt.Dimension;

import java.awt.Toolkit;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPasswordField;

import javax.swing.JTextField;

public class Test26 { public static void main(String[] args) {

final String userName = "abc";

final String passwrod = "123";

JFrame jFrame = new JFrame("登陆界面");

Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();

jFrame.setBounds(((int)dimension.getWidth() - 200) / 2, ((int)dimension.getHeight() - 300) / 2, 200, 150);

jFrame.setResizable(false);

jFrame.setLayout(null);

jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JLabel label1 = new JLabel("姓名");

label1.setBounds(10, 10, 100, 30);

jFrame.add(label1);

JLabel label2 = new JLabel("密码");

label2.setBounds(10, 40, 100, 30);

jFrame.add(label2);

final JTextField text1 = new JTextField();

text1.setBounds(50, 15, 130, 20);

jFrame.add(text1);

final JPasswordField text2 = new JPasswordField();

text2.setBounds(50, 45, 130, 20);

jFrame.add(text2);

JButton button = new JButton("Login");

button.setBounds(10, 75, 170, 40);

button.addActionListener(new ActionListener() {

@Override public void actionPerformed(ActionEvent e) {

if(userName.equals(text1.getText()) && passwrod.equals(text2.getText())) {

JOptionPane.showMessageDialog(null, "登陆成功误", "提示", JOptionPane.INFORMATION_MESSAGE);

}

else {

JOptionPane.showMessageDialog(null, "错误", "提示", JOptionPane.ERROR_MESSAGE); text1.setText("");

text2.setText("");

}

}

});

jFrame.add(button); jFrame.setVisible(true);

}

}

posted on 2016-04-17 16:50  旭日易成  阅读(151)  评论(0编辑  收藏  举报

导航