您的当前位置:首页java程序

java程序

2022-07-15 来源:乌哈旅游
 import javax.swing.JDialog;

import java.awt.Dimension; import java.awt.Toolkit; import javax.swing.JButton; import javax.swing.JPanel;

import java.awt.Rectangle;

import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JLabel; import javax.swing.JTextField;

import javax.swing.WindowConstants; import javax.swing.JPasswordField; public class LoginDialog extends JDialog { /** * */ private static final long serialVersionUID = -4130130495104582329L; private JPanel jPanel = null; private JButton loginButton = null; private JButton clolseButton = null; private JLabel usernameLabel = null; private JLabel passwordLabel = null; private JTextField usernameField = null; private JPasswordField passwordField = null; /** * This method initializes * */

public LoginDialog() { super(); initialize(); }

/**

* This method initializes this * */

private void initialize() { this.setSize(500,320);

this.setContentPane(getJPanel()); this.setModal(false); this.setTitle(\"登录\");

this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } });

}

private void closeDialog() {

this.dispose(); }

/**

* This method initializes jPanel *

* @return javax.swing.JPanel */

private JPanel getJPanel() { if (jPanel == null) {

passwordLabel = new JLabel();

passwordLabel.setBounds(new Rectangle(140, 117, 52, 32)); passwordLabel.setText(\"密 码:\"); usernameLabel = new JLabel();

usernameLabel.setBounds(new Rectangle(139, 55, 52, 32)); usernameLabel.setText(\"用户名:\"); jPanel = new JPanel(); jPanel.setLayout(null);

jPanel.add(getJButton(), null); jPanel.add(getJButton1(), null);

jPanel.add(usernameLabel, null); jPanel.add(passwordLabel, null); jPanel.add(getJTextField(), null);

jPanel.add(getJPasswordField(), null); }

return jPanel; }

/**

* This method initializes jButton *

* @return javax.swing.JButton */

private JButton getJButton() { if (loginButton == null) {

loginButton = new JButton();

loginButton.setBounds(new Rectangle(138, 219, 80, 32)); loginButton.setText(\"登录\");

loginButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { String username = usernameField.getText(); @SuppressWarnings(\"deprecation\") String password = passwordField.getText(); if (username == null || username.equals(\"\")) {

javax.swing.JOptionPane.showMessageDialog(null, \"用户名不能为空!\");

} else if (password == null || password.equals(\"\")) { javax.swing.JOptionPane.showMessageDialog(null, \"密码不能为空!\");

} else if (username.equals(\"Admin\") && password.equals(\"123\")) {

javax.swing.JOptionPane.showMessageDialog(null, \"用户名密码正确 可以进入主页面!\"); } else {

javax.swing.JOptionPane.showMessageDialog(null, \"用户名密码不正确!\"); usernameField.setText(\"\"); passwordField.setText(\"\"); } }

}); }

return loginButton; }

/**

* This method initializes jButton1 *

* @return javax.swing.JButton */

private JButton getJButton1() { if (clolseButton == null) {

clolseButton = new JButton();

clolseButton.setBounds(new Rectangle(288, 218, 80, 32)); clolseButton.setText(\"关闭\");

clolseButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { System.exit(0); } }); }

return clolseButton; }

/**

* This method initializes jTextField *

* @return javax.swing.JTextField */

private JTextField getJTextField() { if (usernameField == null) {

usernameField = new JTextField();

usernameField.setBounds(new Rectangle(191, 53, 165, 35)); }

return usernameField; }

/**

* This method initializes jPasswordField *

* @return javax.swing.JPasswordField */

private JPasswordField getJPasswordField() { if (passwordField == null) {

}

passwordField = new JPasswordField();

passwordField.setBounds(new Rectangle(191, 114, 165, 35)); }

return passwordField; }

@SuppressWarnings(\"deprecation\") public static void main(String args[]) {

LoginDialog dialog = new LoginDialog();

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); dialog.setBounds((screenSize.width - 500) / 2, (screenSize.height - 320) / 2, 500, 320); dialog.show(); }

因篇幅问题不能全部显示,请点此查看更多更全内容