I am creating a program in Java to calculate various retail figures having to do with sale prices in different departments, and for some reason when I run my program I am getting an empty window that opens with nothing in it?? I know I have added panels, buttons, text fields, and a number of other elements that should be appearing inside of my window, but all I am getting is nothing, just a blank, empty window??
Anyway, here is my code, which compiles and runs just fine, with no errors:
but when I run this it opens a window with nothing in it, and I cannot understand this....import java.awt.*; import javax.swing.*; public class RetailCalculator extends JFrame { public JLabel itemMessageLabel; //to display item message public JPanel panel; public JTextField itemTextField; public JLabel departmentMessageLabel; public JLabel itemOriginalLabel; public JTextField itemOriginal; public JLabel percentOffLabel; public JTextField percentOff; public ButtonGroup bg; final int WINDOW_WIDTH = 1200, //WINDOW WIDTH IN PIXELS WINDOW_HEIGHT = 1000; /*Constructor*/ public RetailCalculator() { super("Retail Calculator"); //CREATE window //create window with title JFrame window = new JFrame ("Retail Calculator"); //set size of window window.setSize(WINDOW_WIDTH, WINDOW_HEIGHT); //what happens when x or close is clicked window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //display the window buildPanel(); pack(); window.setVisible(true); panel.setVisible(true);} //create label text field and buttons private void buildPanel() { //create custom panels JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); itemMessageLabel = new JLabel ("Enter your first item number: "); //text field for item name itemTextField = new JTextField(8); //select department from menu (combo, radio or menu) //display message to choose department departmentMessageLabel = new JLabel ("Choose your department: "); //create 5 departments with radio buttons JRadioButton department1 = new JRadioButton("Women's"); JRadioButton department2 = new JRadioButton("Men's"); JRadioButton department3 = new JRadioButton("Children's"); JRadioButton department4 = new JRadioButton("Shoes"); JRadioButton department5 = new JRadioButton("Toys"); bg = new ButtonGroup(); bg.add(department1); bg.add(department2); bg.add(department3); bg.add(department4); bg.add(department5); //text field for original price itemOriginalLabel = new JLabel ("Enter the items original price: "); itemOriginal = new JTextField(); //text field for percent discount percentOffLabel = new JLabel ("Enter the percent off for sale price: "); percentOff = new JTextField(2); //add item button JButton button1 = new JButton ("Add Item"); //calculate button computes and displays JButton button2 = new JButton ("Compute Sale Price"); //create and add objects to panel //add the item data to the panel panel.add(itemMessageLabel); panel.add(itemTextField); //add the departments to the panel //add original info to panel panel.add(itemOriginalLabel); panel.add(itemOriginal); panel.add(percentOffLabel); panel.add(percentOff); //add buttons panel.add(button1); panel.add(button2);} /* private inner class to handle event of buttons and radio fields */ public static void main(String[] args) { new RetailCalculator();}}
I did panel.setVisible(true);, and I thought that would cause the panel with all of the buttons to appear when run, but I am getting nothing here, Please Help!!