This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.

Chris Waguespack

Ranch Hand
+ Follow
since Jul 26, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Chris Waguespack

I'm developing an application with Swing and had some questions about the correct way to use actions/listeners in multiple files. I have a main GUI class with a menu bar/menu items and each menu item has an action. The actions are in their own classes. I also have a class that extends JInternalFrame to use with the application's desktop pane. When a JInternalFrame is activated, I want the main GUI's menu bar->boldCheckBoxMenuItem's enabled property to be updated based on the state of the internal frame's text area. Code attached below.
I know some of these topics have been discussed in the forums, but I'm having trouble figuring out how to adapt the information for my application.
First question: What is the ideal way to let actions access the main GUI? Should you pass the GUI instance as a parameter in the action's constructor?
Second question: When an internal frame is activated, how do I access a menu item from the main GUI's menu bar? Should you pass the GUI instance as a parameter in the frame's constructor?

Thanks for your help. If you need any more information, please let me know.



12 years ago
Hello Mac, and welcome to JavaRanch. I'm having trouble understanding what problems you're having; could you give a description of either the error or incorrect result you're getting? Also, you can use the code tags to make your code easier to read.

- Chris
12 years ago
Ah! Thank you! I can't believe I didn't spot that earlier.

Rob Spoor wrote:I would like to make one other improvement though:
If you leave out the ? super part you will only allow types that are comparable to objects of the exact same type. java.lang.Timestamp could not be used though, as it does not implement Comparable<Timestamp> but through inheritance Comparable<Date>. The ? super part makes sure that classes like Timestamp can also be used.


Ok, I remember seeing something like that in the tutorial, but I couldn't figure out exactly why it was needed. Thank you for clearing this up for me.
12 years ago
Hello everyone. It's been a while since I've been to the forums, but I have a problem I just can't figure out.

I'm trying to implement a node for a tree-based data structure (just a binary search tree to start with), and I want this node to have a key that is comparable. I would also like the node to be comparable, using its key to determine the result. My problem deals with combining generics and the comparable interface (mainly my lack of experience using them :P). Please see the code below (constructors/getters/setters omitted).

When I try to run this, it says "The type BSTNode<K> must implement the inherited abstract method Comparable<BSTNode>.compareTo(BSTNode)" and "The method compareTo(BSTNode<K>) of type BSTNode<K> must override or implement a supertype method".
If I remove the "<K>" from the method's parameter type, those errors go away, but I'm given the error "The method compareTo(K) in the type Comparable<K> is not applicable for the arguments (Comparable)". When I look at the return type for getKey(), this.getKey() returns K, while node.getKey() returns Comparable. I know this has something to do with how generics work, but I still can't figure it out, even after reading Oracle's generics tutorial.

So, after all that, my questions are:
First, am I even doing this right for what I want to accomplish?
Second, is there a better way of doing this?
Third, if I am doing this correctly, how do I fix my errors?

Thank you for help!

12 years ago
Thanks...I can never find the right combination of words to search with...yet I manage to find them for a post title..sigh. Thanks again, good information.

- Chris
16 years ago
After skimming the web and the forums,I can't seem to find a good way to accomplish this. I'm using InputVerifiers to check text box inputs, and when the input is not valid, I would like the tool tip for that text box to appear. Is there a way to do this?

Thanks again,
Chris
16 years ago
Ah, thank you! That works nicely. Even after pouring over a lot of tutorials and javadocs, I still can't find the correct times to use repaint(), validate(), invalidate(), and revalidate()...does anyone know of a good resource that explains this in an easy to understand way?

Thanks a lot,
Chris

16 years ago
Alright lets see...

First I remove the last item from the panel..
DOH!!
Ok, I need to remove the component not the index-based component.


Then I check to see if the list has any items left in it.
If it does, I modify the constraints, then remove and re-add the component with the new constraints.
When jScrollPane.revalidate() is called, the screen is not repainted.

Thanks again,
Chris
16 years ago
After reading some other posts, I understand that using System.exit() is not the preferable way to exit an application, but instead I should use a RuntimeException (I think?). Could anyone provide some more information on this, and why System.exit() should not be used (both in cases where the application is told by the user to exit and when the application needs to terminate immediately).

Thanks,
Chris
16 years ago
I believe you are talking about the lack of isEmpty() checking. I know it needs to be there, just didn't add it for this simplistic example. Am I missing something else?
16 years ago
In the case I'm working with, the ElectricalSystem would need to know about the House.

Originally posted by manuel aldana:
if so, i would rather extract this House behaviour by an interface to avoid circular dependency.



I'm unsure exactly what you mean by this; could you explain this further?

Thanks,
Chris
I have a JPanel inside of a JScrollPane that contains objects when you click the add button and deletes them when you click the delete button. Doing an add updates the screen, but a delete does not. Can anyone figure out what's going on?



16 years ago
I have a question about how to use composition while avoiding circular dependency. I ran FindBugs (thanks Pat ) and found that I have some in my design and was wondering about the best way to take care of them. If you have, lets say, a House, and that House has an ElectricalSystem, then you would expect the House class to have an ElectricalSystem property. But, if that ElectricalSystem is specific to only that house, you would have a two-way association (1 to 1). In that case the ElectricalSystem class would need a House property (problem!) to create this association.

Am I wrong with this assumption and is there a way around this?

Thanks,
Chris
Thanks for all the help! Though this brings me to another question; if you have a GUI application, should a quit menu option directly call System.exit(0); or is there a better way to handle this?

Thanks again,
Chris

Edit: I think I figured out a correct approach. System.exit(); can be called if the application is exiting safely, as requested by the user. throw new RuntimeException(); should be used if an error occurs and the application needs to exit. Sound about right?
[ May 19, 2008: Message edited by: Chris Waguespack ]
16 years ago
Thanks everyone. So basically assertions should only be used while developing/debugging your application...yeah I guess that makes sense since assertions are disabled by default.

- Chris
16 years ago