Results 1 to 12 of 12
Thread: array in GUI
- 04-22-2011, 02:00 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 17
- Rep Power
- 0
array in GUI
I need to array each drink, so that when value is input, the supply decreases by 1, and it displays back to the supply JTField. Here's my coding but it returns null value instead.
code:
public void actionPerformed(ActionEvent e)
{
double num1 = Double.parseDouble(jtf2.getText().trim());
double result = 0.0;
double change = 0.0;
VendMach v[] = new VendMach[0];
VendMach v1[] = new VendMach[0];
count--;
for(int i = 10; i >= v.length; i--){
if(e.getSource() == jbt1)
{
result = 1.20;
change = num1 - result;
coffee.setDrink("latte");
coffee.setResult(result);
coffee.setAmount(num1);
coffee.setChange(change);
coffee.setSupply(i--);
}
}
count--;
for(int i = 10; i >= v1.length; i--){
if(e.getSource() == jbt2)
{
result = 1.30;
change = num1 - result;
coffee.setDrink("White Coffee");
coffee.setResult(result);
coffee.setAmount(num1);
coffee.setChange(change);
coffee.setSupply(i--);
}
}
jtf1.setText(String.valueOf(result));
jtf3.setText(String.valueOf(change));
jtf4.setText(String.valueOf(supply));
showMessageDialog(null, coffee.toString());
}
- 04-22-2011, 02:21 AM #2
What returns a null value?
Also does it give you any exceptions? If so post the whole stacktrace
- 04-22-2011, 02:29 AM #3
Member
- Join Date
- Nov 2010
- Posts
- 44
- Rep Power
- 0
i'm trying to decipher your code here:
the i is from the for loop. and you are already decrementing it to begin with. Is that how you intend it?
I'll try to be helpful but i need clarification on what the code itself is doing, thanks.Last edited by f1gh; 04-22-2011 at 02:32 AM.
- 04-22-2011, 02:32 AM #4
setText(String s); is a void method, it's not supposed to return anything.
Btw try doing something like jtf4.setText(coffee.getSupply());
- 04-22-2011, 02:51 AM #5
- 04-22-2011, 03:05 AM #6
Member
- Join Date
- Apr 2011
- Posts
- 17
- Rep Power
- 0
well the value of i is returned to the supply field, i.e 'i' value is supply value. is it possible ?
- 04-22-2011, 03:09 AM #7
- 04-22-2011, 03:31 AM #8
Please post the whole class where you put that "actionPerformed()" method, I'm still trying to understand what you are trying to do. (in code tags and not quote tags :p)
Why are you creating two new arrays with zero size each time that method is run? As far as I can see, all you are using them for is the for-loops (which I have no idea why you are using either).Java Code:VendMach v[] = new VendMach[0]; VendMach v1[] = new VendMach[0];
No, that sends the value of i to the coffee object.The coffee.setSupply(i--) sends the decremented i value to the supply text fieldLast edited by OutputStream; 04-22-2011 at 03:33 AM.
- 04-22-2011, 03:38 AM #9
Member
- Join Date
- Apr 2011
- Posts
- 17
- Rep Power
- 0
I need to for loop each object(i.e latte, white coffe, etc) into an array of size 10. Simply put, there is 10 of each drink in stock. Now, when the user chooses a drink, stock for drink decreases......so i was doing for loops for each objects for.
- 04-22-2011, 03:53 AM #10
Member
- Join Date
- Apr 2011
- Posts
- 17
- Rep Power
- 0
What's the coding error with passing i value to supply text field ?
-
I have edited your post #14 above and have changed your [quote] [/quote] tags to [code] [/code] tags so that the code formatting won't be lost.
- 04-22-2011, 04:20 AM #12
Member
- Join Date
- Apr 2011
- Posts
- 17
- Rep Power
- 0
Similar Threads
-
Variable of an object in an array compared to an element of another array?
By asmodean in forum New To JavaReplies: 23Last Post: 09-07-2010, 08:12 PM -
Trying to make an array list // inserting an element to middle of array
By javanew in forum New To JavaReplies: 2Last Post: 09-06-2010, 01:03 AM -
create a 2d char array from a 1D string array
By jschmall12 in forum New To JavaReplies: 1Last Post: 04-27-2010, 09:01 PM -
Array length and printing out uninitialized array.
By nicolek808 in forum New To JavaReplies: 4Last Post: 09-10-2009, 09:12 AM -
How to add an integer to a array element and the store that backinto an array.
By Hannguoi in forum New To JavaReplies: 1Last Post: 03-31-2009, 06:40 AM


LinkBack URL
About LinkBacks
Reply With Quote


Bookmarks