// Imports
import javax.swing.*;

// Interface Class
public class Interface extends JFrame {

    // Components
    private JPanel panel;
    private JTextArea queryInputField;
    private JTextArea queryOutputField;
    private JButton queryButton;

    // Interface Method
    public Interface(Database database) {
        // Create Windows
        setTitle("MySQL Query Tool");
        setResizable(false);
        setSize(600, 300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setContentPane(panel);
        setVisible(true);
        // Query Button Clicked
        queryButton.addActionListener( e -> {
            // Update Button
            queryButton.setText("Querying");
            // Get Query
            String query = queryInputField.getText();
            try {
                queryOutputField.setText(database.query(query));
            } catch (Exception ex) {
                queryOutputField.setText("Error");
            }
            // Update Button
            queryButton.setText("Query");
        });
    }

}