2016-07-17 27 views
0

Ich weiß, das wurde in anderen Threads gefragt, aber ich kann nicht sehen, was das Problem mit meinem Code ist. Meine JPanels werden nicht in meinem JFrame angezeigt. Bitte helfen.JFrame wird nicht angezeigt

Dies ist für eine Einführungsstufe Informatik Schule Zuordnung, so dass einige sonst dumme Dinge außerhalb meiner Kontrolle sind.

Danke.

package view; 

import java.awt.BorderLayout; 
import java.awt.Color; 
import java.awt.Dimension; 

import javax.swing.JButton; 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.JPanel; 
import javax.swing.JTextField; 

public class DequeueView { 

    //main JFrame 
    private JFrame mainFrame ; 

    //Containers 
    private JPanel display; 
    private JPanel buttons; 

    //Buttons 
    private JButton addFront; 
    private JButton dequeue; 
    private JButton enqueue; 
    private JButton removeRear; 

    //Textbox and label 
    private JTextField displayQueue; 
    private JLabel greeting; 

    /** 
    * Constructor for the main application with the title bar set to 
    * a title. 
    */ 
    public DequeueView(){ 

     /* 
     * The hierarchy is as follows: 
     * 
     * Container JPanel- to display the message "Hello" and to display queue. 
     *  Label , textbox 
     * Container JPanel- to put the buttons. 
     *  JButtons 
     */ 

     JPanelDisplayHelper();  //formats the displays. 
     JPanelButtonHelper();  //formats the buttons. 
     JFrameHelper();    //formats the JFrame. 

    } 

    /** 
    * Sets up the JFrame that will house the 4 buttons. 
    */ 
    private void JPanelButtonHelper(){ 

     addFront = new JButton("Add to Front"); 
     dequeue = new JButton("Take from Front"); 
     enqueue = new JButton("Add to Back"); 
     removeRear = new JButton("Take from Back"); 

     buttons = new JPanel(); 
     buttons.add(addFront); 
     buttons.add(dequeue); 
     buttons.add(enqueue); 
     buttons.add(removeRear);   
    } 

    /** 
    * Sets up the JFrame that will house everything. 
    */ 
    private void JFrameHelper(){ 

     String title = new String ("Queue Application"); 

     mainFrame = new JFrame(); 
     mainFrame.setLocation(200,150); 
     mainFrame.setSize(500, 500); 
     mainFrame.setResizable(false); 
     mainFrame.setTitle(title); 
     mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

     mainFrame.add(display); 
     mainFrame.add(buttons); 
     mainFrame.setLayout(new BorderLayout()); 
     mainFrame.setVisible(true); 

    } 

    /** 
    * Sets up the JPanel that will display the greeting and the queue in 
    * String form. 
    */ 
    private void JPanelDisplayHelper(){ 

     String text = new String("Hello, this app displays a queue. Enjoy!"); 

     //formats the label 
     greeting = new JLabel(text, JLabel.LEFT); 
     greeting.setVisible(true); 


     //formats the JTextField. 
     displayQueue = new JTextField(10); 
     displayQueue.setText("Your Queue will display here!"); 
     displayQueue.setBackground(Color.WHITE); 
     displayQueue.setEditable(false); 
     displayQueue.setVisible(true); 
     displayQueue.validate(); 

     display = new JPanel(); 
     display.add(greeting); 
     display.add(displayQueue); 
     display.setLayout(new BorderLayout()); 


    } 

} 

Antwort

0

Haben Sie die Klasse in Ihrer Hauptmethode so eingerichtet? Es weiß nicht, darüber in der Hauptmethode für Ihr Programm, wenn Sie es tatsächlich definieren

public static void main(String[] args) { 
    new DequeueView(); 
} 

PS: können Sie den Titel Parameter innerhalb des JFrame frame = new JFrame („title“)

+0

Wenn Sie hinzufügen brauche mehr Klärung zu diesem Tag einfach mich, ich halte mich für ziemlich gut in JFrames –