// Imports
import javax.swing.*;

// Login Class
public class Login extends JFrame {

    // Components
    private JPanel panel;
    private JLabel image;
    private JTextField urlField;
    private JTextField usernameField;
    private JPasswordField passwordField;
    private JButton submitButton;

    // Login Method
    public Login(Database database) {
        // Create Window
        setTitle("MySQL Query Tool");
        setResizable(false);
        setSize(600, 300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setContentPane(panel);
        setVisible(true);
        // Submit Button Clicked
        submitButton.addActionListener( e -> {
            // Update Button
            submitButton.setText("Connecting");
            // Get Field Data
            String url = urlField.getText();
            String username = usernameField.getText();
            String password = passwordField.getText();
            // Create Connection
            try {
                database.setup("jdbc:mysql://" + url, username, password);
                setVisible(false);
                dispose();
            } catch (Exception exception) {
                submitButton.setText("Login");
            }
        });
    }

}