I am trying to create an inventory GUI display for scool. I have this GUI class as part of a 4 class program. For some reason I thought that the last lines created buttons yet this program lacks them. I also hav problems having my main call the GUI to display, appearently it takes more than having [CDGui myGui = new CDGui();] in main. here is the GUI, can anyone tell me what I am missing?

 * Class to create Graphic user interface
 * to display inventory
// impotr GUI classes for program useage
import java.awt.event.MouseEvent;
import javax.swing.JTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.GridLayout;
import javax.swing.JButton;
import java.awt.event.MouseListener;
 * @author vincent herrmann
public class CDGui extends JFrame
    //variables for GUI
       private JLabel label1;
	private JButton button1;
	private JLabel label2;
	private JLabel label3;
	private JLabel label4;
	private JLabel label5;
	private JTextField ProductCode;
	private JTextField CDtitle;
	private JTextField Restock;
	private JTextField TotalValue;
	private JButton button2;

	* Required designer variable.
	private int length = 5;
	private int index = 0;

	private String cdname = null;
	private double productcode = 0;
	private double price = 0;
	private double inventory = 0;
	private double productValue = 0;
	private CDNames compactdisc[]= new CDNames[5];

	private JTextField Quantity;
	private JLabel label6;
	private JTextField TextField1;
         //variables for GUI
        private JTextField textField1;
        private JTextField textField2;
        private JTextField textField3;
        private JTextField textField4;
        private JTextField textField5;
        private JButton nextButton;
        private JButton previousButton;
        // GUI constructor
        public CDGui(CDNames[] cdInventory, int index)
            super( "C.D. Inventory");

           this.compactdisc = cdInventory;

         setLayout( new GridLayout());
         //create textfield with 2 columns

         textField1 = new JTextField( 2 );
         add( textField1 );

         //print out data
         textField2 = new JTextField( "C.D. Title"+ compactdisc[index].getCdName() );
         add( textField2 );

          textField3= new JTextField( "price "+compactdisc[index].getCdPrice() );

         textField4 = new JTextField("restock cost"+ compactdisc[index].getRestockValue() );
         add( textField4 );

         textField5 = new JTextField( "total value"+ compactdisc[index].totalvalue());
         add( textField5 );
       }// end constructor
        public CDGui()

		// TO DO: Add any constructor code after InitializeComponent call
		//openfile for icon picture box

		// array set up
		//CDNames compactdisc[] = new CDNames[5];
		double temp;
		temp = 10.99 * 1.05;
		compactdisc[0] = new CDNames( "Beatles", 10.99, 50, 12345,temp);

		temp = 10.99 * 1.05;
		compactdisc[1] = new CDNames( "Bread", 10.99, 30, 12346,temp);

		temp = 10.99 * 1.05;
		compactdisc[2] = new CDNames( "Fleetwood Mac", 10.99, 30, 12347,temp);

		temp = 10.99 * 1.05;
		compactdisc[3] = new CDNames( "Heart", 10.99, 25, 12348,temp);

		temp = 10.99 * 1.05;
		compactdisc[4] = new CDNames( "Vanhalen", 10.99, 40, 12349,temp);

		cdname = compactdisc[0].getCDName();
		productcode = compactdisc[0].getcdProductCode();
		price = compactdisc[0].getCdPrice();
		inventory = compactdisc[0].getcdinventory();
        nextButton = new JButton ("next");
        add (nextButton);// adds to jframe
        previousButton = new JButton ("previous");
        add (previousButton); // add to jframe
        }// end class CDGui

JFrames are invisible until you explicitly make them visible.
You have 2 constructors. If you call the first it adds labels but not buttons. If you call the second it adds buttons but not labels. You can't call both constructors for the same instance.

This article has been dead for over six months. Start a new discussion instead.