so whats going on? (things aren't showing up)
I have the following code below, which is well commented and explains pretty much what it does. in theory it creates a window 800x600, puts "Sample Application" in the top, under the words (SOUTH i believe) creates a wrapper panel with a grid lay out of two, thus holding two more panels, one containing buttons and one containing a description of the buttons.
Now when run all that shows up is "Sample Application" why is that?
Code:
package OtherGUI;
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
public class MainWindow
{
private Vector<JPanel> panel;
/**
* Call MainWindow which in turns calls the CreateWindow that contains
* all the properties and contents of the entire application.
*
* @param args
*/
public static void main(String args[])
{
new MainWindow();
}
/**
* Call the CreateWindow method that contains all the
* contents and properties of the Frame.
*/
public MainWindow()
{
panel = new Vector<JPanel>(4);
JPanel temp = CreateContent();
panel.add(temp);
CreateWindow();
}
/**
* Create the basis of the frame, the size, and location on the
* desktop of the application. populate the application with the
* CreateContent() method
*
*/
public void CreateWindow()
{
JFrame window = new JFrame("Main Window");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setBounds(10, 10, 800, 600);
JLabel title = new JLabel("Sample Application");
title.setFont(new Font("Serif", Font.PLAIN, 26));
window.add(title, BorderLayout.CENTER);
CreateContent();
window.setVisible(true);
}
/**
* Gather all the contents together and display
* them with in a grid Layout.
*/
private JPanel CreateContent()
{
JPanel addButtons = Buttons();
//Gather all the conents
JPanel contents = new JPanel();
contents.setLayout(new GridLayout(4,2));
contents.add(addButtons);
return addButtons;
}
/**
* Create a Panel specifically for Buttons.
* in this case the four main buttons which are
* Movies, Customer, Games and Home.
*
* @return - buttonHolder which is the JPanel
* that contains the buttons
*/
private JPanel Buttons()
{
JPanel wrapper = new JPanel();
wrapper.setLayout(new GridLayout(2,4));
JButton home = new JButton("home");
JButton customer = new JButton("customer");
JButton movies = new JButton("movies");
JButton games = new JButton("games");
//des = description
JTextArea desOne = new JTextArea("Sample Text");
desOne.setEditable(false);
JTextArea desTwo = new JTextArea("Sample Text");
desTwo.setEditable(false);
JTextArea desThree = new JTextArea("Sample Text");
desThree.setEditable(false);
JTextArea desFour = new JTextArea("Sample Text");
desFour.setEditable(false);
//desHolder = descriptionHolder
JPanel desHolder = new JPanel();
desHolder.setLayout(new GridLayout(1, 4));
desHolder.add(desOne);
desHolder.add(desTwo);
desHolder.add(desThree);
desHolder.add(desFour);
//Hold all the buttons
JPanel buttonHolder = new JPanel();
buttonHolder.setLayout(new GridLayout(1,4));
buttonHolder.add(home);
buttonHolder.add(customer);
buttonHolder.add(movies);
buttonHolder.add(games);
buttonHolder.setBorder(new TitledBorder(new EtchedBorder(), "Navagation"));
/*
* Hold both contents of Button Holder and
* desHolder
*/
wrapper.add(buttonHolder);
wrapper.add(desHolder);
return buttonHolder;
}
}