Can Zheng

+ Follow
since Jul 15, 2006
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Can Zheng

Hi Micheal,

I have this JTextfield which accepts only 6-character ID, so I preset it with something like 000000, and then treat every input as a replace(i.e overwrite the character at the caret position). I did all the above by overiding the insertstring in the textfield's document class. The problem is when the user can select some text, he can delete it or directly type something to replace the selected part. I know I can override delete() in the document class to prevent that, but with selection enabled but deleting and overwriting disabled is quite unintuitive to me. So I'd like to disable selection as well.

Any hints?

17 years ago
Hi Micheal, thanks for your help.

Well I guess I've made a mistake by adding "by mouse" in the previous post. Actually I wanna prevent any operation which can select part of or the whole text. By not adding a motion listener we prevent mouse to do it but still we can use shift and arrow key to select it. Is there any other way to do it?

17 years ago
Hi ranchers,

I am doing the URLyBird assignment and I wanna use a JTextfield for the customer ID input. For some user experience related reason I wanna prevent the user from selecting text in this JTextField control. But how can I achieve this?
[ August 16, 2006: Message edited by: Can Zheng ]
17 years ago
Hi ranchers,

I have a JTextField in which I wanna prevent the user from selecting text. How do I achieve this? Thanks!
[ August 16, 2006: Message edited by: Can Zheng ]
17 years ago
Thanks Jeroen and Mihai, but I still can not get the reason. Please help me clarify it a bit more.

Hi Jeroen,

it's a checked exception. Checked exceptions need to be either caught or thrown from a method where they can result.

Well, IMHO java.lang.SecurityException extends java.lang.RuntimeException so that it's not a checked exception. Is this SecurityException we are allowed to throw?

and Mihai,

I understand that we need to consider that there are other clients running, but nevertheless, what I insisted is that in my application, a client will always lock before he can update or unlock, and this lock op by its definition should block until a lock is obtained and it never throw SecurityException. So I don't see the reason that considering other clients and even other client apps would change the logic, and thus require this exception be taken care of.
Thanks Mihai,

Yup your suggestion is exactly what I meant. After using a layout manager I still need to hard code the components prefered/minimum/maximum size in many cases, and I'm quite uncomfortable with that. Is there a way we can get the UI code cleaner?
Hi Mihai,

Your point is of course correct, but maybe I need to make my question a bit clearer.

My concern is, since the client only makes use of update() and unlock(), which potentially throws SecurityException, in the book() method, and the business logic would never result in the SecurityException being thrown. So why do we need to catch it?

Am I missing anything here?
Hi ranchers?

I'm doing the URLyBird assignment and get stuck in the exception handling logic. Hope someone can help me.

The problem is, although in the db interface a SecurityException might be thrown when the cookie provided in delete(), update() or unlock() is not the original cookie returned when calling lock() on the record, it is not possible to happen in my application, unless there is an error in the code. That's because my client code only use lock cookie in the book method which calls lock(), update(), unlock() sequentially and providing a wrong cookie is something not supposed to happen.

So do I still need to take care of SecurityException thrown from these methods? Or simply let it go. I know a RuntimeException can cause something terrible to happen, but this is what ought to happen when there is a mistake like this in the code, right?

Please point out if I missed anything here. Thanks!
Hi ranchers,

When designing and implementing GUI, how do you set the component sizes? At first I though it would be ok to go with not setting the size at all, but this "large enough to contain" logic resulted in resized components when I tried to change the labels of the buttons in runtime. So I think maybe I should set them to a certain value.

But how do you guys do it? Do you hard code the component size, and is it ok?

Hi Micheal, thanks for your advice.

But I still don't understand why can't we use JFormattedTextField with NumberFormatter? I thought deleting all the content could be a usual senario, right? Anyone can help?
17 years ago
Sorry to dig out this pretty old post. But I'm having exactly the same problem and can't work it out.

Anyone can shed some light on this?

17 years ago
Hi ranchers,

I'm doing the URLyBird assignment and there's a requirement that the configurations be saved in file and be consistent between runs of the app.

All this is pretty straight forward, but my question is do I need two separated properties for db file locations for standalone mode and server mode respectively?
Hi ranchers,

I'm doing my URLyBird assignment right now, and for the data access part I am required to implement add, delete, find and update operations. But I'm not sure which of these are used in which senarios at the client's perspective. (Of course I've implemented all of them at the data access tier, but how they are used is sort of important for me to design the client end.)

Let me state it more clearly, so my questions are:

1. Do clients(CSRs in my assignment) input records?
2. Do clients delete records? (I can't think of a reason why clients are allowed to delete records)
3. Or do they only make the booking?

And how do I reflect the booking made by the client? It seems we can do it by specifying the owner field of the record. If so, do I need to list the records already booked by a customer?

And how do I respect the 48 hours rule? I noticed there is a date field in the record. Does it mean only records with a date later than "48 hours prior to current time" is effective? Then I can delete all other records? The assignment did not make it clear but had it stated like the following:

They take bookings only within 48 hours of the start of room occupancy

I just don't have enough business knowledge to understand something like that...

Another question:
For my assignment, it stated that the fields in a record should be null terminated, but in the db file supplied it is always padded by 0x20(spaces). So do I conform to this convention or use null(0x00)?

Thanks a lot for anyone who's willing to share his/her opinions. You guys are all my hope
[ July 30, 2006: Message edited by: Can Zheng ]
Thanks, Jeroen. That helps a lot. Well I guess I'll buy the voucher for the written exam whenever I'm done with the assignment