Welcome to Dream.In.Code
Become a Java Expert!

Join 149,522 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,391 people online right now. Registration is fast and FREE... Join Now!




Trouble getting selected Time from JTable

 
Reply to this topicStart new topic

Trouble getting selected Time from JTable, Assignment Help!

HermanW
27 May, 2007 - 06:42 AM
Post #1

New D.I.C Head
*

Joined: 26 Apr, 2007
Posts: 16


My Contributions
Been working on this assignment for months now but still cant get it working right. The trouble im having now is that my confirmation screen wont show the right time because I implemented my table heading for time manually. Can someone look at my program for me please...

Check out the pics for the problem...

I know the problem has got to do with this code (in ScheduleWindow class)
CODE

int tmpTF = table.getSelectedRow() + 8;


any suggestions guys??

Note: the selection was made at 1030 and pressed booked and confirmation comes out with a different time output.... /cry!

EDIT: Modified title to be more descriptive ~ jayman9

This post has been edited by jayman9: 27 May, 2007 - 08:27 AM


Attached thumbnail(s)
Attached Image Attached Image

Attached File(s)
Attached File  Program.zip ( 5.54k ) Number of downloads: 19
User is offlineProfile CardPM
+Quote Post

spullen
RE: Trouble Getting Selected Time From JTable
27 May, 2007 - 07:55 AM
Post #2

D.I.C Regular
Group Icon

Joined: 22 Mar, 2007
Posts: 330



Thanked: 1 times
Dream Kudos: 50
My Contributions
Try:
CODE

Date now = new Date();
SimpleDateFormat form = new SimpleDateFormat("hh:mm");
String timeNow = form.format(now); //timeNow should hold the current time

And it's in the java.text.*; (Date, and SimpleDateFormat).
User is offlineProfile CardPM
+Quote Post

HermanW
RE: Trouble Getting Selected Time From JTable
27 May, 2007 - 08:16 AM
Post #3

New D.I.C Head
*

Joined: 26 Apr, 2007
Posts: 16


My Contributions
thnx will try to put it in my code somehow....
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Trouble Getting Selected Time From JTable
27 May, 2007 - 08:23 AM
Post #4

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,303



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
The problem is that you are grabbing the value stored at the column and row that you select in your table, when all you want is the time value stored at the row heading.

The method getSelectedRow just returns the row number. With a couple of modifications you can grab the time from the rowNames array.

Here I added one more variable which uses the value from tmpTF to access the correct row inside the rowNames array. Got to parse it into type Integer since it is an Object array.
CODE

int tmpTF = table.getSelectedRow();
int tmpNo = table.getSelectedColumn();
            
int tmpTime = Integer.parseInt(rowNames[tmpTF][0].toString());


Next modifiy the call to the BookingDetail constructor to use this new variable in place of tmpTF.
CODE

BookingDetail BD = new BookingDetail(loggedUser, tmpBDate, tmpTime, tmpNo);


Now it will grab the time that is stored in that row of the table.
User is offlineProfile CardPM
+Quote Post

HermanW
RE: Trouble Getting Selected Time From JTable
27 May, 2007 - 08:45 AM
Post #5

New D.I.C Head
*

Joined: 26 Apr, 2007
Posts: 16


My Contributions
Yup... that got it working thnx heaps for the help...
User is offlineProfile CardPM
+Quote Post

HermanW
RE: Trouble Getting Selected Time From JTable
27 May, 2007 - 06:32 PM
Post #6

New D.I.C Head
*

Joined: 26 Apr, 2007
Posts: 16


My Contributions
Just a tiny error here i think... I'm trying to get the data loaded onto the JTable from textfile but nothing is comming up on the screen. The method that loads the data is ShowSchedule() which is placed in layout2 in TimeTableWindow Class.




Attached File(s)
Attached File  Java.zip ( 10.26k ) Number of downloads: 16
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 08:32PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month