Hallo
Ich bin neu was Java Swing angeht (und eigentlich auch was Java angeht...) und bräuchte daher mal ein wenig hilfe.
ganz unten seht ihr diesen teil um dens mir hier geht:
in meiner datei kunde_an_erf.java steht nun folgendes:
wie ihr an dem btn_menu_click seht hab ich das programm vorher so umgesetzt, dass der frame einfach unsichtbar geschaltet wird und ein neuer geladen. Find ich persönlich (und ihr dann sowieso auch ) eher unschön.
Jetzt will ich halt das nach meinem repaint in der datei oben, die daten aus der anderen geholt werden und der frame damit neu aufgebaut wird. aber irgendwie klappt das nicht.
Kann mir da jemand bei helfen?
grüße
Alex
Ich bin neu was Java Swing angeht (und eigentlich auch was Java angeht...) und bräuchte daher mal ein wenig hilfe.
Java:
import javax.swing.JFrame;
import javax.swing.JTextField;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
public class kunde_anlegen extends menu {
private static final long serialVersionUID = 1L;
JLabel lbl_kundennummer, lbl_name, lbl_vorname, lbl_strasse, lbl_plz, lbl_ort, lbl_telefon1, lbl_telefon2, lbl_email, lbl_webname, lbl_webpass;
JTextField txt_kundennummer, txt_name, txt_vorname, txt_strasse, txt_plz, txt_ort, txt_telefon1, txt_telefon2, txt_email, txt_webname, txt_webpass;
JButton btn_anlegen, btn_menu;
public kunde_anlegen() {
this.getContentPane().setLayout(null);
this.initialize();
this.addWindowListener(new WindowListener() {
public void windowClosed(WindowEvent arg0) {
}
public void windowActivated(WindowEvent e) {
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public void windowDeactivated(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowOpened(WindowEvent e) {
}
});
}
protected void initialize() {
// Instanzieren:
lbl_kundennummer = new JLabel("Kundennummer:");
lbl_name = new JLabel("Name");
lbl_vorname = new JLabel("Vorname:");
lbl_strasse = new JLabel("Strasse");
lbl_plz = new JLabel("Plz:");
lbl_ort = new JLabel("Ort");
lbl_telefon1 = new JLabel("Telefon 1:");
lbl_telefon2 = new JLabel("Telefon 2");
lbl_email = new JLabel("eMail:");
lbl_webname = new JLabel("Nutzername");
lbl_webpass = new JLabel("Passwort:");
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost/boutique_kasse", "root", "blablub");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select Kundennummer from kunden ORDER BY Kundennummer DESC LIMIT 1");
while (rs.next()) {
int buffer = Integer.parseInt(rs.getString(1)) + 1;
txt_kundennummer = new JTextField(String.valueOf(buffer));
}
rs.close();
stmt.close();
con.close();
}catch(Exception ex) {
System.err.println("SQLException: " + ex.getMessage());
}
txt_name = new JTextField();
txt_vorname = new JTextField();
txt_strasse = new JTextField();
txt_plz = new JTextField();
txt_ort = new JTextField();
txt_telefon1 = new JTextField();
txt_telefon2 = new JTextField();
txt_email = new JTextField();
txt_webname = new JTextField();
txt_webpass = new JTextField();
btn_anlegen = new JButton("Anlegen");
btn_menu = new JButton("Hauptmenü");
btn_anlegen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
btn_anlegen_click();
}
});
btn_menu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ex) {
btn_menu_click();
}
});
// Positionen festlegen
lbl_kundennummer.setBounds(200,5,100,30);
lbl_name.setBounds(200,45,100,30);
lbl_vorname.setBounds(200,85,100,30);
lbl_strasse.setBounds(200,125,100,30);
lbl_plz.setBounds(200,165,100,30);
lbl_ort.setBounds(200,205,100,30);
lbl_telefon1.setBounds(200,245,100,30);
lbl_telefon2.setBounds(200,285,100,30);
lbl_email.setBounds(200,325,100,30);
lbl_webname.setBounds(200,365,100,30);
lbl_webpass.setBounds(200,405,100,30);
txt_kundennummer.setBounds(500,5,100,30);
txt_name.setBounds(500,45,100,30);
txt_vorname.setBounds(500,85,100,30);
txt_strasse.setBounds(500,125,100,30);
txt_plz.setBounds(500,165,100,30);
txt_ort.setBounds(500,205,100,30);
txt_telefon1.setBounds(500,245,100,30);
txt_telefon2.setBounds(500,285,100,30);
txt_email.setBounds(500,325,100,30);
txt_webname.setBounds(500,365,100,30);
txt_webpass.setBounds(500,405,100,30);
btn_anlegen.setBounds(350,445,100,30);
btn_menu.setBounds(350,525,100,30);
// Elemente dem Fenster hinzufügen:
// (this ist ein Zeiger auf dieses Objekt, also das Fenster)
this.getContentPane().add(lbl_kundennummer);
this.getContentPane().add(lbl_name);
this.getContentPane().add(lbl_vorname);
this.getContentPane().add(lbl_strasse);
this.getContentPane().add(lbl_plz);
this.getContentPane().add(lbl_ort);
this.getContentPane().add(lbl_telefon1);
this.getContentPane().add(lbl_telefon2);
this.getContentPane().add(lbl_email);
this.getContentPane().add(lbl_webname);
this.getContentPane().add(lbl_webpass);
this.getContentPane().add(txt_kundennummer);
this.getContentPane().add(txt_name);
this.getContentPane().add(txt_vorname);
this.getContentPane().add(txt_strasse);
this.getContentPane().add(txt_plz);
this.getContentPane().add(txt_ort);
this.getContentPane().add(txt_telefon1);
this.getContentPane().add(txt_telefon2);
this.getContentPane().add(txt_email);
this.getContentPane().add(txt_webname);
this.getContentPane().add(txt_webpass);
this.getContentPane().add(btn_anlegen);
this.getContentPane().add(btn_menu);
this.pack();
}
public void btn_menu_click(){
menu menuWindow = new menu();
menuWindow.setBounds(10,10,800,600);
this.setVisible(false);
menuWindow.setVisible(true);
}
public void btn_anlegen_click(){
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost/boutique_kasse", "root", "");
Statement stmt = con.createStatement();
stmt.executeUpdate("Insert into kunden values('"+txt_kundennummer.getText()+"','"+txt_name.getText()+"','"+txt_vorname.getText()+"','"+txt_strasse.getText()+"','"+txt_plz.getText()+"','"+
txt_ort.getText()+"','"+txt_telefon1.getText()+"','"+txt_telefon2.getText()+"','"+txt_email.getText()+"','"+txt_webname.getText()+"','"+txt_webpass.getText()+"')");
stmt.close();
con.close();
JOptionPane.showMessageDialog(this, "Kunde wurde angelegt!", "Gratulation", JOptionPane.INFORMATION_MESSAGE);
this.getContentPane().removeAll();
this.getContentPane().repaint();
new kunde_an_erf(Integer.parseInt(txt_kundennummer.getText()));
this.getContentPane().repaint();
}catch(Exception ex) {
System.err.println("SQLException: " + ex.getMessage());
}
}
}
ganz unten seht ihr diesen teil um dens mir hier geht:
Java:
this.getContentPane().removeAll();
this.getContentPane().repaint();
new kunde_an_erf(Integer.parseInt(txt_kundennummer.getText()));
this.getContentPane().repaint();
in meiner datei kunde_an_erf.java steht nun folgendes:
Java:
import javax.swing.JFrame;
import javax.swing.JTextField;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
public class kunde_an_erf extends kunde_anlegen {
private static final long serialVersionUID = 1L;
JLabel lbl_kundennummer;
JLabel lbl_name;
JLabel lbl_vorname;
JLabel lbl_strasse;
JLabel lbl_plz;
JLabel lbl_ort;
JLabel lbl_telefon1;
JLabel lbl_telefon2;
JLabel lbl_email;
JLabel lbl_webname;
JLabel lbl_webpass;
JLabel lbl_kundennummer_erg;
JLabel lbl_name_erg;
JLabel lbl_vorname_erg;
JLabel lbl_strasse_erg;
JLabel lbl_plz_erg;
JLabel lbl_ort_erg;
JLabel lbl_telefon1_erg;
JLabel lbl_telefon2_erg;
JLabel lbl_email_erg;
JLabel lbl_webname_erg;
JLabel lbl_webpass_erg;
JButton btn_editieren;
JButton btn_menu;
JButton btn_drucken;
int kundennummer;
public kunde_an_erf(int kd) {
kundennummer = kd;
this.initialize();
this.addWindowListener(new WindowListener() {
public void windowClosed(WindowEvent arg0) {
}
public void windowActivated(WindowEvent e) {
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public void windowDeactivated(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowOpened(WindowEvent e) {
}
});
}
public void initialize() {
this.lbl_kundennummer = new JLabel("Kundennummer:");
this.lbl_name = new JLabel("Name");
this.lbl_vorname = new JLabel("Vorname:");
this.lbl_strasse = new JLabel("Strasse");
this.lbl_plz = new JLabel("Plz:");
this.lbl_ort = new JLabel("Ort");
this.lbl_telefon1 = new JLabel("Telefon 1:");
this.lbl_telefon2 = new JLabel("Telefon 2");
this.lbl_email = new JLabel("eMail:");
this.lbl_webname = new JLabel("Nutzername");
this.lbl_webpass = new JLabel("Passwort:");
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost/boutique_kasse", "root", "blablub");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select * from kunden Where Kundennummer = '"+String.valueOf(kundennummer)+"'");
while (rs.next()) {
this.lbl_kundennummer_erg = new JLabel(String.valueOf(kundennummer));
this.lbl_name_erg = new JLabel(rs.getString(2));
this.lbl_vorname_erg = new JLabel(rs.getString(3));
this.lbl_strasse_erg = new JLabel(rs.getString(4));
this.lbl_plz_erg = new JLabel(String.valueOf(rs.getInt(5)));
this.lbl_ort_erg = new JLabel(rs.getString(6));
this.lbl_telefon1_erg = new JLabel(rs.getString(7));
this.lbl_telefon2_erg = new JLabel(rs.getString(8));
this.lbl_email_erg = new JLabel(rs.getString(9));
this.lbl_webname_erg = new JLabel(rs.getString(10));
this.lbl_webpass_erg = new JLabel(rs.getString(11));
}
rs.close();
stmt.close();
con.close();
}catch(Exception ex) {
System.err.println("SQLException: " + ex.getMessage());
ex.printStackTrace();
}
this.btn_editieren = new JButton("Editieren");
this.btn_drucken = new JButton("Drucken");
this.btn_menu = new JButton("Hauptmenü");
this.lbl_kundennummer.setBounds(200,5,100,30);
this.lbl_name.setBounds(200,45,100,30);
this.lbl_vorname.setBounds(200,85,100,30);
this.lbl_strasse.setBounds(200,125,100,30);
this.lbl_plz.setBounds(200,165,100,30);
this.lbl_ort.setBounds(200,205,100,30);
this.lbl_telefon1.setBounds(200,245,100,30);
this.lbl_telefon2.setBounds(200,285,100,30);
this.lbl_email.setBounds(200,325,100,30);
this.lbl_webname.setBounds(200,365,100,30);
this.lbl_webpass.setBounds(200,405,100,30);
this.lbl_kundennummer_erg.setBounds(500,5,100,30);
this.lbl_name_erg.setBounds(500,45,100,30);
this.lbl_vorname_erg.setBounds(500,85,100,30);
this.lbl_strasse_erg.setBounds(500,125,100,30);
this.lbl_plz_erg.setBounds(500,165,100,30);
this.lbl_ort_erg.setBounds(500,205,100,30);
this.lbl_telefon1_erg.setBounds(500,245,100,30);
this.lbl_telefon2_erg.setBounds(500,285,100,30);
this.lbl_email_erg.setBounds(500,325,100,30);
this.lbl_webname_erg.setBounds(500,365,100,30);
this.lbl_webpass_erg.setBounds(500,405,100,30);
this.btn_editieren.setBounds(350, 500,100,30);
this.btn_drucken.setBounds(200,500,100,30);
this.btn_menu.setBounds(500,500,100,30);
super.getContentPane().add(this.lbl_kundennummer);
super.getContentPane().add(this.lbl_name);
super.getContentPane().add(this.lbl_vorname);
super.getContentPane().add(this.lbl_strasse);
super.getContentPane().add(this.lbl_plz);
super.getContentPane().add(this.lbl_ort);
super.getContentPane().add(this.lbl_telefon1);
super.getContentPane().add(this.lbl_telefon2);
super.getContentPane().add(this.lbl_email);
super.getContentPane().add(this.lbl_webname);
super.getContentPane().add(this.lbl_webpass);
super.getContentPane().add(this.lbl_kundennummer_erg);
super.getContentPane().add(this.lbl_name_erg);
super.getContentPane().add(this.lbl_vorname_erg);
super.getContentPane().add(this.lbl_strasse_erg);
super.getContentPane().add(this.lbl_plz_erg);
super.getContentPane().add(this.lbl_ort_erg);
super.getContentPane().add(this.lbl_telefon1_erg);
super.getContentPane().add(this.lbl_telefon2_erg);
super.getContentPane().add(this.lbl_email_erg);
super.getContentPane().add(this.lbl_webname_erg);
super.getContentPane().add(this.lbl_webpass_erg);
super.getContentPane().add(this.btn_editieren);
super.getContentPane().add(this.btn_drucken);
super.getContentPane().add(this.btn_menu);
this.btn_editieren.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
btn_editieren_click();
}
});
this.btn_drucken.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
btn_drucken_click();
}
});
this.btn_menu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
btn_menu_click();
}
});
}
public void btn_editieren_click() {
System.out.println("Editieren");
}
public void btn_drucken_click() {
System.out.println("Editieren");
}
public void btn_menu_click() {
menu menuWindow = new menu();
menuWindow.setBounds(10,10,800,600);
this.setVisible(false);
menuWindow.setVisible(true);
}
}
wie ihr an dem btn_menu_click seht hab ich das programm vorher so umgesetzt, dass der frame einfach unsichtbar geschaltet wird und ein neuer geladen. Find ich persönlich (und ihr dann sowieso auch ) eher unschön.
Jetzt will ich halt das nach meinem repaint in der datei oben, die daten aus der anderen geholt werden und der frame damit neu aufgebaut wird. aber irgendwie klappt das nicht.
Kann mir da jemand bei helfen?
grüße
Alex