Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*; // til filbehandling
- import java.util.*; // til scanner
- import java.awt.*;
- import javax.swing.*;
- import java.awt.event.*;
- // FRAME
- public class loginLayout extends JFrame implements ActionListener {
- public void actionPerformed(ActionEvent e) {
- }
- static JButton loginButton;
- static JTextField usernameField;
- static JTextField passwordField;
- public static void main(String[] args) throws FileNotFoundException {
- loginLayout gui = new loginLayout();
- }
- public loginLayout() throws FileNotFoundException {
- Scanner console = new Scanner(System.in); // Scanner
- final loginCheck getData = new loginCheck(); // Objekt getData metoder fra loginCheck.java
- // Gui vinduet hentes
- JFrame frame = new JFrame();
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setTitle("Dolphin system login");
- frame.setLayout(new BorderLayout());
- // Felterne til login
- JPanel textPanel = new JPanel(new GridLayout(2,2));
- final JTextField typedCPR = new JTextField("", 10);
- typedCPR.setPreferredSize(new Dimension(120, 20));
- final JTextField typedPassword = new JTextField("", 10);
- typedPassword.setPreferredSize(new Dimension(120, 20));
- textPanel.add(new JLabel("Username: "));
- textPanel.add(typedCPR);
- textPanel.add(new JLabel("Password: "));
- textPanel.add(typedPassword);
- frame.add(textPanel, BorderLayout.NORTH);
- // Knap til login
- JPanel buttonPanel = new JPanel(new GridLayout(1,2));
- JButton loginButton = new JButton();
- loginButton.setText("Log in");
- loginButton.setPreferredSize(new Dimension(10, 20));
- // Prøver at logge ind og viser indhold hvis
- // indtastede data er korrekt (Bruger en ActionListener)
- loginButton.addActionListener(this);
- String cprTry = typedCPR.getText();
- String passwordTry = typedPassword.getText();
- String cpr = getData.getLogin(cprTry, passwordTry);
- if (cpr.equals("dontexist")) {
- System.out.println("Brugernavnet eksisterer ikke i databasen");
- }
- else if (cpr.equals("wrongpass")) {
- System.out.println("Brugernavn og password passer ikke sammen!");
- }
- else {
- }
- buttonPanel.add(new JLabel(""));
- buttonPanel.add(loginButton);
- frame.add(buttonPanel, BorderLayout.SOUTH);
- frame.pack();
- frame.setLocationRelativeTo(null);
- frame.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment