package graphics;
//import connection.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
import java.sql.*;
public class Connn extends JFrame{
private JTextField tfuser = new JTextField();
private JPasswordField tfpass = new JPasswordField();
private JTextField tfport = new JTextField();
private JTextField tfhost = new JTextField();
private JTextArea meld = new JTextArea();
public Connn(){
super("MySQL - Connector");
JPanel pan = new JPanel();
pan.setLayout(new GridBagLayout());
pan.setBackground(Color.white);
JLabel lab = new JLabel();
//lab.setLayout(gb);
lab.setOpaque(true);
lab.setBackground(Color.blue);
lab.setForeground(Color.red);
lab.setFont(new Font("Helvetica", Font.BOLD, 24));
lab.setText("MySQL - Connector Version 0.1");
pan.add(lab, new GridBagConstraints(0,0,1,1,0.0,0.5,
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0,0,0,0), 1, 1));
//pan.add(lab);
JLabel lab5 = new JLabel();
//lab.setLayout(gb);
lab5.setOpaque(true);
lab5.setBackground(Color.blue);
lab5.setForeground(Color.black);
lab5.setFont(new Font("Helvetica", Font.PLAIN, 21));
lab5.setText("Schnittstelle zu MySQl - Datenbanken");
pan.add(lab5, new GridBagConstraints(0,1,1,0,0.0,0.5,
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0,0,0,0),1,1));
JPanel pan2 = new JPanel();
pan2.setLayout(new GridBagLayout());
//pan.setBackground(Color.green);
JLabel lab2 = new JLabel();
//lab2.setLayout(gb);
lab2.setOpaque(true);
lab2.setForeground(Color.black);
lab2.setFont(new Font("Helvetica", Font.PLAIN, 18));
lab2.setText("Username: ");
pan2.add(lab2, new GridBagConstraints(0,0,1,1,1.0,1.0,
GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0,0,0,0), 1, 1));
//pan2.add(lab2);
tfuser.setFont(new Font("Helvetica", Font.BOLD, 18));
//String user = tfuser.getText();
pan2.add(tfuser, new GridBagConstraints(1,0,1,1,1.0,1.0,
GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0,0,0,0),1,1));
JLabel lab3 = new JLabel();
//lab3.setLayout(gb);
lab3.setOpaque(true);
lab3.setForeground(Color.black);
lab3.setFont(new Font("Helvetica", Font.PLAIN, 18));
lab3.setText("Passwort: ");
pan2.add(lab3, new GridBagConstraints(0,1,1,1,1.0,1.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(0,0,0,0),1,1));
//pan2.add(lab3);
tfpass.setFont(new Font("Helvetica", Font.BOLD, 18));
//String password = tfpass.getText();
pan2.add(tfpass, new GridBagConstraints(1,1,1,1,1.0,1.0,
GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0,0,0,0),1,1));
JLabel lab4 = new JLabel();
lab4.setOpaque(true);
lab4.setText("DB - Host: ");
lab4.setFont(new Font("Helvetica", Font.PLAIN, 18));
pan2.add(lab4, new GridBagConstraints(0,2,1,1,1.0,1.0,
GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0,0,0,0), 1,1));
tfhost.setFont(new Font("Helvetica", Font.BOLD, 18));
//String host = tfhost.getText();
pan2.add(tfhost, new GridBagConstraints(1,2,1,1,1.0,1.0,
GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0,0,0,0),1,1));
JLabel lab6 = new JLabel();
lab6.setOpaque(true);
lab6.setText("DB - Port: ");
lab6.setFont(new Font("Helvetica", Font.PLAIN, 18));
pan2.add(lab6, new GridBagConstraints(0,3,1,1,1.0,1.0,
GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0,0,0,0),1,1));
tfport.setFont(new Font("Helvetica", Font.BOLD, 18));
pan2.add(tfport, new GridBagConstraints(1,3,1,1,1.0,1.0,
GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0,0,0,0),1,1));
JButton but = new JButton();
but.setText("Verbinden");
but.setBackground(Color.green);
but.addActionListener(AL);
pan2.add(but, new GridBagConstraints(0,4,1,1,1.0,1.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0),1,1));
JButton but1 = new JButton();
but1.setText("Verbindung beenden");
but1.setBackground(Color.red);
//ActionListener but = new AL();
pan2.add(but1, new GridBagConstraints(1,4,1,1,1.0,1.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0),1,1));
JPanel pan3 = new JPanel();
pan3.setLayout(new GridBagLayout());
//JTextField meld = new JTextField();
meld.setFont(new Font("Helvetica", Font.BOLD, 18));
pan3.add(new JScrollPane(meld));
pan3.add(meld, new GridBagConstraints(0,0,1,1,1.0,1.0,
GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0,0,0,0),1,1));
this.getContentPane().setLayout(new GridBagLayout());
this.getContentPane().add(pan, new GridBagConstraints(0,0,1,1,1.0,1.0,
GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(0,0,0,0),1,1));
this.getContentPane().add(pan2, new GridBagConstraints(0,1,1,1,1.0,1.0,
GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(0,0,0,0),1,1));
this.getContentPane().add(pan3, new GridBagConstraints(0,2,1,1,1.0,1.0,
GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(0,0,0,0),1,1));
}
ActionListener AL = new ActionListener(){
public void actionPerformed(ActionEvent e){
Connection conn = null;
meld.append("\n"+"Versuch");
try{
meld.append("\n"+"Test");
Class.forName("org.gjt.mm.mysql.Driver");
meld.append("Treiber wird geladen");
}
catch(ClassNotFoundException cnfs){
meld.append("\n" + "Class not Found");
}
try{
conn = DriverManager.getConnection("jdbc:mysql://"+ tfhost.getText() + ":"+ tfport.getText() +"/shanor", tfuser.getText(), tfpass.getText());
meld.append("\n" + "Verbindungsaufbau");}
catch(SQLException sqle){
meld.append("\n" + "Verbindung fehlgeschlagen: " + sqle.getMessage());}
};
};
};