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 10 of 10

Thread: Problem in AWT and IFrame implementaion

  1. #1
    Junior Member
    Join Date
    Apr 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem in AWT and IFrame implementaion

    hi all and thanks for all the help previously and i was wondering if you could check it over and point out any errors i might of missed

    my credit class
    public class Credit {
     
    	private float credit;
     
    	public Credit(){
    		credit = 0;
    		}
     
    	public float addCredit(){
     
    		credit = + 10;
     
    		return credit;
     
    	}
    }

    my dispenser class

    import javax.swing.JOptionPane;
     
     
    public class Dispencer {
     
    	private String itemID;
    	private String itemName; 
        private int itemPrice;  
        private int itemQuantity;
        boolean items;
     
        public Dispencer(String id, String in, int ip, int iq)
        {
        	itemID = id;
        	itemName = in;
            itemPrice  = ip;
            itemQuantity = iq;
        }
     
        public String getItemID()
        {
        	return(itemID);
        }
     
        public String getItemName()
        {
        	return(itemName);
        }
     
        public int getItemPrice()
        {
        	return(itemPrice);
        }
     
        public int getItemQuantity()
        {
        	return(itemQuantity);
        }
     
        public void replaceItemQuantity(int iq)
        {
            itemQuantity = iq;
    	}
     
        public void replaceItemPrice(int ip)
        {
            itemPrice  = ip;
        }
     
        public String getItemValues()
        {
        	if (!itemID.equals(""))
        		return "Item ID: " + itemID + "Item Name: " + itemName + "  Price: " + itemPrice + " Quantity:" + itemQuantity + "\n";
        	else
        		return("");
        }
     
        public boolean itemsLeft(){
     
     
    		if ((itemQuantity <1))
    			items = false;
    		else
    			items = true;
     
    		return (items);	
    	}
     
        public void dispenceItem()
        {
    		if (itemQuantity >0)
    			itemQuantity = itemQuantity - 1;
    		else
    		{
    			JOptionPane.showMessageDialog(null, "No items left");
    		} 
    	}
        }

    and my GUI
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    import java.util.*;
     
    public class DispencerMachineGUI  extends JFrame implements ActionListener
    {
     
    	private JPanel entryPanel;
    	private JTextArea displayArea;
    	private JLabel itemID, itemName, itemPrice, itemQuantity, credit;
    	private JTextField itemIDTextField, itemNameTextField, itemPriceTextField, itemQuantityTextField, creditTextField;
    	private JButton addItem, dispItem, addCredit, purchaseItem, changePrice, changeQuantity;
    	private int counter;
    	private Dispencer dp1;
    	private Credit c;
    	private ArrayList <Dispencer> item; 
     
    	public static void main(String[] args)
     
    	{
    	new DispencerMachineGUI();
    	}
     
    	public  DispencerMachineGUI()
    	{
     
    	setLayout(new FlowLayout());
    	entryPanel = new JPanel();
    	entryPanel.setPreferredSize(new Dimension(400, 120));
    	entryPanel.setBackground(Color.lightGray);
     
    	itemID = new JLabel("Product ID (starting from 0): ");
    	itemName = new JLabel("Product Name: ");
    	itemPrice =  new JLabel("Product Price (p): ");
    	itemQuantity = new JLabel("Product Quantity : ");
    	credit = new JLabel("Total Credit ");
     
    	creditTextField = new JTextField(10);
    	itemIDTextField = new JTextField(20);
    	itemNameTextField = new JTextField(20);
    	itemPriceTextField = new JTextField(20);
    	itemQuantityTextField = new JTextField(20);
     
    	entryPanel.add(itemID);
    	entryPanel.add(itemIDTextField);
    	entryPanel.add(itemName);
    	entryPanel.add(itemNameTextField);
    	entryPanel.add(itemPrice);
    	entryPanel.add(itemPriceTextField);
    	entryPanel.add(itemQuantity);
    	entryPanel.add(itemQuantityTextField);
     
    	addItem = new JButton("Add Item(s)");
    	addItem.setForeground(Color.red);
    	dispItem = new JButton("Display All Items");
    	dispItem.setForeground(Color.blue);
    	addCredit = new JButton("Add Credit");
    	addCredit.setForeground(Color.blue);
    	purchaseItem = new JButton("Purchase Item");
    	purchaseItem.setForeground(Color.blue);
    	changePrice = new JButton("Change the price of an item");
    	changePrice.setForeground(Color.blue);
    	changeQuantity = new JButton("Change the quantity of an item");
    	changeQuantity.setForeground(Color.blue);
     
    	displayArea = new JTextArea();
    	displayArea.setPreferredSize(new Dimension(400, 200));
    	displayArea.setBackground(Color.lightGray);
     
    	add(entryPanel);
    	add(addItem);
    	add(dispItem);
    	add(addCredit);
    	add(credit);
    	add(creditTextField);
    	add(displayArea);
    	add(changePrice);
    	add(changeQuantity);
    	add(purchaseItem);
    	addItem.addActionListener(this);
    	dispItem.addActionListener(this);
    	addCredit.addActionListener(this);
    	purchaseItem.addActionListener(this);
    	changePrice.addActionListener(this);
    	changeQuantity.addActionListener(this);
     
    	dispItem.setEnabled(false);
    	addCredit.setEnabled(false);
    	purchaseItem.setEnabled(false);
    	changePrice.setEnabled(false);
    	changeQuantity.setEnabled(false);
     
    	setTitle("Vending Machine");
    	setSize(450, 500);
    	setVisible(true);
     
    	item = new ArrayList <Dispencer>();
    	c = new Credit();
    	counter = 0;
     
     
    	creditTextField.setText("0");
     
    	}
     
    	public void actionPerformed(ActionEvent e) 
    	{
     
    		//Adding to available Credit
     
    		if (e.getSource() == addCredit)
    		{
    			float totalMoney = c.addCredit();
    			c.credit = c.credit - totalMoney;
    			creditTextField.setText(Float.toString(totalMoney));
    		}
     
    		//Adding items to array
     
    		if (e.getSource() == addItem)
    		{
    			String iid, itn; 
    			int itp, itq;
    			if(counter <5)
    			{
    				iid = itemIDTextField.getText();
    				itn = itemNameTextField.getText();
    				itp = Integer.parseInt(itemPriceTextField.getText());
    				itq = Integer.parseInt (itemQuantityTextField.getText());
     
    				dp1 = new Dispencer(iid, itn, itp, itq);
    				item.add(counter, (Dispencer) dp1);
     
    				itemIDTextField.setText("");
    				itemNameTextField.setText(""); 
    				itemPriceTextField.setText(""); 
    				itemQuantityTextField.setText("");
     
    				counter ++;
     
    				if(counter > 4)
    				{
    					dispItem.setEnabled(true);
    					addCredit.setEnabled(true);
    					purchaseItem.setEnabled(true);
    					changePrice.setEnabled(true);
    					changeQuantity.setEnabled(true);
    				}
    			}
    			else
    			{
    				JOptionPane.showMessageDialog(null, "The maximum of 5 items have been entered");
    			}	
    		}
     
    		//Displaying all items in array
     
    		if (e.getSource() == dispItem)
    		{
    			String allItems="";
    			for (int i=0; i<5; i++)
    			{
    				allItems = allItems +  item.get(i).getItemValues() +"\n";
    			}
    			displayArea.setText(allItems);
     
    		}
     
    		//Changing the price of an item
     
    		if (e.getSource() == changePrice)
    		{
    			int whichitem;
    			String allItems="";
    			whichitem = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter the ID of the item to be modified"));
    			int newItemPrice = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter the new price"));	
    			item.get(whichitem).replaceItemPrice(newItemPrice);
     
    		//Display updated price
    			for (int i=0; i<5; i++)
    			{
    				allItems = allItems + item.get(i).getItemValues() +"\n";	
    			}
    			displayArea.setText(allItems);
     
    		}
     
    		//Changing the quantity of an item
     
    		if (e.getSource() == changeQuantity)
    		{
    			int whichitem;
    			String allItems="";
    			whichitem = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter the ID of the item to be modified"));
    			int newItemQuantity = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter the new Quantity"));	
    			item.get(whichitem).replaceItemQuantity(newItemQuantity);
     
    		//Display updated quantity
    			for (int i=0; i<5; i++)
    			{
    				allItems = allItems + item.get(i).getItemValues() +"\n";	
    			}
    			displayArea.setText(allItems);
     
    		}
     
    		//Vending an item
     
    		if (e.getSource() == purchaseItem){
    			String Itemname, newidnum,newItm, qtyWanted, allRecords=""; 
    			int newPr, qAvailable, rec=0;
    			boolean found =false;
     
    			Itemname = (JOptionPane.showInputDialog(null, "Enter the item name"));
    			while(rec<5){
    				if(Itemname.equals(item.get(rec).getItemName()))
    				{
    					found = true;
    					qtyWanted = (JOptionPane.showInputDialog(null, "Enter amount to vend"));
    				int QtyOrdered = Integer.valueOf(qtyWanted).intValue();
    					newidnum = item.get(rec).getItemID();
    					newItm = item.get(rec).getItemName();
    					newPr = item.get(rec).getItemPrice();
    					qAvailable = item.get(rec).getItemQuantity();
    				int CurrentQ = Integer.valueOf(qAvailable).intValue();
    				int NewQ = CurrentQ - QtyOrdered;
    				float P = Float.valueOf(newPr).floatValue();
    				float TotalPr = P * QtyOrdered;
     
    				if(TotalPr < c.credit)
    				{
    						JOptionPane.showMessageDialog(null,"Your bill is "+ TotalPr + "p");
    						c.credit = c.credit - TotalPr;
    						String str = "" + c.credit;
    						creditTextField.setText(str);
    						item.get(rec).dispenceItem(newidnum, newItm, newPr, NewQ);
     
    						for (int i=0; i<5; i++)
    						{
    							allRecords = allRecords + item.get(i).getItemValues() +"\n";
    						}
    						displayArea.setText(allRecords);}
     
    						else
    						{
    							JOptionPane.showMessageDialog(null,"Insufficient Credit");
     
    						}
     
    					break;
    				}
    				rec++;
    			}
    				if(found == false){
    					JOptionPane.showMessageDialog(null, "Item not found, please try again");
    			}
    	}
    }
    }
    Last edited by Deep_4; November 7th, 2012 at 12:41 PM.


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 286 Times in 225 Posts
    Blog Entries
    4

    Default Re: Could you check this

    Hello AZBOY2000,

    What happened with this thread:

    http://www.javaprogrammingforums.com...2-classes.html ?

    Did my suggestion solve your question or is it still open?

    What is the problem with the code you have submitted above? Is it working as expected?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  3. #3
    Junior Member
    Join Date
    Apr 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Could you check this

    that problem has been solved i think all this thread is about how i want someone else to look through my code and makes sure it works cos i think there is a problem when you order stuff because it keeps refusing to vend items cos it says i dont have enough money even when i have more than enough

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 286 Times in 225 Posts
    Blog Entries
    4

    Default Re: Could you check this

    Quote Originally Posted by AZBOY2000 View Post
    that problem has been solved i think all this thread is about how i want someone else to look through my code and makes sure it works cos i think there is a problem when you order stuff because it keeps refusing to vend items cos it says i dont have enough money even when i have more than enough
    I can't get this to add an item.. ?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  5. #5
    Junior Member
    Join Date
    Apr 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Could you check this

    hi ive added more code to my classes but an error keeps appearing c.credit bit because it keeps saying it is not visible

    credit class
    public class Credit {
     
    	private float credit;
     
    	public Credit(){
    		credit = 0;
    		}
     
    	public boolean hasCredit()
    	{
    		boolean money;
     
    		if (credit > 0)
    			money = true;
    		else
    			money = false;
     
    		return (money);		
    	}
     
    	public float addCredit(){
     
    		credit = credit + 10;
     
    		return credit;
     
    	}
    }

    my dispenser class
    import javax.swing.JOptionPane;
    public class Dispenser {
    	private String ItemID;
    	private String ItemName; 
        private int ItemPri;  
        private int ItemQuant;
        boolean items;
     
        public Dispenser(String id, String in, int ip, int iq)
        {
        	ItemID = id;
        	ItemName = in;
            ItemPri  = ip;
            ItemQuant = iq;
        }
     
        public String getItemID()
        {
        	return(ItemID);
        }
     
        public String getItemName()
        {
        	return(ItemName);
        }
     
        public int getItemPrice()
        {
        	return(ItemPri);
        }
     
        public int getItemQuantity()
        {
        	return(ItemQuant);
        }
     
        public void replaceItemQuantity(int iq)
        {
            ItemQuant = iq;
    	}
     
        public void replaceItemPrice(int ip)
        {
            ItemPri  = ip;
        }
     
        public String getItemValues()
        {
        	if (!ItemID.equals(""))
        		return "Item ID- " + ItemID + "Item Name- " + ItemName + "  Item Price- " + ItemPri + " Item Quantity-" + ItemQuant + "\n";
        	else
        		return("");
        }
     
        public boolean itemsLeft(){
     
     
    		if ((ItemQuant <1))
    			items = false;
    		else
    			items = true;
     
    		return (items);	
    	}
     
        public void dispenceItem()
        {
    		if (ItemQuant >0)
    			ItemQuant = ItemQuant - 1;
    		else
    		{
    			JOptionPane.showMessageDialog(null, "No items left");
    		} 
    	}
    }

    and my GUI
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    import java.util.*;
     
    public class VendingMachineGUI extends JFrame implements ActionListener {
    	private JPanel entryPanel;
    	private JTextArea displayArea;
    	private JLabel lblVend,lblItemID, lblItemName, lblItemPri, lblItemQuant, lblcredit;
    	private JTextField ItemIDTextField, ItemNameTextField, ItemPriTextField, ItemQuantTextField, creditTextField;
    	private JButton addItButton, displayItButton, addCreditButton, purchaseItemButton, changePriceButton, changeQuantityButton;
    	private int counter;
    	private Dispenser dp1;
    	public Credit c;
    	private ArrayList <Dispenser> item; 
     
    	public static void main(String[] args)
     
    	{
    	new VendingMachineGUI();
    	}
     
    	public  VendingMachineGUI()
    	{
    		setLayout(new FlowLayout());
    		entryPanel = new JPanel();
    		entryPanel.setPreferredSize(new Dimension(400, 210));
    		entryPanel.setBackground(Color.RED);
     
    		lblVend = new JLabel("*****Vending Machine*****");
    		lblVend.setForeground(Color.BLUE);
    		lblItemID = new JLabel("Item ID: ");
    		lblItemID.setForeground(Color.WHITE);
    		lblItemName = new JLabel("Item Name: ");
    		lblItemName.setForeground(Color.WHITE);
    		lblItemPri =  new JLabel("Item Price: ");
    		lblItemPri.setForeground(Color.WHITE);
    		lblItemQuant = new JLabel("Item Quantity: ");
    		lblItemQuant.setForeground(Color.WHITE);
    		lblcredit = new JLabel("Credit Amount ");
    		lblcredit.setForeground(Color.BLUE);
     
    		creditTextField = new JTextField(10);
    		ItemIDTextField = new JTextField(32);
    		ItemNameTextField = new JTextField(30);
    		ItemPriTextField = new JTextField(30);
    		ItemQuantTextField = new JTextField(30);
     
    		entryPanel.add(lblItemID); entryPanel.add(ItemIDTextField); entryPanel.add(lblItemName);
    		entryPanel.add(ItemNameTextField); entryPanel.add(lblItemPri); entryPanel.add(ItemPriTextField);
    		entryPanel.add(lblItemQuant); entryPanel.add(ItemQuantTextField);
     
    		addItButton = new JButton("Add Item(s)");
    		addItButton.setForeground(Color.BLUE);
    		displayItButton = new JButton("Display All Items");
    		displayItButton.setForeground(Color.BLUE);
    		addCreditButton = new JButton("Add Credit");
    		addCreditButton.setForeground(Color.BLUE);
    		purchaseItemButton = new JButton("Purchase Item");
    		purchaseItemButton.setForeground(Color.BLUE);
    		changePriceButton = new JButton("Change the price of an item");
    		changePriceButton.setForeground(Color.BLUE);
    		changeQuantityButton = new JButton("Change the quantity of an item");
    		changeQuantityButton.setForeground(Color.BLUE);
     
    		displayArea = new JTextArea();
    		displayArea.setPreferredSize(new Dimension(400, 200));
    		displayArea.setBackground(Color.MAGENTA);
     
    		add(lblVend); add(addCreditButton); add(lblcredit); add(creditTextField);
     
    		add(entryPanel);
    		add(addItButton); add(displayItButton); add(displayArea); 
    		add(changePriceButton); add(changeQuantityButton); add(purchaseItemButton);
    		addItButton.addActionListener(this); displayItButton.addActionListener(this);
    		addCreditButton.addActionListener(this); purchaseItemButton.addActionListener(this);
    		changePriceButton.addActionListener(this); changeQuantityButton.addActionListener(this);
     
    		displayItButton.setEnabled(false); addCreditButton.setEnabled(false);
    		purchaseItemButton.setEnabled(false); changePriceButton.setEnabled(false);
    		changeQuantityButton.setEnabled(false);
     
    		setTitle("******Vending Machine******");
    		setSize(450, 610);
    		setVisible(true);
     
    		item = new ArrayList <Dispenser>();
    		c = new Credit();
    		counter = 0;
     
    		creditTextField.setText("0");
    		}
    	public void actionPerformed(ActionEvent e) 
    	{
     
    		if (e.getSource() == addCreditButton)
    		{
    			float totalMoney = c.addCredit();
    			c.credit = c.credit - totalMoney;
    			creditTextField.setText(Float.toString(totalMoney));
    		}
     
    		if (e.getSource() == addItButton)
    		{
    			String iid, itn; 
    			int itp, itq;
    			if(counter <5)
    			{
    				iid = ItemIDTextField.getText();
    				itn = ItemNameTextField.getText();
    				itp = Integer.parseInt(ItemPriTextField.getText());
    				itq = Integer.parseInt (ItemQuantTextField.getText());
     
    				dp1 = new Dispenser(iid, itn, itp, itq);
    				item.add(counter, (Dispenser) dp1);
     
    				ItemIDTextField.setText(""); ItemNameTextField.setText(""); 
    				ItemPriTextField.setText(""); ItemQuantTextField.setText("");
     
    				counter ++;
     
    				if(counter > 4)
    				{
    					displayItButton.setEnabled(true); addCreditButton.setEnabled(true);
    					purchaseItemButton.setEnabled(true); changePriceButton.setEnabled(true);
    					changeQuantityButton.setEnabled(true);
    				}
    			}
    			else
    			{
    				JOptionPane.showMessageDialog(null, "The maximum of 5 items have been entered");
    			}	
    		}
     
    		if (e.getSource() == displayItButton)
    		{
    			String allItems="";
    			for (int i=0; i<5; i++)
    			{
    				allItems = allItems +  item.get(i).getItemValues() +"\n";
    			}
    			displayArea.setText(allItems);
     
    		}
     
    		if (e.getSource() == changePriceButton)
    		{
    			int whichitem;
    			String allItems="";
    			whichitem = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter the Item ID of the item to be modified"));
    			int newItemPrice = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter the new price"));	
    			item.get(whichitem).replaceItemPrice(newItemPrice);
     
    			for (int i=0; i<5; i++)
    			{
    				allItems = allItems + item.get(i).getItemValues() +"\n";	
    			}
    			displayArea.setText(allItems);
     
    		}
     
    		if (e.getSource() == changeQuantityButton)
    		{
    			int whichitem;
    			String allItems="";
    			whichitem = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter the ID of the item to be modified"));
    			int newItemQuantity = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter the new Quantity"));	
    			item.get(whichitem).replaceItemQuantity(newItemQuantity);
     
    			for (int i=0; i<5; i++)
    			{
    				allItems = allItems + item.get(i).getItemValues() +"\n";	
    			}
    			displayArea.setText(allItems);
     
    		}
     
    		if (e.getSource() == purchaseItemButton){
    			String Itemname, newidnum,newItm, qtyWanted, allRecords=""; 
    			int newPr, qAvailable, rec=0;
    			boolean found =false;
     
    			Itemname = (JOptionPane.showInputDialog(null, "Enter the item name"));
    			while(rec<5){
    				if(Itemname.equals(item.get(rec).getItemName()))
    				{
    					found = true;
    					qtyWanted = (JOptionPane.showInputDialog(null, "Enter amount to vend"));
    				int QtyOrdered = Integer.valueOf(qtyWanted).intValue();
    					newidnum = item.get(rec).getItemID(); newItm = item.get(rec).getItemName();
    					newPr = item.get(rec).getItemPrice(); qAvailable = item.get(rec).getItemQuantity();
    				int CurrentQ = Integer.valueOf(qAvailable).intValue();
    				int NewQ = CurrentQ - QtyOrdered;
    				float P = Float.valueOf(newPr).floatValue();
    				float TotalPr = P * QtyOrdered;
     
    			if(TotalPr < c.credit)
    			{
    				JOptionPane.showMessageDialog(null,"Your bill is "+ TotalPr);
    				c.credit = c.credit - TotalPr;
    				String str = "" + c.credit;
    				creditTextField.setText(str);
    				item.get(rec).dispenceItem(newidnum, newItm, newPr, NewQ);
     
    				for (int i=0; i<5; i++)
    				{
    					allRecords = allRecords + item.get(i).getItemValues() +"\n";
    				}
    				displayArea.setText(allRecords);}
     
    				else
    				{
    					JOptionPane.showMessageDialog(null,"Insufficient Credit");
     
    				}
     
    				break;
    			}
    			rec++;
    		}
    			if(found == false){
    			JOptionPane.showMessageDialog(null, "Item not found, please try again");
    	}
    	}
    	}
    	}

  6. #6
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 286 Times in 225 Posts
    Blog Entries
    4

    Default Re: Could you check this

    In the Credit class, you need to change:

    [B]private[/B] float credit;
    to

    [B]public[/B] float credit;
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  7. #7
    Junior Member
    Join Date
    Apr 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Could you check this

    hi thanks for that its solved that problem but i still have an error the line
    item.get(rec).DispenseItem(newidnum, newItm, newPr, NewQ);
    because the DispenseItem bit is underlined and it says it's not applicable

  8. #8
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 286 Times in 225 Posts
    Blog Entries
    4

    Default Re: Could you check this

    In the Dispenser class, you need to change:

        public void dispenceItem() {
            if (ItemQuant > 0)
                ItemQuant = ItemQuant - 1;
            else {
                JOptionPane.showMessageDialog(null, "No items left");
            }
        }
    to

        public void dispenceItem(String newidnum, String newItm, int newPr, int NewQ) {
            if (ItemQuant > 0)
                ItemQuant = ItemQuant - 1;
            else {
                JOptionPane.showMessageDialog(null, "No items left");
            }
        }
    The dispenceItem() method needs to be able to accept the arguments, String, String, Int, Int.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  9. #9
    Junior Member
    Join Date
    Apr 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Could you check this

    thanks for all the help so far i just have two problems left and i think there both simple
    1. is that when i order stuff it refuses to dispence because it says i dont have enough credit
    2 . is that ive forgot what you put so you can change the color of the overall form cos i wana change it from grey to blue

  10. #10
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 286 Times in 225 Posts
    Blog Entries
    4

    Default Re: Could you check this

    Quote Originally Posted by AZBOY2000 View Post
    thanks for all the help so far i just have two problems left and i think there both simple
    1. is that when i order stuff it refuses to dispence because it says i dont have enough credit
    2 . is that ive forgot what you put so you can change the color of the overall form cos i wana change it from grey to blue
    I can't get this code to refuse to dispence an item? It doesn't allow me to add anything and it says my credit is 0. Please tell me what I need to do to see this problem for myself.

    Have you tried .setBackground(Color.BLUE); ?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

Similar Threads

  1. Replies: 5
    Last Post: May 21st, 2009, 02:45 AM
  2. How to check that console input should be integer only?
    By Konnor in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: February 2nd, 2009, 04:37 AM