David Nemeskey

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

Recent posts by David Nemeskey

Yes, that is what I am doing now, but it is not robust enough. What if a system uses a different enconding, where (int)'N' != VK_N?
15 years ago
Thanks for your answer, but I already know that.

What I would like to know, if I have a character, like 'N', how do I get its key code; that is, KeyEvent.VK_N. I don't know the character at compile-time; it is read from a file, so the code has to be generic. It should be without any ASCII magic, only by calling API methods.
15 years ago
Yes, but it expects a key code, one of the KeyEvent.VK_XX constants, and not a character, as 'A'.

Of course, I can assume that (int)'A' == 65 == KeyEvent.VK_A, and that is what I am doing now, but that is not very robust, is it? What I am looking for is an API way that can "translate" 'A' to VK_A.
[ July 10, 2008: Message edited by: David Nemeskey ]
15 years ago
Hi,

I have a problem regarding mnemonics. I would like to add mnemonics to a subclass of AbstractAction. However, I am using a resource bundle, and the action text differs in different languages. Some titles don't even have common letters, so I put the mnemonics to the resource bundle too.

Now my problem is that there seems to be no method that accepts characters as mnemonics. Even worse, I can't seem to find a method that accepts a character and returns the corresponding KeyEvent keycode! I tried

, but it returned 0, as the KEY_TYPED and the KEY_PRESSED, KEY_RELEASED events are entirely separated in the API.

I know I could just assume that VK_A = 65 (ASCII value), and so on, but it isn't very robust...
15 years ago
Hi,

I would like to have an architecture where certain threads (and threads created by them) cannot access other threads and thread groups outside their own. More specifically, if I have thread A in thread group AG, the thread should be able to create thread groups A1G, A2G... if those are children of AG. It should also be able to create threads in them. However, it should not be able to access any other thread groups.

I figured I would create a CustomThreadGroup class for AG, and use a SecurityManager to check permissions. The overwritten checkaccess method looks like this:

, where getCustomAncestor returns the uppermost CustomThreadGroup in the thread group tree (or null).

The problem with this is, that in getCustomAncestor, I have to call the getParent() method of the thread group. This, however, results in another checkAccess() call, and that in another getCustomAncestor, resulting in a StackOverflowError.

My question would be:
How to prevent the recursivity? I thought about creating a thread in the SecurityManager (private Thread class), that can access both groups, but isn't it an overkill to such a problem? Isn't there a simpler (API) way?

Thanks,
David
[ June 15, 2008: Message edited by: David Nemeskey ]
15 years ago



Compiles but it is a bad programming practice because you use a Lock object as a monitor and javadoc of Lock class prevents it because generates confusion.



Actually, no; he uses a simple Object, just calls it "lock" It is not a bad programming practice because of that; it is bad because it simply does not work. The Object on which the code synchronizes is created in the method itself. So two parallel calls to the method "synchronize" on two different objects, meaning there will be no synchronization at all. I guess you meant



, which is exactly the same as synchronized (this).

Anyway, I have a requirement, that states threads should not consume CPU while they are idle, and that can only be satisfied by one lock for each record. So I use a synchronized block to access the lock map, and then with hand-in-hand locking, lock the ReentrantLock object in the map. In other words, I did not really choose between the two
Hi,

I am doing the URLyBird assignment right now, and I have these instructions:

"All configuration must be done via a GUI, and must be persistent between runs of the program. Such configuration information must be stored in a file called suncertify.properties which must be located in the current working directory."

and

..."you must provide either a single plain ASCII (not word processor format) text document, which must be called userguide.txt"...

Now, if I understood correctly, the "working directory" is from where the java -jar ... command is executed. So that means if my jar is in directory X, and the user starts it from directory Y, then the "working directory" is Y. Am I right on this?

However, I do not really know what they will do with the userguide.txt file. I have to include it beside the jar, but can I make any assumptions about where it will be when my application is run? Can I assume that it will be in the same directory as the jar? I am asking this because I plan to make it available from the GUI as well (display it in a JTextArea).

Assuming the file will be in the same directory as the jar file, I still have to know which directory it is. Is there a way to determine in what directory the jar file is? new File(".") returns the working directory, so that does not work. I have had a look at the system properties, and I have found that "java.class.path" is always the path of my jar file. Can I depend on it being always so? At least -- can I assume that (if there are other files/directories there; even if I could not "add" anything there, even by using the -cp option) my jar file is always in it, and preferrable in the first place?

I was also thinking about including the file in the jar as well. Though it would be duplication, it is possibly not a big deal. What do you think?

Thanks,
David
Hi,

I have a problem regarding the order of JFrame events.

I am using a frame, which can be closed. I want to achieve that on next reopening, it appears in the same place and in the same size as it was before it was closed. So I save its state, location and size.

The problem is the next: if it was maximized when it was closed, how can I save the non-maximized bounds? I managed to do it with the size, but I find it difficult for location. Why? It is because the order I receive the events:
1. Move (ComponentListener.componentMoved)
2. Maximize (WindowStateListener.windowStateChanged)
3. Resize (ComponentListener.componentResized)

So I can check in resize if the frame is maximized, and if not, I do not save the new size. However, move comes before maximize, so that does not work here. Two question comes to mind:
1. Why isn't the maximized event the first ("cause" of the others), or the last (the "consequence")? It doesn't really make sense...
2. Is the above order fixed across platforms, LaFs, etc? Because I can make a solution for this order, but if under say, Linux (the above was observed on Windows), the order is different, I am beat.

Or is there some other way to save the problem?

Thanks,
David
16 years ago
Hi,

I have come across a strange error while using generics. I want to overwrite outerMethod() in the subclasses, and I want to use the type safety provided by generics. There is a sample static subclass called aptly sample. Is there a way to achieve the differently?



The error message I get is a bit absurd... and not helpful at all.


I can change the code, and that solves the problem, but isn't there a better solution?

16 years ago
Hi,

I have a problem in my application with focus handling. I am using a glass pane to prevent the user from interact with data while a lengthy process is running. So far, so good. However, if the process fails, I would like to display a warning dialog via JOptionPane.showMessageDialog.

My problem is, that the "Ok" button in the dialog is not focused. Pressing TAB works, but quite strangely: the button is focused, and if I reproduce the situation, the next time it is focused. Then it is not on the next time, etc.

Here is the code that sets the glass pane:

Initial settings for the glass pane:


How I use it before the long process runs:


The long process shows the message roughly like this:


It seems that the problem is the line getGlassPane().requestFocusInWindow(); But I have to give it the focus, so that the user cannot use the keys to meddle with the data when he should not.

How can I solve this problem?

Thanks,
David
[ May 03, 2007: Message edited by: David Nemeskey ]
16 years ago
Edward Harned: thanks for the answer. Too bad; I think this is a serious feature hole in RMI, then.

Mr. C Lamont Gilbert: As I said in the topic starter, I unexported both. And I think nothing is listening, just the "RMI Accept-Xxxx" threads are running (and who knows what other resources RMI needs). Unfortunately it seems that there is no way to write a flexible RMI server (with reconfigurable ports). Or, rather, not this way.

For reference, here is the code. Never mind the method indices, I had some others as well to test it

[ April 26, 2007: Message edited by: David Nemeskey ]
16 years ago
I was thinking about this:

All dialogs are modal. Each showXxxDialog method blocks the
current thread until the user's interaction is complete.

However, if the current thread is the event dispatch thread, then it is
not blocked but sent to keep pumping events until the dialog is closed.


I took this as "it does not block the EDT, but when I tried to call it from other threads, those were".

Of course, you are right that this does not mean that it is thread-safe. And indeed it is not: I took a look at the code, and nowhere does it call invokeLater/Wait, or check which thread it is running on.

But the second question still remains: if I read something in javadoc (where there is no might/may), can I expect it to work the same way on all JDKs? How "trustworthy" is the JDK in implementation details?
16 years ago
Hello,

I am curious what is the "standard" way to use ResourceBundles. I am creating a GUI application right now, and I came up with the following. There are two problems: access (1) and usage (2):

1:
The javadoc says that ResourceBundles MIGHT be cached. As it turns out, the Sun implementation IS cached, but it is not obligatory. So creating it each time with getBundle() may lead to problems.

It can be created once, and passed around as parameters. But I don't know if it is a good idea to put it into the API everywhere like this.

I can make it static / use a singleton. It only allows for 1 Locale at a time, but it is okay for me now. But there may be a problem if it cannot be instantiated (no bundles exist, etc).

2:
Then there is the problem of MissingResourceException: it should be caught "just in case", but should I litter my code with try {} catch-es? I thought of subclassing it, but it is not possible due to the package-level access methods in ResourceBundle. So I thought of creating a wrapper object, which just returns the key or null if I call it with an invalid key. I think this makes the application more robust.

Thanks,
David
16 years ago
Hello,

I was just wondering if anybody knows. Is it safe to use the showXxxDialog methods of JOptionPane in a thread other than the EDT?

The API states that

All dialogs are modal. Each showXxxDialog method blocks the current thread until the user's interaction is complete.



Also, I have found this. The bug effectively states that JOptionPane does not block the EDT. Putting this together, I can only conclude that JOptionPane can be displayed from any thread, but it blocks the thread if it is not the EDT (which is fine by me).

What do you think? Even if the answer is "it is thread safe", can I depend on it on other JVMs, like IBM's? How "global" is javadoc? Is it only for Sun's JDK, or is it how each implementation should work?
16 years ago
Hello,

Do you know if there is a way to stop the RMI service on the server side programatically?

I started RMI by creating a Registry with LocateRegistry.createRegistry(). I traced the program with jconsole. It seems like whatever I do (unbinding the service, unexporting the exported service object, even unexporting the registry itself), the RMI Accept-<port> thread(s) don't stop. Do I have to exit the application to stop the RMI threads, or have I just missed something?
16 years ago