General Discussion Undecided where to post - do it here. |
Reply to Thread New Thread |
![]() |
#1 |
|
For starters, you want a class member
Code: Code
int index = 0; and change those to Code: Code
ptArray[index][0] = timeValue; ptArray[index][1] = paymentValue; index++; Regarding your TextArea issue, you can't do: Code: Code
textarea.append(ptArray); textarea.append takes a string as an argument. When you cast an object to a string (arrays are a subclass of Object), if there isn't a specific function for converting that object to a string it just prints out "gibberish" (actually, it's something like the memory address of the object IIRC, it should look like "[I@10b62c9"). You want to do something like the following: Code: Code
for (int i = 0; i < index; i++) textarea.append("time: " + ptArray[i][0] + "; payment: " + ptArray[i][1] + "\n"); |
![]() |
![]() |
#2 |
|
Your for loop condition is backwards. The loop is running forever.
Why are you appending them to reportArea every time the enter button is pressed? I thought you only wanted to do that when the report was generated? If you append to reportArea each time, you don't want the for loop, you just want to say: Code: Code
reportArea.append("Time: " + ptArray[index][0]...); index++; and of course remove the earlier index++; |
![]() |
![]() |
#4 |
|
Code:
Code
int index = 0; ... ptArray[index][0] = timeValue; ptArray[index][1] = paymentValue; index++; index is being set to zero each time that runs so it will always be zero when enterActionPerformed is run. it needs to be handled differently, and since you're doing java you should go with Kuci's suggestion. |
![]() |
![]() |
#5 |
|
|
![]() |
![]() |
#6 |
|
I really hate Java, but I bet learning Python will be a breeze after all this. That said, there's the right tool for the right job and I think Python should be very easy to learn, I learned the basics over a weekend and just picked up the more advanced stuff as I encountered it. Python's a breeze. |
![]() |
![]() |
#7 |
|
|
![]() |
![]() |
#10 |
|
The book I'm using is called Big Java third edition. You can download it if you want to take a look at it, that's how I got mine. It's from 2007 I think. Also, that link is much clearer and much more to the point. From what I have read so far am I correct in understanding that there is no way to have an undefined first parameter in the array? Which would explain why everyone first asks if I must use a multidimensional array. I went ahead and set it to 5 and just said **** it so I can move on to writing the calculations and other stuff they want. If they don't like it they can tell me later.
|
![]() |
![]() |
#11 |
|
|
![]() |
![]() |
#12 |
|
|
![]() |
![]() |
#13 |
|
The difference here is that the arrays are actually a literal and a crucial feature and the fact that they've been deprecated for something with astonishingly uglier syntax is obnoxious. |
![]() |
![]() |
#15 |
|
I said that if you know the limits then arrays are more efficient - knowing the limits mean that you don't expect them to change.
Dude, we're talking about ****ing managed code. ArrayList and equivalents are not going to be measurably "less efficient" in any plausible use case. Do we really have to play the "BlackCat defends some dumb comment he made long past the point that it's obvious to everyone else that he's wrong" game again? I don't use fixed arrays today because CPU speed easily can handle it, but my first "PC" was a 2 MHz 64 kb (OS took a third) and if anyone had suggested using dynamic versus static arrays, they would probably be fired. asd;lfkjdsaf; the only performance difference between a "dynamic array" and a regular array is the overhead of a method call. |
![]() |
![]() |
#16 |
|
Holy ****, you are dumb.
HERE ARE THE RELEVANT PIECES OF CODE FROM ARRAYLIST.JAVA IN THE ACTUAL ****ING JDK VERSION 6.18: Code: Code
/* * @(#)ArrayList.java 1.56 06/04/21 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package java.util; public class ArrayList { private Object[] elementData; private int size; public ArrayList(int initialCapacity) { this.elementData = new Object[initialCapacity]; } public E get(int index) { return (E) elementData[index]; } public void set(int index, E element) { elementData[index] = element; } public boolean add(E e) { ensureCapacity(size + 1); elementData[size++] = e; return true; } public void ensureCapacity(int minCapacity) { int oldCapacity = elementData.length; if (minCapacity > oldCapacity) { int newCapacity = (oldCapacity * 3)/2 + 1; if (newCapacity < minCapacity) newCapacity = minCapacity; // minCapacity is usually close to size, so this is a win: elementData = Arrays.copyOf(elementData, newCapacity); } } public E remove(int index) { E oldValue = (E) elementData[index]; int numMoved = size - index - 1; if (numMoved > 0) System.arraycopy(elementData, index+1, elementData, index, numMoved); elementData[--size] = null; // Let gc do its work return oldValue; } } It is literally a thin shim over a Java array. |
![]() |
![]() |
#18 |
|
It is literally a thin shim over a Java array. The most annoying thing about string arrays is Java's refusal to overload == to test string equality as opposed to just comparing the references. I don't know, I feel like they should have just made an exception for strings. |
![]() |
![]() |
#19 |
|
|
![]() |
![]() |
#20 |
|
Really? Okay, I was under the false impression that they were some special structure or whatnot. |
![]() |
Reply to Thread New Thread |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|