public class Conn extends JFrame{
public Conn(){
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);
JTextField tfuser = new JTextField();
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);
JPasswordField tfpasswd = new JPasswordField();
tfpasswd.setFont(new Font("Helvetica", Font.BOLD, 18));
String password = tfpasswd.getText();
pan2.add(tfpasswd, 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));
JTextField tfdbHost = new JTextField();
tfdbHost.setFont(new Font("Helvetica", Font.BOLD, 18));
String host = tfdbHost.getText();
pan2.add(tfdbHost, 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));
JTextField dbPort = new JTextField();
dbPort.setFont(new Font("Helvetica", Font.BOLD, 18));
String port = dbPort.getText();
pan2.add(dbPort, 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(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;
try{
Class.forName("org.gjt.mm.mysql.Driver");
}
catch(ClassNotFoundException cnfs)
{
System.out.println("Treiber konnte nicht geladen werden");
}
try{
conn = DriverManager.getConnection("jdbc:mysql://"+ host + ":" + port + "/" + user, password);}
catch(SQLException sqle){
System.out.println("Verbindung fehlgeschlagen: " + sqle.getMessage());}
public void setUser (String user)
{
this.user = user;
}
};
};
}