aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Newbie needs help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Newbie needs help" Watch "Newbie needs help" New topic
Author

Newbie needs help

jason gass
Greenhorn

Joined: Nov 11, 2004
Posts: 13
Hi Everyone,
I have a huge problem. I am new at java. I am taking a class in school and for the first half of the semester, the professor taught interface principle, the second half (less that 8 weeks) he is trying to teach java code. I need to create a spreadsheet. Simple grid with textboxs, labels and able to save. I am lost complety. I have a week and half and we havent been taught any events.

Can someone give me some direction to get the interface developed? I have been going back and forth between gridlayout and gridbaglayout. Imunsure what to use. I figured to use a loop to create textfields and store it to an array(not quite sure how this works) this is so the cells can be refrenced to, but then i need to be able to create labels next to the cells

Please help in anyway. I am really interested in Java but trying to learn it in 5 weeks is not my style.

Jason
Jimmy Die
Ranch Hand

Joined: Nov 20, 2003
Posts: 97
Hi,


I was looking at some java demos just reciently. There is a spreadsheet demo also. Have a look at this, and maybe more questions will come.Spreadsheet


Jimmy Die
jason gass
Greenhorn

Joined: Nov 11, 2004
Posts: 13
That is pretty close to what I need to get. I just got back from the bookstore looking at sample code and picked up a couple of books. I think I have an idea to get the layout done properly, but can someone direct me how to save the textfields to an array? I am using a loop to create them in a panel.

Thanks,

Jason

Note: I tried the source code link on that last page and it just comes up as a page with a bunch of mixed up writing? any suggestions?
jason gass
Greenhorn

Joined: Nov 11, 2004
Posts: 13
Can I create a java table that will do the basic task i need? or will it not work?

thanks
Barry Higgins
Ranch Hand

Joined: Jun 05, 2003
Posts: 89
To save textFields to an array you just create an array of TextFields eg.
TextFields txtFields=new TextFields[10];
then instantiate each one as you need it txtFields[0]=new TextField();
You should probably do this in a loop.
For a spreadsheet you can use a 2d array of TextBoxes; eg. TextFields[10][10]

The Applet that Jimmy sent you doesn't use TextFields it draws the cells using AWT. if you can get away with that go bananas.
However if you need to use TextFields you'll have to trace through the code replacing the Cell instnaces with TextFields. Whatever you need to do the code should be useful.

Lastly I can see the source code for that Applet without a problem but maybe you should try saving the code locally and opening it using notepad or whatever IDE you're using.
Good luck,
Barry
jason gass
Greenhorn

Joined: Nov 11, 2004
Posts: 13
Im not bound to either textfields or the AWT. My professor really hasnt talked much how to do this so I am looking for the easiest way right now as I am learning.

So I am looking at this in two ways:

1) use the AWT, I can have it create the cells
setLayout(new GridLayout(0, 10, 1, 1));
//make the cells

for (int b=1; b <=100; b++) {
add(new TextField(" "));

But I do not know where to go from here. I, can not get the labels to line up right at the top or bottom. When I create a new label it pushes the text boxes onto the next row.


2) Use an array to create textboxes and then display them, but I am unsure how to get them to line up properly in a grid format.

Finally, I need to be able to refrence the cells so I can do simple calculations like add and subtract.

Any suggestions?

Jason
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Take a look at the API docs. (This link is for version 1.4.2. If you are using a different version of Java, go here.) Scroll the top left frame down until you find the java.awt package. When you click on it, the bottom left frame lists the classes from that package. Scroll down until you find the GridLayout class. The page in the main frame on the right loads with lots of information. In particular, you need to check out the parameters for the constructor. I think you are not specifying the correct number of rows and columns that you want to use.

HTH

Layne

p.s. You may get more information if you visit the Swing / AWT / SWT / JFace forum. That's where they talk about GUI issues around these parts.
[ November 15, 2004: Message edited by: Layne Lund ]

Java API Documentation
The Java Tutorial
Ben Wood
Ranch Hand

Joined: Aug 14, 2001
Posts: 342
Jason, I hope I don't confuse you at this stage by offering a different solution, but you might want to look at the JTable swing component. This will take away your layout headaches.

examples

sun tutorial
[ November 16, 2004: Message edited by: Ben Wood ]

SCJP 1.4, www.gsi3d.org.uk
jason gass
Greenhorn

Joined: Nov 11, 2004
Posts: 13
Can a Jtable do arithmetic functions?

Jason
Sebastiaan Kortleven
Ranch Hand

Joined: Mar 12, 2004
Posts: 81
No.. a JTable is just a graphical representation of data.. You give it an array of arrays (myData[10][10] eg, add the JTable to your jframe (or jpanel or whatever) and it will show you your data in a table like structure.. much, much easier then writing your own with JTextFields..
A JTable can be editable, so double clicking on a cell will start to edit that cell, and the value will be saved in you array..

Check out the official tutorial on JTables..

JTable Tutorial

If you want those functions, you can always write your own TableModel, it looks harder then it is... first try to get the table on the screen (with the data), then try the custom tablemodel..


good luck!
[ November 17, 2004: Message edited by: Sebastiaan Kortleven ]
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1824

While there has been a lot of useful suggestions, I think that this is best suited in our Jwing/AWT forum, so there it goes.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
 
jQuery in Action, 2nd edition
 
subject: Newbie needs help