aspose file tools*
The moose likes Beginning Java and the fly likes Newbie 2D array and GUI question. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Newbie 2D array and GUI question." Watch "Newbie 2D array and GUI question." New topic
Author

Newbie 2D array and GUI question.

beverly Azanbou
Greenhorn

Joined: Nov 23, 2012
Posts: 3
Hi guys,
I am new to java and I have a class assignment.
So here it goes.
The assignment consist of filling a 2D array with user input.
The inputs are tutoring time and amount earned.
I have build the array but I have two questions:

1.) I am not able to get the numbers to print successcively,
when the user inputs some new values, the ones before that disappear from the text area.
I tried the append thing and created a for loop to go with , but still it won't do print out the previous values after I hit the enter key.

2.)How do I get the average for such and array with user input.My question is I am not sure where and how to create the counter for this array.

Last question, do you guys think my code is appropriate for building a 2D array?

These are some snippets of the code I have come up with so far.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39791
    
  28
Welcome to the Ranch

I am sorry to tell you, but you should get rid of the frame. And the windows. Ditch the GUI entirely … at least for the time being. What you should do, is get that application working as a console application. Get your tutoring class working, with lots of methods which allow you to enter time, get charges, etc. Get that working so you can call it from another class’ methods and print out the results on the command line/terminal. Then you can create a GUI to go on top of that.
Don’t put any application code in the GUI. The GUI calls the app and displays it. It does not do any arithmetic, recording, etc.
You have been told you have a 2D array, but you ain’t, because there ain’t no such critter. Note cowpoke grammar used on the Ranch What you have is an array or arrays, which is different from a 2D array, and better.
But why are you using arrays like that? Why don’t you have a TutorSession class which encapsulates the time and cost? You can even have a per‑hour field in that class, which allows it to do the arithmetic for you. You can have a Tutor class which has a TutorSession[] as a field. You can even fiddle things so you can get the first session by entering 1 and find sessions[0].

You should also go through the Java Tutorials and read about text components. Some of them support multiple lines and some only support a single line.
beverly Azanbou
Greenhorn

Joined: Nov 23, 2012
Posts: 3
Campbell Ritchie wrote:Welcome to the Ranch

I am sorry to tell you, but you should get rid of the frame. And the windows. Ditch the GUI entirely … at least for the time being. What you should do, is get that application working as a console application. Get your tutoring class working, with lots of methods which allow you to enter time, get charges, etc. Get that working so you can call it from another class’ methods and print out the results on the command line/terminal. Then you can create a GUI to go on top of that.
Don’t put any application code in the GUI. The GUI calls the app and displays it. It does not do any arithmetic, recording, etc.
You have been told you have a 2D array, but you ain’t, because there ain’t no such critter. Note cowpoke grammar used on the Ranch What you have is an array or arrays, which is different from a 2D array, and better.
But why are you using arrays like that? Why don’t you have a TutorSession class which encapsulates the time and cost? You can even have a per‑hour field in that class, which allows it to do the arithmetic for you. You can have a Tutor class which has a TutorSession[] as a field. You can even fiddle things so you can get the first session by entering 1 and find sessions[0].

You should also go through the Java Tutorials and read about text components. Some of them support multiple lines and some only support a single line.


My class assignment required that I use GUI.
I had actually created a 2 array that ran very will on its own, then I cut snippets of that and added it to the Jframe.
I don't see how I can get lots of methods when I need to fill and 2D array or and array of arrays like so:
TUTORING TIME(mins) AMOUNT EARNED($)
67 40
89 67
78 73

can you please explain how to do that?
How do I encapsulate the time and cost in a class and create separate methods that come together as a 2D array or array of arrays( I am not sure what the difference is between those two albeit all the research I have been doing online) .
This is the code for the 2 D array i wrote before I immersed it in the netBeans JFrame:
>
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8196
    
  23

beverly Azanbou wrote:My class assignment required that I use GUI...

Fine, but you didn't read what Campbell said properly. He said: "Ditch the GUI entirely … at least for the time being", and that is the essence of good programming - isolating problems.

Get your 2D array working first; then add the GUI stuff. And my advice would be to keep the two things as separate as you possibly can anyway.

HIH

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39791
    
  28
Winston Gutkowski wrote: . . . Campbell said . . . "Ditch the GUI entirely … at least for the time being", . . .
I also said, “Then you can create a GUI to go on top of that. ”
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39791
    
  28
beverly Azanbou wrote: . . .
I had actually created a 2 array that ran very will on its own, then I cut snippets of that and added it to the Jframe.
. .
You ought to use the app you had created, not trying to take it apart and put it into something else. If it works, don’t change it.
beverly Azanbou
Greenhorn

Joined: Nov 23, 2012
Posts: 3
I agree with you guys a 100% but I am just not sure where to start and how to do that.
I have only be writing code for like 23 days... so this is still very new to me.
Any help in the form of code samples and examples will be greatly appreciated.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39791
    
  28
Start with the old version of your code which worked without a GUI.
 
 
subject: Newbie 2D array and GUI question.