网上找的~~~自己还没看
public class login extends JFrame
{
private JComboBox nameJComboBox;
private JPanel userJPanel;
private JLabel pictureJLabel;
private JButton okJButton, cancelJButton;
private JLabel nameJLabel, passwordJLabel, note;
private JPasswordField passwordJPasswordField;
private String name1;
private String password1;
private String user;
private ImageIcon myImageIcon;
public login(){
createUserInterface(); // 调用创建用户界面方法
}
private void createUserInterface(){
Container contentPane = getContentPane();
contentPane.setLayout(null);
userJPanel = new JPanel();
userJPanel.setBounds(35, 120, 300, 96);
userJPanel.setBorder(BorderFactory.createEtchedBorder()); // 显示一圈边儿
userJPanel.setLayout(null);
contentPane.add(userJPanel);
nameJComboBox = new JComboBox();
nameJComboBox.setBounds(100, 12, 170, 25);
nameJComboBox.addItem("admin");
nameJComboBox.addItem("aloie");
nameJComboBox.setSelectedIndex(0);
nameJComboBox.setEditable(true);
userJPanel.add(nameJComboBox);
pictureJLabel = new JLabel();
pictureJLabel.setBounds(45, 0, 380, 118);
pictureJLabel.setIcon(new ImageIcon("pic.gif"));
contentPane.add(pictureJLabel);
nameJLabel = new JLabel("姓 名:");
nameJLabel.setBounds(20, 12, 80, 25);
userJPanel.add(nameJLabel);
passwordJPasswordField = new JPasswordField();
passwordJPasswordField.setBounds(100, 60, 170, 25);
userJPanel.add(passwordJPasswordField);
passwordJLabel = new JLabel("密 码:");
passwordJLabel.setBounds(20, 60, 80, 25);
userJPanel.add(passwordJLabel);
note = new JLabel("密码与用户名相同");
note.setBounds(0, 295, 180, 25);
add(note);
okJButton = new JButton("登 陆");
okJButton.setBounds(60, 250, 80, 25);
contentPane.add(okJButton);
okJButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
okJButtonActionPerformed(event);
}
}
);
cancelJButton = new JButton("取 消");
cancelJButton.setBounds(210, 250, 80, 25);
contentPane.add(cancelJButton);
cancelJButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
System.exit(0); // 退出登陆
}
}
);
setTitle("登陆窗口");
setSize(380, 350);
setResizable(false); // 将最大化按钮设置为不可用
}
private void okJButtonActionPerformed(ActionEvent event)
{
// okJButton响应事件,检查用户名和密码的匹配
name1 = nameJComboBox.getSelectedItem().toString();
if (name1.equals("admin"))
{
if (passwordJPasswordField.getText().equals("admin"))
{
showNewWindow();
setVisible(false);
} else
{
JOptionPane.showMessageDialog(this, "密码错误,拒绝登陆",
"密码错误 !", JOptionPane.ERROR_MESSAGE);
}
}
else if (name1.equals("aloie"))
{
if (passwordJPasswordField.getText().equals("aloie"))
{
showNewWindow();
setVisible(false);
}
else
{
JOptionPane.showMessageDialog(this, "密码错误,拒绝登陆",
"密码错误 !", JOptionPane.ERROR_MESSAGE);
}
}
}
public void showNewWindow()
{
JFrame jf = new JFrame("main Frame");
jf.setSize(500, 400);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
login mylogin = new login();
mylogin.setVisible(true);
mylogin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
分享到:
相关推荐
这是一个基于matlab的gui 登陆界面,简单易懂。
登陆界面的代码,大家有兴趣可以看看哦哦,可能不好别见怪
创建一个GUI用户登陆界面,使使用者可以方便登录。
登陆界面,是用贵做的,可以登录的哦,还可以注册
Matlab GUI登录界面设计!欢迎下载!
用 java GUI swing组件编写的简单的登陆界面
北邮国院大二JAVA大作业
EAS 登陆界面的修改,例如登陆界面图片 logo 等之类的更改
matlab GUI密码登陆界面,已经调好(已经标注好),可直接用,直接运行就可以,我设置的登陆密码是123,用户名也为123,可以自己更改,另一个也可以用!
GUI登陆窗口
MATLAB gui 密码登陆程序,是MATLAB gui学习手记第十一章的11.1 类似的程序代码
java 初学者练习的小项目,做一个登录界面,采用的文件读取,加的有图片,,里面有可运行的java工程源码和jar架包。交作业(你懂得),学习必备。。
通过SWING设计登陆界面,通过属性配置文件来读取正确信息,并对相关问题进行剖析和总结,希望对大家能有所帮助.
图形用户界面(GUI)初学者。 3.学习要点: (1) 主要包:java.awt, javax.swing (2) 基本组件(JButton,JLable,JTextField......)及方法 (3)基本容器(JFrame......)及方法 (4) 事件处理机制 (5)容器布局...
用java写GUI图形界面 public class login extends JFrame { private JComboBox nameJComboBox; private JPanel userJPanel; private JLabel pictureJLabel; private JButton okJButton,cancelJButton; ...
基于MATLAB GUI工具开发的登陆界面,美观实用.
用matlab制作的一个登录界面,可供学习参考
登陆界面课程设计(Java版) 简单的GUI图形界面设计
小巧功能强大的图形用户界面设计工具,操作简洁,可以将设计的界面处理演示.