Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //01DDT20F1122
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class LabTask3 extends JFrame {
- private JPasswordField _password;
- private JComboBox _user;
- private JCheckBox _showPassword;
- private JButton _buttonLogin;
- private JButton _buttonCancel;
- private JPanel _mainPanel;
- private String[] _userNameList = { "Zainal Abidin", "Moktar Dahari", "Fernando Forestieri", "John Jhonny Jonarthan", "Pele" };
- private String[] _userPasswordList = { "12345", "5555", "12435134", "423412", "1234156" };
- public LabTask3() {
- _mainPanel = new JPanel();
- _mainPanel.setLayout(new BoxLayout(_mainPanel, BoxLayout.Y_AXIS));
- this.createNewImageLabel("C:\\Users\\User\\Downloads\\profile1.png");
- _user = this.createNewComboBox("Username:",_userNameList);
- _password = this.createNewTextFieldForm("Password:", 10);
- _showPassword = this.createNewJCheckBox("Show Password", " ");
- String[] buttonName = {"Login", "Cancel"};
- JButton[] _buttonCollection = this.createNewJButton(buttonName);
- _buttonCollection[0].addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- if(_userPasswordList[_user.getSelectedIndex()].equals(_password.getText()))
- {
- JOptionPane.showMessageDialog(new JFrame(), "SUCCESFULL LOGIN", "SUCCESSS!!", 1);
- }
- else
- {
- JOptionPane.showMessageDialog(new JFrame(), "WRONG PASSWORD", "ERROR!!", 2);
- }
- }
- });
- _buttonCollection[1].addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- System.exit(0);
- }
- });
- _showPassword.addItemListener(new ItemListener() {
- @Override
- public void itemStateChanged(ItemEvent e) {
- if (e.getStateChange() == ItemEvent.SELECTED) {
- System.out.println("SELECTED");
- _password.setEchoChar((char) 0);
- } else {
- System.out.println("DESELECTED");
- _password.setEchoChar('*');
- }
- }
- });
- this.iniTialization();
- }
- private void iniTialization()
- {
- this.add(_mainPanel);
- this.setTitle("LabTask3");
- this.setDefaultCloseOperation(3);
- this.setVisible(true);
- this.setLayout(new FlowLayout());
- this.setSize(500,500);
- }
- private void createNewImageLabel(String path)
- {
- JPanel tempPanel = new JPanel(new FlowLayout() );
- JLabel image = new JLabel(new ImageIcon(path));
- tempPanel.add(image);
- _mainPanel.add(tempPanel);
- }
- private JPasswordField createNewTextFieldForm(String label, int textFieldsSize)
- {
- JPanel tempPanel = new JPanel(new FlowLayout(FlowLayout.LEFT) );
- JPasswordField tempTextField = new JPasswordField(textFieldsSize);
- tempPanel.add(new JLabel(label));
- tempPanel.add(tempTextField);
- _mainPanel.add(tempPanel);
- return tempTextField;
- }
- private JComboBox createNewComboBox(String label, String[] userList)
- {
- JPanel tempPanel = new JPanel(new FlowLayout(FlowLayout.LEFT) );
- JComboBox tempComboBox = new JComboBox(userList);
- tempPanel.add(new JLabel(label));
- tempPanel.add(tempComboBox);
- _mainPanel.add(tempPanel);
- return tempComboBox;
- }
- private JCheckBox createNewJCheckBox(String label, String spacer)
- {
- JPanel tempPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
- JCheckBox tempComboBox = new JCheckBox(label);
- tempPanel.add(new JLabel(spacer));
- tempPanel.add(tempComboBox);
- _mainPanel.add(tempPanel);
- return tempComboBox;
- }
- private JButton[] createNewJButton(String[] button)
- {
- JPanel tempPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
- JButton button1 = new JButton(button[0]);
- JButton button2 = new JButton(button[1]);
- button1.setPreferredSize(new Dimension(100, 40));
- button2.setPreferredSize(new Dimension(100, 40));
- tempPanel.add(button1);
- tempPanel.add(button2);
- _mainPanel.add(tempPanel);
- return new JButton[] {button1, button2};
- }
- public static void main(String args[])
- {
- new LabTask3();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement