demo5() { f = new Frame(); f.setSize(300, 300); // f.setBackground(Color.red); f.setLayout(null); s1 = new Scrollbar(Scrollbar.VERTICAL, 0, 5, 0, 260); s1.setBackground(Color.red); s1.setBounds(30, 35, 20, 255); s2 = new Scrollbar(Scrollbar.VERTICAL, 0, 5, 0, 260); s2.setBackground(Color.green); s2.setBounds(60, 35, 20, 255); s3 = new Scrollbar(Scrollbar.VERTICAL, 0, 5, 0, 260); s3.setBackground(Color.blue); s3.setBounds(90, 35, 20, 255); f.add(s1); f.add(s2); f.add(s3); s1.addAdjustmentListener(this); s2.addAdjustmentListener(this); s3.addAdjustmentListener(this); p1 = new Panel(); p1.setBounds(120, 35, 170, 255); f.add(p1); f.setVisible(true); }
/** Create the frame. */ public AdminUserControl() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 572, 387); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); list = new JList(listModel); list.addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent arg0) { int i = list.getSelectedIndex(); firstnameField.setText(users.get(i).first_name); lastnameField.setText(users.get(i).last_name); emailField.setText(users.get(i).email); phoneField.setText(users.get(i).phonenumber); if (users.get(i).admin_status == 1) { adminCheckBox.setSelected(true); } else { adminCheckBox.setSelected(false); } } }); list.setBounds(25, 30, 184, 272); contentPane.add(list); users = DB.getAllUsers(); for (int i = 0; i < users.size(); i++) { listModel.addElement(users.get(i).getName() + " (" + users.get(i).email + ")"); } firstnameField = new JTextField(); firstnameField.setBounds(390, 30, 99, 20); contentPane.add(firstnameField); firstnameField.setColumns(10); lastnameField = new JTextField(); lastnameField.setBounds(390, 61, 99, 20); contentPane.add(lastnameField); lastnameField.setColumns(10); emailField = new JTextField(); emailField.setBounds(390, 92, 99, 20); contentPane.add(emailField); emailField.setColumns(10); JLabel lblNewLabel = new JLabel("F\u00F6rnamn:"); lblNewLabel.setBounds(310, 33, 83, 14); contentPane.add(lblNewLabel); JLabel lblNewLabel_1 = new JLabel("Efternamn:"); lblNewLabel_1.setBounds(310, 64, 83, 14); contentPane.add(lblNewLabel_1); JLabel lblNewLabel_2 = new JLabel("E-mail:"); lblNewLabel_2.setBounds(310, 95, 61, 14); contentPane.add(lblNewLabel_2); JLabel lblAdminStatus = new JLabel("Adminstatus:"); lblAdminStatus.setBounds(310, 162, 83, 14); contentPane.add(lblAdminStatus); JLabel lblAccounts = new JLabel("V\u00E4lj Konto"); lblAccounts.setBounds(89, 11, 61, 14); contentPane.add(lblAccounts); JButton btnUppdatera = new JButton("Uppdatera"); btnUppdatera.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { EmailValidator emailValidator = new EmailValidator(); PhoneValidator phoneValidator = new PhoneValidator(); int i = list.getSelectedIndex(); if (i >= 0) { User user = users.get(i); int adminStatus = 0; if (adminCheckBox.isSelected()) { adminStatus = 1; } else if (adminCheckBox.isSelected() == false) { adminStatus = 0; } if (!emailValidator.validate(emailField.getText().trim())) { JOptionPane.showMessageDialog(null, "Du måste ange en giltlig Email"); emailField.setBackground(Color.red); /* Action that you want to take. For ex. make email id field red or give message box saying invalid email id. */ } else if (!phoneValidator.validate(phoneField.getText().trim())) { JOptionPane.showMessageDialog(null, "Du måste ange ett Telefonnummer"); phoneField.setBackground(Color.red); } else { String ret = DB.UpdateUser( user.id, emailField.getText(), firstnameField.getText(), lastnameField.getText(), phoneField.getText(), adminStatus); JOptionPane.showMessageDialog(null, ret); AdminUserControl reload = new AdminUserControl(); AdminUserControl.this.dispose(); reload.setVisible(true); } } else { JOptionPane.showMessageDialog(null, "Du måste välja en användare!"); } } }); btnUppdatera.setBounds(390, 215, 99, 23); contentPane.add(btnUppdatera); adminCheckBox = new JCheckBox(""); adminCheckBox.setBounds(390, 158, 97, 23); contentPane.add(adminCheckBox); JButton btnTaBort = new JButton("Ta bort"); btnTaBort.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { int i = list.getSelectedIndex(); if (i >= 0) { User user = users.get(i); String ret = DB.RemoveUser(user.id); JOptionPane.showMessageDialog(null, ret); AdminUserControl reload = new AdminUserControl(); AdminUserControl.this.dispose(); reload.setVisible(true); } else { JOptionPane.showMessageDialog(null, "Du måste välja en användare!"); } } }); btnTaBort.setBounds(390, 245, 99, 23); contentPane.add(btnTaBort); JButton btnNyttKonto = new JButton("Nytt konto"); btnNyttKonto.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { AddUserAdmin Adduser = new AddUserAdmin(); Adduser.setVisible(true); setVisible(false); } }); btnNyttKonto.setBounds(390, 279, 99, 23); contentPane.add(btnNyttKonto); phoneField = new JTextField(); phoneField.setBounds(390, 123, 99, 20); contentPane.add(phoneField); phoneField.setColumns(10); JLabel lblTelefonnr = new JLabel("Telefonnr:"); lblTelefonnr.setBounds(310, 126, 65, 14); contentPane.add(lblTelefonnr); Scrollbar scrollbar = new Scrollbar(); scrollbar.setBounds(192, 30, 17, 272); contentPane.add(scrollbar); JButton btnTillbaka = new JButton("Tillbaka"); btnTillbaka.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { AdminMenu menu = new AdminMenu(); menu.setVisible(true); setVisible(false); } }); btnTillbaka.setBounds(265, 315, 89, 23); contentPane.add(btnTillbaka); }