Frame-Inhalt wird nicht angezeigt!

Luk10

Top Contributor
Hallo,

Ich habe bei meinem kleine GUI ein paar Variablen-Name geändert (der Übersicht halber) und nach jetztigem Testen wird mir nur noch ein leerer Frame angezeigt ...

Kann mir jemand sagen was damit nicht stimmt?

Java:
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;

public class LoginGui {
  
  private String zustand;
  private static String getName;
  private static String getKey;
  
  JFrame mainFrame;
  JTextField nameField;
  JTextField passwortField;
  JLabel anzeigeLabel;
  

    public void passwortFragen () {
        zustand = "login";
        
        mainFrame = new JFrame();
        JLabel nameLabel = new JLabel("Name:");
        JLabel passwortLabel = new JLabel("Passwort:");
        nameField = new JTextField(40);
        passwortField = new JTextField(40);
        JPanel hauptPanel = new JPanel();
        JButton loginButton = new JButton("Login");
        anzeigeLabel = new JLabel();
        JButton zurueckButton = new JButton("Zurück");
        JPanel unteresPanel = new JPanel();
        
        mainFrame.setSize(300, 150);
        mainFrame.setVisible(true);
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        loginButton.addActionListener(new LoginListener());
        zurueckButton.addActionListener(new ZurueckListener());
        
        mainFrame.getContentPane().add(BorderLayout.CENTER, hauptPanel);
        mainFrame.getContentPane().add(BorderLayout.SOUTH, unteresPanel);
        hauptPanel.setLayout(new BoxLayout(hauptPanel, BoxLayout.Y_AXIS));
        hauptPanel.add(nameLabel);
        hauptPanel.add(nameField);
        hauptPanel.add(passwortLabel);
        hauptPanel.add(passwortField);
        hauptPanel.add(anzeigeLabel);
        unteresPanel.add(loginButton);
        unteresPanel.add(zurueckButton);
    }
    public void passwortFestlegen () {
        zustand = "erstellen";
        
        mainFrame = new JFrame();
        JLabel passwortLabel = new JLabel("Geben Sie ihr Passwort ein:");
        JLabel nameLabel = new JLabel ("Geben Sie ihren Namen ein:");
        passwortField = new JTextField(40);
        nameField = new JTextField(40);
        JButton erstellenButton = new JButton("Senden");
        JPanel hauptPanel = new JPanel();
        anzeigeLabel = new JLabel();
        JPanel unteresPanel = new JPanel();
        JButton zurueckButton = new JButton("Zurück");
        
        mainFrame.setSize(300, 150);
        mainFrame.setVisible(true);
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        erstellenButton.addActionListener(new SpeicherListener());
        zurueckButton.addActionListener(new ZurueckListener());
        
        mainFrame.getContentPane().add(BorderLayout.CENTER, hauptPanel);
        mainFrame.getContentPane().add(BorderLayout.SOUTH, unteresPanel);
        hauptPanel.setLayout(new BoxLayout(hauptPanel, BoxLayout.Y_AXIS));
        
        hauptPanel.add(nameLabel);
        hauptPanel.add(nameField);
        hauptPanel.add(passwortLabel);
        hauptPanel.add(passwortField);
        hauptPanel.add(anzeigeLabel);
        unteresPanel.add(erstellenButton);
        unteresPanel.add(zurueckButton);
    }
    
    public void anfragen() {
        zustand = "anfragen";
        
        mainFrame = new JFrame();
        JButton loginButton = new JButton("Login");
        JButton erstellenButton = new JButton("Erstellen");
        JLabel startLabel = new JLabel("Wenn sie noch keinen Account haben, klicken sie auf 'Erstellen'");
        JPanel hauptPanel = new JPanel();

        mainFrame.setSize(400, 80);
        mainFrame.setVisible(true);
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        loginButton.addActionListener(new LoginFensterListener());
        erstellenButton.addActionListener(new SpeicherFensterListener());
        
        mainFrame.getContentPane().add(BorderLayout.CENTER, hauptPanel);
        hauptPanel.add(startLabel);
        hauptPanel.add(loginButton);
        hauptPanel.add(erstellenButton);     
        
    }
    public void adminErstellen() {
        zustand = "admin";
        
        mainFrame = new JFrame();
        JPanel hauptPanel = new JPanel();
        JPanel northPanel = new JPanel();
        JButton initialisierenButton = new JButton ("Initialisieren");
        JButton zurueckButton = new JButton ("Zurueck");
        JLabel northLabel = new JLabel("Admin, Initialisieren wenn noch nicht gemacht");
        
        mainFrame.setSize(400, 80);
        mainFrame.setVisible(true);
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        initialisierenButton.addActionListener(new InitialisierenListener());
        zurueckButton.addActionListener(new ZurueckListener());
        
        mainFrame.getContentPane().add(BorderLayout.CENTER, hauptPanel);
        mainFrame.getContentPane().add(BorderLayout.NORTH, northPanel);
        hauptPanel.setLayout(new BoxLayout(hauptPanel, BoxLayout.Y_AXIS));
        hauptPanel.add(initialisierenButton);
        hauptPanel.add(zurueckButton);
        northPanel.add(northLabel);
    }
             
    public static String getName() {
        return getName;
    }
    public static String getKey() {
        return getKey;
    }

}

Die ActionListener hab ich weggelassen weil's ziemlich viel sonst ist!

Danke, Luk
 
Code:
mainFrame.setVisible(true);
setVisible(true) auf den Frame immer erst aufrufen wenn die Komponenten alle platziert sind, wenn' s nicht anderst geht (Änderungen zur Laufzeit) per validate(); die GUI aktualisieren.
 

Neue Themen


Zurück
Oben