Hallo alle zusammen.
Ich möchte gerne eine Anwendung schreiben, die mehrere "Formulare" enthält. Dazu habe ich ein JFrame geschrieben, welches in einem JLabel andere Formulare darstellen soll.
Das Problem ist allerdings, dass ich die Label nicht mehr austauschen kann.
Hier ein kleines Beispiel:
das zweite sieht dann analog zu Log1 aus...
Kann man das überhaupt realisieren??
Habe auch schon versucht einen Observer mit rein zu basteln.. momentan leider noch ohne Erfolg
Gruß Marco
L-ectron-X hat diesen Beitrag am 02.06.2006 um 20:14 Uhr editiert.
Code-Tags eingefügt.
Ich möchte gerne eine Anwendung schreiben, die mehrere "Formulare" enthält. Dazu habe ich ein JFrame geschrieben, welches in einem JLabel andere Formulare darstellen soll.
Das Problem ist allerdings, dass ich die Label nicht mehr austauschen kann.
Hier ein kleines Beispiel:
Code:
public class OverallFrame extends JFrame{
private Log1 login;
private Log2 logout;
public OverallFrame() {
super();
initGUI();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
pack();
this.setSize(650, 450);
} catch (Exception e) {
e.printStackTrace();
}
wechsel(1);
}
public void wechsel(int wech){
switch(wech){
case 1:
login = new Log1(this);
this.getContentPane().removeAll();
getContentPane().add(login, BorderLayout.CENTER);
break;
case 2:
logout = new Log2(this);
this.getContentPane().removeAll();
getContentPane().add(logout, BorderLayout.CENTER);
break;
}
}
public static void main(String argsv[]){
OverallFrame overallframe = new OverallFrame();
overallframe.setVisible(true);
}
}
Nun kommt eines der Formulare
public class Log1 extends javax.swing.JPanel implements ActionListener{
private JButton Login;
private OverallFrame overallframe;
public Log1(OverallFrame overallframe) {
super();
this.overallframe = overallframe;
initGUI();
}
private void initGUI() {
try {
BorderLayout thisLayout = new BorderLayout();
this.setLayout(thisLayout);
this.setPreferredSize(new java.awt.Dimension(650, 400));
{
Login = new JButton();
this.add(Login, BorderLayout.CENTER);
Login.setText("Login");
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void actionPerformed(ActionEvent ae) {
if(ae.getActionCommand().toString().equals("Login"))
overallframe.wechsel(2);
}
}
das zweite sieht dann analog zu Log1 aus...
Kann man das überhaupt realisieren??
Habe auch schon versucht einen Observer mit rein zu basteln.. momentan leider noch ohne Erfolg
Gruß Marco
L-ectron-X hat diesen Beitrag am 02.06.2006 um 20:14 Uhr editiert.
Code-Tags eingefügt.