The second JAVA job, the second java job

Source: Internet
Author: User

The second JAVA job, the second java job

I am working on the logon interface. JButton, JComboBox, JOptionPane, JPasswordField, and JTextField are used to implement event-related functions. When the account and password entered are both 123, the system prompts that the logon is successful. Otherwise, the logon fails!

The color and font classes in java are also added. The font is CENTER_BASELINE and the color is black. The shortcut keys are added to the OK and cancel buttons.

However, ImageIcon (image) is not implemented.

The source code is as follows:

1 package wole; 2 3 import java. awt. color; 4 import java. awt. font; 5 import java. awt. event. actionEvent; 6 import java. awt. event. actionListener; 7 import java. awt. event. keyEvent; 8 import javax. swing. imageIcon; 9 import javax. swing. JButton; 10 import javax. swing. JComboBox; 11 import javax. swing. JFrame; 12 import javax. swing. JLabel; 13 import javax. swing. JOptionPane; 14 import javax. swing. JPanel; 15 Import javax. swing. JPasswordField; 16 import javax. swing. JTextField; 17 18 public class showLoginFrame extends JFrame implements ActionListener {19 20 private static final long serialVersionUID = 1L; 21 22 JPanel p; 23 JButton a; 24 JButton B; 25 JLabel u; 26 JLabel m; 27 JLabel se; 28 JLabel t; 29 JLabel shfen; 30 JComboBox kuang3; 31 ImageIcon tu; 32 JTextField kuang1; 33 JPasswordField kuang2; 34 String role [] = {"manager", "him"}; 35 36 public showLoginFrame () {37 38 se = new JLabel ("network site internal capacity management system"); 39 se. setBounds (115, 20,420, 50); 40 se. setFont (new Font ("", Font. CENTER_BASELINE, 20); 41 se. setForeground (Color. black); 42 43 u = new JLabel ("username:"); 44 u. setFont (new Font ("", Font. CENTER_BASELINE, 15); 45 u. setForeground (Color. black); 46 47 m = new JLabel ("Password:"); 48 m. setFont (New Font ("", Font. CENTER_BASELINE, 15); 49 m. setForeground (Color. black); 50 51 shfen = new JLabel ("Identity:"); 52 shfen. setFont (new Font ("", Font. CENTER_BASELINE, 15); // set the font 53 shfen. setForeground (Color. black); 54 shfen. setBounds (130,200,100, 50); 55 56 kuang3 = new JComboBox (role); 57 kuang3.setForeground (Color. black); 58 kuang3.setBounds (210,210,100, 25); 59 60 kuang1 = new JTextField (); 6 1 kuang1.setBounds (210,100,180, 25); 62 kuang1.setForeground (Color. black); 63 64 kuang2 = new JPasswordField (); 65 kuang2.setBounds (210,160,180, 25); 66 kuang2.setEchoChar ('*'); // set the symbol 67 kuang2.setForeground (Color. black); 68 69 a = new JButton ("OK (ALT + Y)"); 70. setMnemonic (KeyEvent. VK_Y); // Add the shortcut key for the OK button, ALT + G 71. setForeground (Color. black); // The font color is blue 72. addActionListener (this); // click this button. Listen 73 74 B = new JButton ("cancel (ALT + N)"); 75 B. setMnemonic (KeyEvent. VK_N); 76 B. setForeground (Color. black); 77 B. addActionListener (this); 78 79 p = new JPanel (); 80 tu = new ImageIcon ("/img/22.jpg"); // this is the image 81 t = new JLabel (tu ); // Add the image to JLabel 82 p. add (t); // add to JPanel 83 84 p. setBounds (0, 0,560,400); // picture 560*400 (width * Height) 85 B. setBounds (320,270,120, 35); 86. setBounds (120,270,120, 35); 87 u. set Bounds (130, 90,100, 50); 88 m. setBounds (130,150,100, 50); 89 90 add (se); 91 add (u); 92 add (m); 93 add (shfen); 94 add (kuang3 ); 95 add (kuang1); 96 add (kuang2); 97 add (a); 98 add (B); 99 add (p ); 100 101 setTitle (""); 102 setSize (560,400); 103 setResizable (false ); // The page size cannot be changed by 104 setLayout (null); // The layout manager of the page cannot be empty. 105 setVisible (true); 106 setLocationRelativeTo (null ); // place the window in the center of the screen 107 108} 1 09 110 public static void main (String [] args) {111 112 new showLoginFrame (); 113 114} 115 116 public void actionreceivmed (ActionEvent e) {117 if (e. getSource () = a) 118 119 {120 if (kuang1.getText (). trim (). equals ("") {121 122 JOptionPane. showMessageDialog (null, "Enter the user name! "," Prompt for empty username ", JOptionPane. OK _OPTION); 123 124} 125 126 else {127 128 if (new String (kuang2.getPassword ()). equals ("") {129 130 JOptionPane. showMessageDialog (null, "enter the password! "," Blank password prompt ", JOptionPane. OK _OPTION); 131 132} 133 134 else {135 136 if (kuang1.getText (). trim (). equals ("123") & (new String (kuang2.getPassword ()). equals ("123") {137 138 this. dispose (); // exit the current interface from 139 140 JOptionPane. showMessageDialog (null, "congratulations, login successful! "); 141} 142 143 else 144 145 JOptionPane. showMessageDialog (null," the user name or password you entered is incorrect! "); 146 147 kuang2.setText (null); // The password setting box is empty. 148 149} 150} 151} 152 if (e. getSource () = B) 153 154 System. exit (0); // close the current interface 155 156} 157 158}


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.