Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Transferring final String values in one class to another class in Eclipse.

 
David Ward
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Afternoon guys!

Wondering if anyone could point me in the right direction. I have created a class in Eclipse which basically works out and displays a students timetable. For each timeslot I have created strings which are initialized to "" then changed if necessary.

Now I ran into a variety of problems when trying to create a Swing table in the same class, so made a new visual class and designed it that way. Now, I want to extract the Strings from Timetable.java so I can use them in the Swing table.

I've read up a little on Getters and Setters but wasn't sure I was using them properly. Would this be the right path to go down?

Any help is much appreciated!
 
Ben Ooms
Ranch Hand
Posts: 47
Debian Eclipse IDE Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,

Its a little bit difficult to find out what you want without seeing any code. Anyway if you want to populate a Jtable you want to use a defaultTableModel by passing the timetable data and column names as arrays or implement a adapter for your student timetable by creating a class extending abstractTableModel and feed the JTable with this model.

just my 2c
Regards,
Ben

 
David Ward
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply Ben! Even though this a coding forum I always feel like showing all my code would be messy! I'll show my workings for the timeslot values as the table is just a basic Jtable really.



But I will go away and have a bash at what you suggested Ben! ;p
 
David Ward
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
edit: Just noticed there are some lines in there which resulted from me tinkering but aren't actually used.
 
Ben Ooms
Ranch Hand
Posts: 47
Debian Eclipse IDE Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Based on the code at 136 till 141 you could create a new (static) method for the tablemodel:


In a other class where you have your visual code you can create the JTable with:


PS: dont forget the appropriate imports, I didn't test it (dont have testfile)but should work.

regards,
Ben
 
David Ward
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah! I see now! Thanks very much for your help Ben!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic