This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Add New Record - Problem with GUI and JPanels Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Add New Record - Problem with GUI and JPanels" Watch "Add New Record - Problem with GUI and JPanels" New topic
Author

Add New Record - Problem with GUI and JPanels

Jason Marshall
Greenhorn

Joined: Jul 17, 2006
Posts: 18
Hello All,

I am up to the stage in my project where I need to add a new record.

I have built the GUI now that displays all the records that exist in a JTable.

So my question is.

When the user clicks on the Add New Button. This fires an Event.

How do I open a new JPanel that exists within the same JFrame?

My problem is because the Frames, Tables, Menus etc have already been created in it's main method. How do I create other Frame objects on a call to Action Service.

I am an URLyBird 1.2.2

Regards,

Jason


Look for solutions not problems!
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5216
    
  12

Jason Marshall wrote:I am up to the stage in my project where I need to add a new record.

Don't see any reason why you want to provide the possibility to add a new record in your GUI, it's not required at all by the instructions (only find rooms and book room as far as I know). You won't receive extra points for doing things that were not required, you only might lose some points...

You have problems with something you totally not need, so I would just advice: don't do it and concentrate on the things you must do.

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2379
    
    7

Jason Marshall wrote:How do I open a new JPanel that exists within the same JFrame?


Hi Jason, how are you doing book or search? Are you using internal frame (like you are currently) or popup frame/dialog?

The idea should be the same. Creating or delete records is the least worry of the GUI. Searching and booking (updating) are the key requirements you must implement.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
Jason Marshall
Greenhorn

Joined: Jul 17, 2006
Posts: 18
Thanks Roel,

But what is the point of this method in the DBAccess?

// Creates a new record in the database (possibly reusing a
// deleted entry). Inserts the given data, and returns the record
// number of the new record.
public long createRecord(String [] data)
throws DuplicateKeyException;

I'm confused, why would they put it in there if it wasn't meant to be used.

Cheers,

Jas
Jason Marshall
Greenhorn

Joined: Jul 17, 2006
Posts: 18
K. Tsang wrote:
Jason Marshall wrote:How do I open a new JPanel that exists within the same JFrame?


Hi Jason, how are you doing book or search? Are you using internal frame (like you are currently) or popup frame/dialog?

The idea should be the same. Creating or delete records is the least worry of the GUI. Searching and booking (updating) are the key requirements you must implement.


Thanks for your reply,

I'm using everything internally, once the JFrame Class is called all of the Panels, Menu's etc are instantiated.

I'm just not to sure how to open a new Panel to replace the existing panel so that I can add the new Room in.

I'm quite surprised that adding a new room is not a requirement as it is in the DBAccess Interface?

If this is not the case I suppose I'm just about home then

J
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5216
    
  12

Hi Jason,

I have implemented all methods from DBAccess (and even some own methods I needed) in my Data class: so I have in my Data class a create- (reusing deleted entries), update-, delete-, read-, find-, isLocked-, lock- and unlock-method.

I only used these methods in my program: find (look for rooms), read (read the rooms), update + isLocked + lock + unlock (book a room). So create- and delete-method are unused.

If you want to test your methods (see if implementation is ok and they act like they should) I would create a test-case (or test-program, something like Junit, TestNG). I even suggest this for all your methods, certainly for your Data class (it's the most important class you will create). I created a Data class test with 100% coverage (so each situation is tested, also those when you pass a wrong/illegal parameter). I have a 68 different tests (for just 11 methods ). The benefit of this approach: if you make some changes after a week to your Data class, you just run your test-case and you see immediately of those changes broke your existing code. And of course running just this test-case is a lot easier and faster than starting whole your application to see if an update was successful

But you don't have to use all methods from Data. I created a second find-method (returning record numbers + record data instead of just record numbers). And in my program I use that one instead of the one defined in Sun's interface.

[edit] don't forget to make a backup of your original database file (if you start updating, deleting,...) because you have to submit an original (unchanged) database file)

Kind regards,
Roel
Jason Marshall
Greenhorn

Joined: Jul 17, 2006
Posts: 18
Roel De Nijs wrote:Hi Jason,

I have implemented all methods from DBAccess (and even some own methods I needed) in my Data class: so I have in my Data class a create- (reusing deleted entries), update-, delete-, read-, find-, isLocked-, lock- and unlock-method.

I only used these methods in my program: find (look for rooms), read (read the rooms), update + isLocked + lock + unlock (book a room). So create- and delete-method are unused.

If you want to test your methods (see if implementation is ok and they act like they should) I would create a test-case (or test-program, something like Junit, TestNG). I even suggest this for all your methods, certainly for your Data class (it's the most important class you will create). I created a Data class test with 100% coverage (so each situation is tested, also those when you pass a wrong/illegal parameter). I have a 68 different tests (for just 11 methods ). The benefit of this approach: if you make some changes after a week to your Data class, you just run your test-case and you see immediately of those changes broke your existing code. And of course running just this test-case is a lot easier and faster than starting whole your application to see if an update was successful

But you don't have to use all methods from Data. I created a second find-method (returning record numbers + record data instead of just record numbers). And in my program I use that one instead of the one defined in Sun's interface.

[edit] don't forget to make a backup of your original database file (if you start updating, deleting,...) because you have to submit an original (unchanged) database file)

Kind regards,
Roel


WOW,

Thank you very much Roel. I think I have saved my original database File on gmail so I will retrieve it this way. I new that chances are one day that I would probably corrupt it. Here's me getting my Delete method perfect to find out that it's not used in the GUI along with the Add new record. Anyway at least I was learning.

I think I got your test classes about 6 months ago so your right it is a good idea to go over my data class again to check that I have not broken anything whilst building my Gui classes. Why did I think it was necessary to have this functionality in? I probably was not reading the doc file correctly.

If you could answer three quick questions for me?

1. When reserving a room the user/operator only needs to have an edit field on the rooms row where they can add in the owners name to reserve the room?
2. Do I need to edit the other fields in the row such as Date and Smoking?
3. A little bit ff topic, I heard that Java where setting a year's time limit to do the assignment, I downloaded mine about 3 years ago opps will this affect me?

Thanks for your help, much appreciated.

Jas
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2379
    
    7

Hi Jason,

For your questions, ideally you just need to enter the customer ID (owner field) which is 8-digit string, not the customer name like you said. All other fields don't need to change, but if you want you can change the date to the check-in date (ie 2 days from today satisfying that 48 hour rule).

Don't worry if you worked on the assignment more than one year, I think the one-year period applies to new candidates.

Also when you do submit, you need to submit the original database file that came with your assignment (no new records, no deleted records, no changed fields).
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5216
    
  12

Hi Jason,

You have to make sure your delete and create method work perfect, because I guess they will be tested. So it's certainly not wasted time. If you want to take a risk (and have enough money) you could try to throw an UnsupportedOperationException from any method that's not used in your program. Argumenting it in your choices.txt the implentations will be handled when they are needed in the gui. And see if you can pass with such an approach

I didn't post my full coverage Data class test-case, because it's specially made for my interface and would take to much time to adjust on another interface, so it's faster to write your own from scratch.

Quick answers on your questions:
1. when room is booked, i open dialog with all fields (showing hotel room info) disabled except for the customer-id. user can enter only customer-id and confirm/cancel booking. dialog could also be reused for in future releases (creating, deleting, unbooking,...)
2. No, not required
3. I had my assignment from April-May 2007, submitted 2 years later and I had not a problem at all.

Kind regards,
Roel
Jason Marshall
Greenhorn

Joined: Jul 17, 2006
Posts: 18
K. Tsang wrote:Hi Jason,

For your questions, ideally you just need to enter the customer ID (owner field) which is 8-digit string, not the customer name like you said. All other fields don't need to change, but if you want you can change the date to the check-in date (ie 2 days from today satisfying that 48 hour rule).

Don't worry if you worked on the assignment more than one year, I think the one-year period applies to new candidates.

Also when you do submit, you need to submit the original database file that came with your assignment (no new records, no deleted records, no changed fields).


Thanks K. Tsang and Roel,

You two have helped me out a lot. I'll let you know how I go with my marks in a few months time.

Cheers..

Jas
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Add New Record - Problem with GUI and JPanels