M
maretz
Gast
Moin,
ich habe hier mal eine eher konzeptionelle Frage. Ich habe mir eine kleine Anwendung gebaut.
Das Hauptfenster enthält erstmal eine SplitPane. Links soll ein Menü sein, Rechts soll der Arbeitsbereich kommen. Jetzt möchte ich zuerst die Funktion "Login" bauen. Soweit kein Thema. Ich habe im dazu ein Panel erzeugt:
Dieses kann auch von meiner Hauptfunktion wie gewünscht in das rechte Pane eingefügt werden - klappt. Wo ich jetzt aber hänge: Wenn man auf Login klickt und die Benutzerdaten richtig sind dann müsste ja auch im Hauptfenster das linke Pane mit dem Menü aktuallisiert werden. Hier fehlt mir einfach grade die Idee wie ich das vernünftig hinbekomme das ich eine aktuallisierung des Panes anstoße...
Hier nochmal kurz das Hauptfenster:
Kann mir da mal jemand kurz nen Denkanstoß geben? (Achso - das der Login-ActionListener noch leer ist weiß ich - da ich hier grade noch mit einen Dummy arbeite wäre hier so oder so noch keine wirkliche Abfrage drin.... Die Datenbank-Verbindung usw. ist später auch kein Problem - mir fehlt hier einfach grade die Idee.... D.h. man darf in diesem Action-Listener derzeit ruhig davon ausgehen das die Benutzerdaten wirklich gültig waren )
ich habe hier mal eine eher konzeptionelle Frage. Ich habe mir eine kleine Anwendung gebaut.
Das Hauptfenster enthält erstmal eine SplitPane. Links soll ein Menü sein, Rechts soll der Arbeitsbereich kommen. Jetzt möchte ich zuerst die Funktion "Login" bauen. Soweit kein Thema. Ich habe im dazu ein Panel erzeugt:
Java:
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class LoginPanel extends javax.swing.JPanel {
private static final long serialVersionUID = -2116173186197498854L;
private JLabel UsernameLabel;
private JLabel PasswordLabel;
private JButton LoginButton;
private JPasswordField PasswordInput;
private JTextField UsernameInput;
public LoginPanel() {
try {
GridBagLayout thisLayout = new GridBagLayout();
setPreferredSize(new Dimension(400, 300));
thisLayout.rowWeights = new double[] {0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1};
thisLayout.rowHeights = new int[] {7, 7, 7, 7, 7, 7, 7, 7};
thisLayout.columnWeights = new double[] {0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1};
thisLayout.columnWidths = new int[] {7, 7, 7, 7, 7, 7, 7, 7};
this.setLayout(thisLayout);
{
UsernameLabel = new JLabel();
this.add(UsernameLabel, new GridBagConstraints(0, 2, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
UsernameLabel.setText("Username");
}
{
PasswordLabel = new JLabel();
this.add(PasswordLabel, new GridBagConstraints(0, 3, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
PasswordLabel.setText("Password");
}
{
UsernameInput = new JTextField();
this.add(UsernameInput, new GridBagConstraints(2, 2, 6, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
}
{
PasswordInput = new JPasswordField();
this.add(PasswordInput, new GridBagConstraints(2, 3, 6, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
}
{
LoginButton = new JButton();
this.add(LoginButton, new GridBagConstraints(3, 5, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
LoginButton.setText("Login");
LoginButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
}
});
}
this.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Dieses kann auch von meiner Hauptfunktion wie gewünscht in das rechte Pane eingefügt werden - klappt. Wo ich jetzt aber hänge: Wenn man auf Login klickt und die Benutzerdaten richtig sind dann müsste ja auch im Hauptfenster das linke Pane mit dem Menü aktuallisiert werden. Hier fehlt mir einfach grade die Idee wie ich das vernünftig hinbekomme das ich eine aktuallisierung des Panes anstoße...
Hier nochmal kurz das Hauptfenster:
Java:
public class Start extends javax.swing.JFrame {
private static final long serialVersionUID = 9004956858470395817L;
private JSplitPane jSplitPane1;
private JPanel jPanel1;
private JButton InsertBasicRates;
private JButton AddRateTypeButton;
private JButton AddPortButton;
private JButton AddCarrierButton;
private JButton ShowRatesButton;
private JButton ExitButton;
private JButton LoginButton;
private JPanel jPanel2;
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Start inst = new Start();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}
public Start() {
super();
initGUI();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
{
jSplitPane1 = new JSplitPane();
getContentPane().add(jSplitPane1, BorderLayout.CENTER);
{
jPanel1 = new JPanel();
jSplitPane1.add(jPanel1, JSplitPane.RIGHT);
}
{
jPanel2 = new JPanel();
GridBagLayout jPanel2Layout = new GridBagLayout();
jSplitPane1.add(jPanel2, JSplitPane.LEFT);
jPanel2Layout.rowWeights = new double[] {0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1};
jPanel2Layout.rowHeights = new int[] {7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7};
jPanel2Layout.columnWeights = new double[] {0.1};
jPanel2Layout.columnWidths = new int[] {7};
jPanel2.setLayout(jPanel2Layout);
{
LoginButton = new JButton();
jPanel2.add(LoginButton, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
LoginButton.setText("Login");
LoginButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jSplitPane1.add(new LoginPanel(), JSplitPane.RIGHT);
}
});
}
{
ExitButton = new JButton();
jPanel2.add(ExitButton, new GridBagConstraints(0, 24, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
ExitButton.setText("Exit");
ExitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jSplitPane1.add(new ReallyExitPanel(), JSplitPane.RIGHT);
}
});
}
{
// Das hier soll nur angezeigt werden wenn der Benutzer sich angemeldet hat!
ShowRatesButton = new JButton();
jPanel2.add(ShowRatesButton, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
ShowRatesButton.setText("Show Rates");
}
{
// Das hier soll nur angezeigt werden wenn der Benutzer sich angemeldet hat!
AddCarrierButton = new JButton();
jPanel2.add(AddCarrierButton, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
AddCarrierButton.setText("Add Carrier");
}
}
}
pack();
this.setSize(1024, 768);
} catch (Exception e) {
//add your error handling code here
e.printStackTrace();
}
}
}
Kann mir da mal jemand kurz nen Denkanstoß geben? (Achso - das der Login-ActionListener noch leer ist weiß ich - da ich hier grade noch mit einen Dummy arbeite wäre hier so oder so noch keine wirkliche Abfrage drin.... Die Datenbank-Verbindung usw. ist später auch kein Problem - mir fehlt hier einfach grade die Idee.... D.h. man darf in diesem Action-Listener derzeit ruhig davon ausgehen das die Benutzerdaten wirklich gültig waren )