Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 22 of 22

Thread: My buttons will not work

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    13
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default My buttons will not work

    I have been working on this program for about a week and for some reason it works fine until i start adding buttons. I needed to modify my program to navigate buttons (First, Previous, Next and Last) to the GUI that allows the user to move to the first item, the previous item, the next item, and the last item in the inventory. If the first item is displayed and the user clicks on the Previous button, the last item should be displayed. If the last item is displayed and the user clicks on the Next button, the first item should displayed. The thing is my I keep getting error's. I think it is my packages or my imports. I must be missing something but I am not sure what?

    Here is my code:
    import java.awt.*;
    import javax.swing.*;
    import java.text.NumberFormat;
    import java.util.Locale;
    import java.util.Arrays;
    public class InventoryPart5
    {
    	public static Printer[] sortArray(Printer[] printers)
    	{
     
    		String[] productName = new String[printers.length];
     
     
    		Printer[] serialNumber = new Printer [printers.length];
     
     
    		for (int i = 0; i < printers.length; i++)
    		{
    		  productName[i] = printers[i].getProductName();
    		}
     
     
    		Arrays.sort(productName);
     
    		for (int i = 0; i < printers.length; i++)
    		{
    		     for (int j = 0; j < productName.length; j++)
    		     {
    		          if (printers[i].getProductName().equalsIgnoreCase(productName[j]))
    				  {
    				     serialNumber[j] = printers[i];
     
    				  }
     
    		     }
    		}
     
    		return serialNumber;
     
    	}
     
     
    	public static double totalInventory(Printer[] printers)
    	{
    		double total = 0;
     
    		for (int i = 0; i < printers.length; i++)
    		{
    			total += printers[i].totalInventory();
    		}
     
    		return total;
    	}
     
    	public static void main (String args[])
    	{
     
    		NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
     
     
    		//create inventory items in array
    		Printer brother = new Printer("P1101", "Brother Inkjet Muliti-function Printer", 12, 217.60, "BroLM200");
    		Printer canon = new Printer("P1102","Canon Bubble Jet Photo Printer", 13, 1249.98, "CanJPH300");
    		Printer dell = new Printer("P1103", "Dell Multi-Function Laser Printer", 3, 149.99, "DelMFL400");
    		Printer hp = new Printer("P1104","HP LaserJet Printer" , 5, 149.99, "HPL500");
    		Printer lexmar = new Printer("P1105","Lexmar CLP Printer", 10, 299.98, "LexCLP600");
     
    		final Printer[] printerList = new Printer[5];
    		printerList[0] = brother;
    		printerList[1] = canon;
    		printerList[2] = dell;
    		printerList[3] = hp;
    		printerList[4] = lexmar;
     
     
    		//calculate inventory total
    		double totalInventory = totalInventory(printerList);
     
     
           //initialize the JTextArea Class and set the parameters
    		final JTextArea textArea = new JTextArea(7, 15);
    		textArea.setText("");
    		textArea.setEditable(false);
     
    		JPanel buttonPanel = new JPanel();
    		buttonPanel.setLayout(new GridLayout(1, 3));
     
    		JButton firstButton = new JButton("First");
    		buttonPanel.add(firstButton);
    		firstButton.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent e)
    			{
    				printerIndex = 0;
    				prepareDisplay(printerList[printerIndex], textArea);
    			}
    		});
     
    		JButton lastButton = new JButton("Last");
    		buttonPanel.add(lastButton);
    		lastButton.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent e)
    			{
    				printerIndex = (printerList.length - 3);
    				prepareDisplay(printerList[printerIndex], textArea);
     
    			}
    		});
     
    		JLabel logoLabel = new JLabel (new ImageIcon("CompanyLogo.jpg"));
    		JPanel logoPanel = new JPanel();
    		logoPanel.add(logoLabel);
     
    			   JPanel centerPanel = new JPanel();
    			   centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS));
    			   centerPanel.add(prepareDisplay(printerList[printerIndex], textArea));
     
     
     
    		//prepare the text that will be displayed in the GUI
    		for (int i = 0; i < printerList.length; i++ )
    		{
    		   textArea.append(printerList[i]);
    		}
    		//initialize the GUI window and set the parameters
    		JFrame frame = new JFrame();
    		frame.setLayout(new BorderLayout());
    		frame.add(logoPanel, BorderLayout.NORTH);
    		frame.add(buttonPanel, BroderLayout.SOUTH);
    		frame.add(CenterPanel, BorderLayout.CENTER);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.pack();
    		frame.setLocationRelativeTo(null);
    		frame.setVisible(true);
     
    		textArea.append("\nTotal Inventory: " + nf.format(totalInventory));
     
    	}//end main
    }//end Iventory class
    I also have my product class
    import java.text.NumberFormat;
    import java.util.Locale;
    import java.util.Arrays;
     
    class Printer {
     
    	//declare class variables
    	private String itemNumber;
    	private String productName;
    	private int unitsInStock;
    	private double unitPrice;
    	private double totalInventory;
    	private String serialNumber;
    	private double restockFee;
    	NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
     
    	//class constructor
    	public Printer (String itemNumber, String productName, int unitsInStock, double unitPrice, String serialNumber){
    		this.itemNumber = itemNumber;
    		this.productName = productName;
    		this.unitsInStock = unitsInStock;
    		this.unitPrice = unitPrice;
    		this.serialNumber = serialNumber;
    		this.restockFee = restockFee;
    	}
     
    	//get and set methods
     
    	//item number
    	public String getItemNumber(){
    		return itemNumber;
    	}
     
    	public void setItemNumber(String itemNumber){
    		this.itemNumber = itemNumber;
    	}
     
     
    	//printer name
    	public String getProductName(){
    		return productName;
    	}
     
    	public void setProductName(String productName){
    		this.productName = productName;
    	}
     
    	//available units
    	public int getUnitsInStock(){
    		return unitsInStock;
    	}
     
    	public void setUnitsInStock (int unitsInStock){
    		this.unitsInStock = unitsInStock;
    	}
     
    	//price
    	public double getUnitPrice(){
    		return unitPrice;
    	}
     
    	public void setUnitPrice (double unitPrice){
    		this.unitPrice = unitPrice;
    	}
     
    	//calculate the total inventory
    	public double totalInventory()
    	{
    		return unitPrice * unitsInStock;
    	}
     
    	public double restockFee()
    	{
    		return unitPrice * .05;
    	}
     
    	//out put the variables with a toString method
    	public String toString ()
    	{
    			return "Item Number: " + itemNumber + "\nProduct Name: " + productName + "\nUnits In Stock: " + unitsInStock +
    									       "\nPrice : " +  nf.format(unitPrice)  + "\nTotal Value: " + nf.format(totalInventory()) + "\nSerial Number: " + serialNumber + "\nRestock Fee: " + nf.format(restockFee());
    	}
     
    }//end Printer class
     
    class Laser extends Printer
    {
     
    	//class variables
    	public String serialNumber;
    	public double restockFee;
    	public static final double RESTOCK_FEE_PERCENTAGE = .05;
     
    	//class constructor
    	public Laser (String itemNumber, String productName, int unitsInStock, double unitPrice, double totalInventory, String serialNumber)
    	{
    		super(itemNumber, productName, unitsInStock, unitPrice, serialNumber);
    		this.serialNumber = serialNumber;
     
    		//calculate the restock fee
    		restockFee = unitPrice * RESTOCK_FEE_PERCENTAGE;
    	}
    	//get and set methods
    	public String getSerialNumber()
    	{
    		return serialNumber;
    	}
     
    	public void setSerialNumber(String serialNumber)
    	{
    		this.serialNumber = serialNumber;
    	}
    	public double getRestockFee()
    	{
    		return restockFee;
    	}
     
    	// output restock fee and serial number
    	public String toString ()
    	{
    		return super.toString() + "\n" + "Serial Number: " + serialNumber + "Restock Fee:" + nf.format(getRestockFee());
    	}
     
    }
    My errors are on these lines won't copy and paste because Im using textPad unfortunately. I am getting errors like: can't find symbol for:
    1) printerIndex = 0;
    2) prepareDisplay(printerList[printerIndex], textArea);
    3) method prepareDisplay(Printer, javax.swing.JTextArea)
    4) location Class Inventory 5 centerPanel.add(prepareDisplay(printerList[printerIndex], textArea));

    And so many more. I really think I am missing a package.


  2. #2
    Junior Member
    Join Date
    Jun 2011
    Location
    Don't worry about it.
    Posts
    14
    My Mood
    Relaxed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My buttons will not work

    I took a look at your code. I strongly recommend that you download an IDE such as Eclipse or NetBeans that will check your spelling. This is why I use Eclipse. (I couldn't spell to save my life) Other than spelling, there were not too many noticable problems.

    You were right, you were missing an import (ActionEvent).

    Also you are never actually declaring the printerIndex variable in your action listeners. You have to give it a type when you declare it.


    Last thing for now. You dont have a prepareDisplay() method.

  3. #3
    Junior Member
    Join Date
    Jun 2011
    Location
    Don't worry about it.
    Posts
    14
    My Mood
    Relaxed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My buttons will not work

    I lied.

            private String itemNumber;
    	private String productName;
    	private int unitsInStock;
    	private double unitPrice;
    	private double totalInventory;
    	private String serialNumber;
    	private double restockFee;
    	NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
     
    	//class constructor
    	public Printer (String itemNumber, String productName, int unitsInStock, double unitPrice, String serialNumber){
    		this.itemNumber = itemNumber;
    		this.productName = productName;
    		this.unitsInStock = unitsInStock;
    		this.unitPrice = unitPrice;
    		this.serialNumber = serialNumber;
    		this.restockFee = restockFee;
    	}

    You don't pass in a restockFee parameter. You are assigning this.restockFee to one of 2 things: 1) null or 2) restockFee which isn't anything at this point in the code.

    --Jams

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: My buttons will not work

    I keep getting error's.
    When you get errors please copy and paste here the full text of the error message.

  5. #5
    Junior Member
    Join Date
    Jun 2011
    Posts
    13
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My buttons will not work

    Thank you for your reply. First I must say that I actually uninstalled Eclipse and Netbeans because we are using TextPad and I failed my first attempt at this class because I spend too much time trying to learn those other IDE's. I did make some changes to my program but first: very confused on your last post about the restock fee I put:
    public double restockFee()
    {
    return unitPrice * .05;
    }
    Before I added the buttons my program did do everything it was suppose to, including calculate in the restock fee for each printer. I got 100% on that assignment actually. However, I am suppose to modify the program to add buttons. The First, last, previous and next buttons and also add a logo of my choice. I got my program to compile and run, unfortunately my buttons do absolutely nothing. I only added the First, last and logo for now because I am trying to break up the code in pieces. Once I get the first two buttons and logo working it will be easy to reuse the code and add the others. I'm not exactly sure where my problem is at his point but here is my code if you would not mind reviewing it for me one more time. Thank you again for your response it is greatly appreciated.
    public class InventoryPart5
    {
    public static Printer[] sortArray(Printer[] printers)
    {

    String[] productName = new String[printers.length];


    Printer[] serialNumber = new Printer [printers.length];


    for (int i = 0; i < printers.length; i++)
    {
    productName[i] = printers[i].getProductName();
    }


    Arrays.sort(productName);

    for (int i = 0; i < printers.length; i++)
    {
    for (int j = 0; j < productName.length; j++)
    {
    if (printers[i].getProductName().equalsIgnoreCase(productName[j]))
    {
    serialNumber[j] = printers[i];

    }

    }
    }

    return serialNumber;

    }
    public static double totalInventory(Printer[] printers)
    {
    double total = 0;

    for (int i = 0; i < printers.length; i++)
    {
    total += printers[i].totalInventory();
    }

    return total;
    }
    static int printerIndex= 0;

    public static JTextArea PrepareDisplay(Printer myPrinter, JTextArea myTextArea)
    {
    NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);

    myTextArea.setText("");

    myTextArea.append(myPrinter.toString());
    return myTextArea;
    }

    public static void main (String args[])
    {
    Printer brother = new Printer("P1101", "Brother Inkjet Muliti-function Printer", 12, 217.60, "BroLM200");
    Printer canon = new Printer("P1102","Canon Bubble Jet Photo Printer", 13, 1249.98, "CanJPH300");
    Printer dell = new Printer("P1103", "Dell Multi-Function Laser Printer", 3, 149.99, "DelMFL400");
    Printer hp = new Printer("P1104","HP LaserJet Printer" , 5, 149.99, "HPL500");
    Printer lexmar = new Printer("P1105","Lexmar CLP Printer", 10, 299.98, "LexCLP600");
    //create inventory items in array
    final Printer[] printerList = new Printer[5];

    printerList[0] = brother;
    printerList[1] = canon;
    printerList[2] = dell;
    printerList[3] = hp;
    printerList[4] = lexmar;


    //initialize the JTextArea Class and set the parameters
    final JTextArea textArea = new JTextArea(10,15);
    textArea.setText("");
    textArea.setEditable(false);


    //create the first and last buttons and add them to the button panel
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridLayout(1, 3));

    JButton firstButton = new JButton("First");
    buttonPanel.add(firstButton);
    firstButton.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    printerIndex = 0; //set index to the first item in the array

    }
    });


    JButton lastButton = new JButton("Last");
    buttonPanel.add(lastButton);
    lastButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    printerIndex = (printerList.length - 3); //set index to the last item in the array

    }
    });

    //create company logo and then add it to the logo panel
    JLabel logoLabel = new JLabel (new ImageIcon("Company Logo.jpg"));
    JPanel logoPanel = new JPanel();
    logoPanel.add(logoLabel);

    JPanel centerPanel = new JPanel();
    centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS));

    //prepare the text that will be displayed in the GUI
    for (int i = 0; i < printerList.length; i++ )
    {
    textArea.append("\n"+ printerList[i] + "\n");
    }
    //initialize the GUI window and set the parameters
    JFrame frame = new JFrame();
    frame.getContentPane().add(new JScrollPane(textArea));
    frame.setLayout(new BorderLayout());
    frame.add(logoPanel, BorderLayout.NORTH);
    frame.add(buttonPanel, BorderLayout.SOUTH);
    frame.add(centerPanel, BorderLayout.CENTER);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);


    }//end main
    }//end Iventory class

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: My buttons will not work

    unfortunately my buttons do absolutely nothing.
    What are they supposed to do? I see some assignment statements in the listener code.
    Try debugging your code by adding some printlns to the actionPerformed methods to show that they are being executed.



    BTW Please wrap you code in code tags not quote tags.

  7. #7
    Junior Member
    Join Date
    Jun 2011
    Posts
    13
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My buttons will not work

    I tried but for some reason I have not icon to wrap my program in. The big X right? Where did it go?

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: My buttons will not work

    Code tags are in the Go Advanced area, the # icon.
    Or just add them manually.

  9. #9
    Junior Member
    Join Date
    Jun 2011
    Posts
    13
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My buttons will not work

    Sorry, dah!!! (On Information overload right now, sorry) When the GUI window appears, the First printer ("brother printer" since it is in assorted array (alphabetical order)) should be displayed. The first, last, previous and next buttons should allow the user to navigate through the printers. I don't see how I am missing anything at this point (except of course the next and previous buttons I didn't add yet.)
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.text.NumberFormat;
    import java.util.Locale;
    import java.util.Arrays;
     
     
    public class InventoryPart5
    {
    		public static Printer[] sortArray(Printer[] printers)
    						{
     
    							String[] productName = new String[printers.length];
     
     
    							Printer[] serialNumber = new Printer [printers.length];
     
     
    							for (int i = 0; i < printers.length; i++)
    							{
    							  productName[i] = printers[i].getProductName();
    							}
     
     
    							Arrays.sort(productName);
     
    							for (int i = 0; i < printers.length; i++)
    							{
    							     for (int j = 0; j < productName.length; j++)
    							     {
    							          if (printers[i].getProductName().equalsIgnoreCase(productName[j]))
    									  {
    									     serialNumber[j] = printers[i];
     
    									  }
     
    							     }
    							}
     
    							return serialNumber;
     
    						}
    						public static double totalInventory(Printer[] printers)
    						{
    							double total = 0;
     
    							for (int i = 0; i < printers.length; i++)
    							{
    								total += printers[i].totalInventory();
    							}
     
    							return total;
    						}
    						static int printerIndex= 0;
     
    						public static JTextArea PrepareDisplay(Printer myPrinter, JTextArea myTextArea)
    						{
    						NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
     
    						myTextArea.setText("");
     
    						myTextArea.append(myPrinter.toString());
    						return myTextArea;
    	}
     
    		public static void main (String args[])
    	{
    		Printer brother = new Printer("P1101", "Brother Inkjet Muliti-function Printer", 12, 217.60, "BroLM200");
    		Printer canon = new Printer("P1102","Canon Bubble Jet Photo Printer", 13, 1249.98, "CanJPH300");
    		Printer dell = new Printer("P1103", "Dell Multi-Function Laser Printer", 3, 149.99, "DelMFL400");
    		Printer hp = new Printer("P1104","HP LaserJet Printer" , 5, 149.99, "HPL500");
    		Printer lexmar = new Printer("P1105","Lexmar CLP Printer", 10, 299.98, "LexCLP600");
    		//create inventory items in array
    		final Printer[] printerList = new Printer[5];
     
    		printerList[0] = brother;
    		printerList[1] = canon;
    		printerList[2] = dell;
    		printerList[3] = hp;
    		printerList[4] = lexmar;
     
    		//initialize the JTextArea Class and set the parameters
    		final JTextArea textArea = new JTextArea(10,15);
    		textArea.setText("");
    		textArea.setEditable(false);
     
     
    	 	 //create the first and last buttons and add them to the button panel
    		 JPanel  buttonPanel = new JPanel();
    		 buttonPanel.setLayout(new GridLayout(1, 3));
     
    		JButton firstButton = new JButton("First");
    			   buttonPanel.add(firstButton);
    			   firstButton.addActionListener(new ActionListener()
    			   {
    			   			public void actionPerformed(ActionEvent e)
    			   			{
    			   				printerIndex = 0;  //set index to the first item in the array
     
    			   			}
    				});
     
     
    					   JButton lastButton = new JButton("Last");
    					   buttonPanel.add(lastButton);
    					   lastButton.addActionListener(new ActionListener() {
    					   	   			public void actionPerformed(ActionEvent e) {
    					   	   				printerIndex = (printerList.length - 3); //set index to the last item in the array
     
    					   	   			}
    		});
     
    						//create company logo and then add it to the logo panel
    					   JLabel logoLabel = new JLabel (new ImageIcon("Company Logo.jpg"));
    					   JPanel logoPanel = new JPanel();
    					   logoPanel.add(logoLabel);
     
    					   JPanel centerPanel = new JPanel();
    					   centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS));
     
    				//prepare the text that will be displayed in the GUI
    				for (int i = 0; i < printerList.length; i++ )
    				{
    					textArea.append("\n"+ printerList[i] + "\n");
    				}
    		//initialize the GUI window and set the parameters
    		JFrame frame = new JFrame();
    		frame.getContentPane().add(new JScrollPane(textArea));
    		frame.setLayout(new BorderLayout());
    		frame.add(logoPanel, BorderLayout.NORTH);
    		frame.add(buttonPanel, BorderLayout.SOUTH);
    	    frame.add(centerPanel, BorderLayout.CENTER);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.pack();
    		frame.setLocationRelativeTo(null);
    		frame.setVisible(true);
     
     
    	}//end main
    }//end Iventory class
    Here is my printer class:
    import java.text.NumberFormat;
    import java.util.Locale;
    import java.util.Arrays;
     
    class Printer {
     
    	//declare class variables
    	private String itemNumber;
    	private String productName;
    	private int unitsInStock;
    	private double unitPrice;
    	private double totalInventory;
    	private String serialNumber;
    	private double restockFee;
    	NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
     
    	//class constructor
    	public Printer (String itemNumber, String productName, int unitsInStock, double unitPrice, String serialNumber){
    		this.itemNumber = itemNumber;
    		this.productName = productName;
    		this.unitsInStock = unitsInStock;
    		this.unitPrice = unitPrice;
    		this.serialNumber = serialNumber;
    		this.restockFee = restockFee;
    	}
     
    	//get and set methods
     
    	//item number
    	public String getItemNumber(){
    		return itemNumber;
    	}
     
    	public void setItemNumber(String itemNumber){
    		this.itemNumber = itemNumber;
    	}
     
     
    	//printer name
    	public String getProductName(){
    		return productName;
    	}
     
    	public void setProductName(String productName){
    		this.productName = productName;
    	}
     
    	//available units
    	public int getUnitsInStock(){
    		return unitsInStock;
    	}
     
    	public void setUnitsInStock (int unitsInStock){
    		this.unitsInStock = unitsInStock;
    	}
     
    	//price
    	public double getUnitPrice(){
    		return unitPrice;
    	}
     
    	public void setUnitPrice (double unitPrice){
    		this.unitPrice = unitPrice;
    	}
     
    	//calculate the total inventory
    	public double totalInventory()
    	{
    		return unitPrice * unitsInStock;
    	}
     
    	public double restockFee()
    	{
    		return unitPrice * .05;
    	}
     
    	//out put the variables with a toString method
    	public String toString ()
    	{
    			return "Item Number: " + itemNumber + "\nProduct Name: " + productName + "\nUnits In Stock: " + unitsInStock +
    									       "\nPrice : " +  nf.format(unitPrice)  + "\nTotal Value: " + nf.format(totalInventory()) + "\nSerial Number: " + serialNumber + "\nRestock Fee: " + nf.format(restockFee());
    	}
     
    }//end Printer class
     
    class Laser extends Printer
    {
     
    	//class variables
    	public String serialNumber;
    	public double restockFee;
    	public static final double RESTOCK_FEE_PERCENTAGE = .05;
     
    	//class constructor
    	public Laser (String itemNumber, String productName, int unitsInStock, double unitPrice, double totalInventory, String serialNumber)
    	{
    		super(itemNumber, productName, unitsInStock, unitPrice, serialNumber);
    		this.serialNumber = serialNumber;
     
    		//calculate the restock fee
    		restockFee = unitPrice * RESTOCK_FEE_PERCENTAGE;
    	}
    	//get and set methods
    	public String getSerialNumber()
    	{
    		return serialNumber;
    	}
     
    	public void setSerialNumber(String serialNumber)
    	{
    		this.serialNumber = serialNumber;
    	}
    	public double getRestockFee()
    	{
    		return restockFee;
    	}
     
    	// output restock fee and serial number
    	public String toString ()
    	{
    		return super.toString() + "\n" + "Serial Number: " + serialNumber + "Restock Fee:" + nf.format(getRestockFee());
    	}
     
    }
    Sorry about that.

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: My buttons will not work

    So, is the program working ok for you now?
    If not please explain.

  11. #11
    Junior Member
    Join Date
    Jun 2011
    Posts
    13
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My buttons will not work

    No, its not working. I have two buttons that appear in the GUI window but nothing else display's in the window. I need each printer to appear through the navigation of the buttons.
    Printer brother = new Printer("P1101", "Brother Inkjet Muliti-function Printer", 12, 217.60, "BroLM200");
    		Printer canon = new Printer("P1102","Canon Bubble Jet Photo Printer", 13, 1249.98, "CanJPH300");
    		Printer dell = new Printer("P1103", "Dell Multi-Function Laser Printer", 3, 149.99, "DelMFL400");
    		Printer hp = new Printer("P1104","HP LaserJet Printer" , 5, 149.99, "HPL500");
    		Printer lexmar = new Printer("P1105","Lexmar CLP Printer", 10, 299.98, "LexCLP600");
    		//create inventory items in array
    		final Printer[] printerList = new Printer[5];
     
    		printerList[0] = brother;
    		printerList[1] = canon;
    		printerList[2] = dell;
    		printerList[3] = hp;
    		printerList[4] = lexmar;
    Notice these are all names of printers the brother, canon, dell, hp, lexmar. When the program in run I need the first printer to display as such:
    Item Number: P1101
    Product Name: Brother Inkjet Multi-Function Printer
    Price: $217.60
    Total Value: $2611.20
    Serial Number: BroM200
    Restock Fee: $10.88
    Then when the NEXT button is clicked I need it to display the next printer ("Canon") and its Item number, product name, etc. And I need the program to navigate through the inventory as long as the buttons are pushed. As of right now I am having a problem with the buttons. They do not work. When Take the buttons and the logo code out of my program, all my inventory displays in one big window. I need each printer to display only when the buttons are clicked. I hope you understood that. ~

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: My buttons will not work

    when the NEXT button is clicked I need it to display the next printer
    Where is the data to be displayed?

  13. #13
    Junior Member
    Join Date
    Jun 2011
    Posts
    13
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My buttons will not work

    Its in my array.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: My buttons will not work

    Sorry, I meant to say: where will the user see the data when it is displayed.

  15. #15
    Junior Member
    Join Date
    Jun 2011
    Posts
    13
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My buttons will not work

    On the GUI window.

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: My buttons will not work

    I see that this is going to take a long time.
    Where on the GUI window?

  17. #17
    Junior Member
    Join Date
    Jun 2011
    Posts
    13
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My buttons will not work

    Screenshot example.doc

    I have attached an example of how it should display. The buttons at the botton (SOUTH) the logo center top(NORTH) and the text should be in the middle(CENTER).

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: My buttons will not work

    Sorry, I don't download .doc files. Make it an image.
    What are you waiting for to make the needed changes to your code for it to display what you want?

  19. #19
    Junior Member
    Join Date
    Jun 2011
    Posts
    13
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My buttons will not work

    I was trying to get some direction or maybe some advice on where I might be going wrong with my program. But your right, this is taking too long. Thank you and have a nice day.

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: My buttons will not work

    You haven't designed a GUI with a slot to display things. You need a design BEFORE you write the code.

    Look at the panels you now have and where they are being positioned to be displayed.
    One set of GUI overlays another one. Go back and work on the GUI design.

  21. #21
    Junior Member
    Join Date
    Jun 2011
    Posts
    13
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My buttons will not work

    Is this a real forum or am I speaking to a computer? I do not understand what you are saying: isn't this my GUI WINDOW?

    //initialize the GUI window and set the parameters
    		JFrame frame = new JFrame();
    		frame.getContentPane().add(new JScrollPane(textArea));
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.pack();
    		frame.setLocationRelativeTo(null);
    		frame.setVisible(true);
    Don't worry about it I will figure it out. Thanks anyway for time.

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: My buttons will not work

    Good luck.

Similar Threads

  1. Help with Java buttons
    By Nameless _1 in forum AWT / Java Swing
    Replies: 2
    Last Post: June 18th, 2011, 03:16 PM
  2. How to add buttons on this code
    By tarell85 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 18th, 2011, 07:08 AM
  3. [SOLVED] Buttons not working..
    By khms in forum What's Wrong With My Code?
    Replies: 14
    Last Post: September 2nd, 2010, 06:01 PM
  4. JRadio buttons
    By chronoz13 in forum AWT / Java Swing
    Replies: 0
    Last Post: November 29th, 2009, 01:08 AM
  5. Need more buttons!
    By GotWankel? in forum AWT / Java Swing
    Replies: 0
    Last Post: October 5th, 2009, 01:08 AM