Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.imageio.ImageIO;
- import javax.swing.*;
- import org.junit.Ignore;
- import java.awt.event.*;
- import java.io.IOException;
- public class Gui extends Guiback
- {
- String username;
- String password;
- JFrame gui = new JFrame("SoftwareHuset A/S");
- JPanel panel = new JPanel();
- JLabel logoLabel, oldPasswordLabel, newPasswordLabel;
- JTextField usernameText, startDatoText, slutDatoText, projectNameText;
- JPasswordField passwordText, newPasswordText;
- JButton loginButton, createUserButton, createProjectButton, editProjectButton, cancelButton, editUserButton;
- String[] projectsString = {"p1", "p2"};
- public Gui()
- {
- try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}
- catch (ClassNotFoundException e) {}
- catch (InstantiationException e) {}
- catch (IllegalAccessException e) {}
- catch (UnsupportedLookAndFeelException e) {}
- setUpGui();
- }
- public static void main(String[] args)
- {
- Gui gui = new Gui();
- }
- public void setUpGui() {
- panel.setLayout(null);
- editUserButton = new JButton();
- cancelButton = new JButton();
- slutDatoText = new JTextField();
- projectNameText = new JTextField();
- createUserButton = new JButton();
- startDatoText = new JTextField();
- createProjectButton = new JButton();
- editProjectButton = new JButton();
- usernameText = new JTextField();
- usernameText.setBounds(50, 220, 200, 30);
- passwordText = new JPasswordField();
- passwordText.setBounds(50, 250, 200, 30);
- passwordText.setEchoChar('*');
- newPasswordText = new JPasswordField();
- newPasswordText.setEchoChar('*');
- newPasswordLabel = new JLabel();
- oldPasswordLabel = new JLabel();
- usernameText.setText("Username");
- passwordText.setText("password");
- ImageIcon logo = new ImageIcon("image/logo.png");
- logoLabel = new JLabel("", logo, JLabel.CENTER);
- logoLabel.setBounds(50, 10, 200, 200);
- cancelButton.setBounds(50, 190, 200, 30);
- cancelButton.setText("Cancel");
- loginButton = new JButton();
- loginButton.setBounds(100, 280, 100, 30);
- loginButton.setText("Login");
- loginButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- username = usernameText.getText();
- password = new String(passwordText.getPassword());
- //System.out.println(username + " " + password);
- try
- {
- if((Guiback.testLogin(username, password)) == true) {
- changeToLoggedIn();
- hideLogIn();
- }
- }
- catch (IOException e1)
- {
- e1.printStackTrace();
- }
- }
- });
- panel.add(logoLabel);
- panel.add(loginButton);
- panel.add(usernameText);
- panel.add(passwordText);
- panel.add(newPasswordText);
- panel.add(cancelButton);
- panel.add(editUserButton);
- panel.add(createUserButton);
- panel.add(startDatoText);
- panel.add(slutDatoText);
- panel.add(createProjectButton);
- panel.add(projectNameText);
- panel.add(editProjectButton);
- panel.add(oldPasswordLabel);
- panel.add(newPasswordLabel);
- cancelButton.setVisible(false);
- //add components
- gui.add(panel);
- //set window settings
- gui.setSize(300, 350);
- gui.setLocationRelativeTo(null);
- gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- gui.setVisible(true);
- gui.setResizable(false);
- }
- public void changeToEditProject()
- {
- gui.setSize(300, 300);
- startDatoText.setBounds(50, 80, 200, 30);
- startDatoText.setText("Start Date day:month:year");
- slutDatoText.setBounds(50, 110, 200, 30);
- slutDatoText.setText("End date day:month:year");
- editProjectButton.setBounds(50, 150, 200,30);
- projectNameText.setBounds(50, 50, 200, 30);
- projectNameText.setText("Project name");
- cancelButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- hideEditProject();
- changeToLoggedIn();
- showLoggedIn();
- }
- });
- editProjectButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- }
- });
- }
- public void changeToEditUser(){
- gui.setSize(300, 300);
- hideLoggedIn();
- showEditUser();
- usernameText.setBounds(50, 50, 200, 30);
- usernameText.setText("Username");
- passwordText.setBounds(50, 80, 200, 30);
- newPasswordText.setBounds(50, 110, 200, 30);
- editUserButton.setBounds(50, 150, 200,30);
- newPasswordLabel.setBounds(10, 110, 200, 30);
- newPasswordLabel.setText("New");
- oldPasswordLabel.setBounds(10, 80, 200, 30);
- oldPasswordLabel.setText("Old");
- cancelButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- hideEditUser();
- changeToLoggedIn();
- showLoggedIn();
- }
- });
- editUserButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- username = usernameText.getText();
- password = new String(passwordText.getPassword());
- String newPassword = new String(newPasswordText.getPassword());
- try{
- Guiback.editUserPassword(username, newPassword, password);
- }
- catch (IOException e1) {
- }
- }
- });
- }
- public void changeToLoggedIn()
- {
- gui.setSize(600, 600);
- newPasswordText.setText("New password");
- usernameText.setText("New username");
- usernameText.setBounds(50, 430, 200, 30);
- passwordText.setText("New password");
- passwordText.setBounds(50, 460, 200, 30);
- projectNameText.setBounds(350, 400, 200, 30);
- projectNameText.setText("Project name");
- startDatoText.setBounds(350, 430, 200, 30);
- startDatoText.setText("Start Date day:month:year");
- slutDatoText.setBounds(350, 460, 200, 30);
- slutDatoText.setText("End date day:month:year");
- createUserButton.setBounds(50, 490, 200, 30);
- createUserButton.setText("Create user");
- createProjectButton.setBounds(350, 490, 200, 30);
- createProjectButton.setText("Create project");
- editProjectButton.setBounds(350, 530, 200, 30);
- editProjectButton.setText("Edit project");
- editUserButton.setBounds(50, 530, 200, 30);
- editUserButton.setText("Edit user");
- createUserButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- username = usernameText.getText();
- password = new String( passwordText.getPassword());
- try
- {
- if (Guiback.userAvailable(username) == true)
- {
- Guiback.createUser(username, password);
- JOptionPane.showMessageDialog(null, "infoMessage", "InfoBox: " + "titleBar", JOptionPane.INFORMATION_MESSAGE);
- }
- }
- catch (IOException e1)
- {
- e1.printStackTrace();
- }
- /*
- else
- {
- //Fejl om brugernavnet allerede er taget.
- }
- */
- }
- });
- createProjectButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- }
- });
- editProjectButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- changeToEditProject();
- hideLoggedIn();
- showEditProject();
- }
- });
- editUserButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- changeToEditUser();
- hideLoggedIn();
- showEditUser();
- }
- });
- }
- public void hideLoggedIn() {
- projectNameText.setVisible(false);
- passwordText.setVisible(false);
- usernameText.setVisible(false);
- createUserButton.setVisible(false);
- createProjectButton.setVisible(false);
- startDatoText.setVisible(false);
- slutDatoText.setVisible(false);
- editUserButton.setVisible(false);
- editProjectButton.setVisible(false);
- }
- public void hideLogIn(){
- logoLabel.setVisible(false);
- loginButton.setVisible(false);
- }
- public void hideEditProject(){
- cancelButton.setVisible(false);
- projectNameText.setVisible(false);
- }
- public void hideEditUser() {
- cancelButton.setVisible(false);
- newPasswordText.setVisible(false);
- newPasswordLabel.setVisible(false);
- oldPasswordLabel.setVisible(false);
- }
- public void showLoggedIn() {
- projectNameText.setVisible(true);
- passwordText.setVisible(true);
- usernameText.setVisible(true);
- createUserButton.setVisible(true);
- createProjectButton.setVisible(true);
- startDatoText.setVisible(true);
- slutDatoText.setVisible(true);
- editUserButton.setVisible(true);
- editProjectButton.setVisible(true);
- }
- public void showEditProject() {
- startDatoText.setVisible(true);
- slutDatoText.setVisible(true);
- cancelButton.setVisible(true);
- editProjectButton.setVisible(true);
- projectNameText.setVisible(true);
- }
- public void showEditUser() {
- passwordText.setVisible(true);
- cancelButton.setVisible(true);
- editUserButton.setVisible(true);
- newPasswordText.setVisible(true);
- usernameText.setVisible(true);
- newPasswordLabel.setVisible(true);
- oldPasswordLabel.setVisible(true);
- }
- }
Add Comment
Please, Sign In to add comment