aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes applet gui issues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "applet gui issues" Watch "applet gui issues" New topic
Author

applet gui issues

Matthew Helling
Greenhorn

Joined: Mar 18, 2004
Posts: 17
Hi folks
I'm a bit new to Java (having coded in C, VB, perl and others) and I'm trying to write an app for work (I'm not a fulltime coder, this is just an "itch" that needs scratching).
Here's my issues, perhaps folks can help.
my import statements are
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
I know swing exists, but my only java book doesn't cover swing (its an old book). If y'all tell me I can't get help with awt, thats cool, I guess I'll spring for a new book.
the app is one where I have a series of checkboxes (with listener events) and as boxes are selected/deselected, other options appear/disappear. The checkboxes are used to narrow down product selection. Kind of like, if you check the box for "push mower" it will make all the riding mowers disappear.
The issues i'm having are
1- my checkboxes don't immediately work. I have to check a box, uncheck it, and then on the second time I put a check in it will "activate" the code.
2- I'm having trouble getting multiple boxes to work in conjunction. For example, if you check the box for "push mower", then check the box for "Snapper (a mower brand)" it will properly narrow down the choices. But if you uncheck "push mower", it comes back along and re-displays ALL non-push mowers, Snapper or otherwise.
Is it kosher to post the whole code up here? I want to provide enough information for a bit of help, but not take up too much space.
Thanks for any help you can give me. I'll check back here on the morrow. If anyone can be of assistance I'd greatly appreciate it
Matt
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8968
    
    9

Originally posted by Matthew Helling:
If y'all tell me I can't get help with awt, thats cool, I guess I'll spring for a new book.

We can help you with pretty much anything. One resource you'll want to look at is the Java Tutorial. Up-to-date examples of Swing and more.

1- my checkboxes don't immediately work. I have to check a box, uncheck it, and then on the second time I put a check in it will "activate" the code.

That's weird. Maybe the logic that keeps the state of your program (i.e. what fields are selected and how to sort the mowers) is fragmented so it takes a couple of tries to get the right combination.

2- I'm having trouble getting multiple boxes to work in conjunction. For example, if you check the box for "push mower", then check the box for "Snapper (a mower brand)" it will properly narrow down the choices. But if you uncheck "push mower", it comes back along and re-displays ALL non-push mowers, Snapper or otherwise.

Sounds like the logic that handles an un-select just repopulates the list rather than taking into account other fields that are selected.

Is it kosher to post the whole code up here?

Absolutely. Make sure you use the UUB Code "CODE" tags (see the buttons below the message edit window) to preserve your code's formatting.


[How To Ask Questions On JavaRanch]
Brian Pipa
Ranch Hand

Joined: Sep 29, 2003
Posts: 299

I know swing exists, but my only java book doesn't cover swing (its an old book). If y'all tell me I can't get help with awt, thats cool, I guess I'll spring for a new book.

You don't need a book - you have the world-wide web! There are plenty of tutorials online and there are even a fair amount of free PDF books available online if you do need a book.
Unless you have a limitation/requirement we don't know about, I would definitely switch to Swing if I were you. It's much better and more full-featured than AWT.
brian


My Java Freeware:<br />MACCC - <a href="http://maccc.pipasoft.com" target="_blank" rel="nofollow">http://maccc.pipasoft.com</a><br />Nator - <a href="http://nator.pipasoft.com" target="_blank" rel="nofollow">http://nator.pipasoft.com</a>
Matthew Helling
Greenhorn

Joined: Mar 18, 2004
Posts: 17
Ok, here's the code. I'd appreciate any help you can offer. Warning- its incredibly messy. Because I'm coding this in "offtime" and "on the side" i use comments to hold snippets of code rather than my memory, which is weak. You'll see a ton of code snips that are commented out, its because I'm using them as a reference for how to do things.



(I edited the code so it doesn't widen the page. - Nathan Pruett)
[ March 19, 2004: Message edited by: Nathan Pruett ]
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Actually, if you are actually trying to do this as an applet because you want it to run as an applet ( and not just doing this as an applet because your book is old and applets were cool back then and they did everything as an applet) it might be better to do as AWT. If you do applets using Swing, you have to have the Java plugin to run it. (This is due to IE using the Microsoft VM, which is kinda old). Swing is a lot nicer, though, and if you want to run as a desktop application (or don't care either way) you can do more. On the other hand, AWT is a lot simpler to learn, but may not provide enough to do more complicated programs.

I'll assume you actually want to do this as an applet, and use AWT. This type of data filtering is actually easier to do using a database and using modifiable SELECT...WHERE statements... as you can see, the filtering gets pretty involved. Another option would be to not label the fields of the Server object, but just use an array of booleans. This would be easier in this case, but it wouldn't model your data well as objects, and makes it confusing if you wanted to use your Server objects somewhere else.

Anyway, on to the code -



-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Matthew Helling
Greenhorn

Joined: Mar 18, 2004
Posts: 17
Nate
I'll have to sit and digest the code you put in there for me. I appreciate the time you spent to help me.
You are correct, i want this to run as an applet because it'll be used by people all over the country and is a bit of a "work in progress" in that it'll be updated every few weeks and I don't want the hassle of different versions of the program "in the wild".
after I go over things I'll probably have another question or two
Matt
Matthew Helling
Greenhorn

Joined: Mar 18, 2004
Posts: 17
Nate!
I copied your code into textpad and compiled it. This is *MUCH* closer to my goal. Thank you so much for helping with this.
I have a couple other questions but they aren't gui related, so I don't want to bother you if its not your area of expertise
Matt
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Ask away! Since the code is already in this post, questions about it would probably make more sense here, and if something is more appropriate in another forum I can always direct you there...

One thing I would like to suggest would be that it seems like this applet would work much better if it used either a database or XML to hold the data for the servers. I made the Server class mostly to just illustrate how the Applet would work. In this case, at startup the applet would either read from the database or parse the XML files to populate the list and produce all the possible options. In this case, the Server class probably wouldn't have specific methods to get the attributes, it would just wrap a Hashtable and would return a default value if the attribute requested wasn't set for that specific server type. If you expect the values not to change much, it would be better to store these objects in the applet and just use them for the tests. If the data was seen as something that would be changing faster, then you would need to go back to the data itself and do the test every time. In your case, you sould probably just read the data at startup and use the objects created from then on.
Matthew Helling
Greenhorn

Joined: Mar 18, 2004
Posts: 17
Nate
I went ahead and extended the applet aways with more checkboxes and extension to the server class. I'm ok with just doing everything inside the applet, it cuts down on how many files have to be posted/distributed.
Ok, so questions
1- I want to add a "recommendations" text box that automatically fills in recommendations as the various options are checked.
2- after a configuration is made, how hard would it be to save it? Can I have a txt file that would store a quote number followed by the true/false of each checkbox. I know java has quite a bite of "sandboxing" built in.
3- same question, but instead of saving it, emailing it.
4- a warning box. This should be relatively easy I'd think. I was thinking if you select a configuration that isn't recommended it changes the background color of the List to Red.
5- disabling checkboxes. I was thinking there should be something like setState.Disabled. Something where it would gray out options that are no longer possible
Thanks again for pushing me in the right direction
Matt
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Originally posted by Matthew Helling:

I went ahead and extended the applet aways with more checkboxes and extension to the server class. I'm ok with just doing everything inside the applet, it cuts down on how many files have to be posted/distributed.

It's fine if you want to embed everything in the applet if the data isn't going to change. If you keep the data separate, though, you won't have to create a new version of the applet every time the data changes.

1- I want to add a "recommendations" text box that automatically fills in recommendations as the various options are checked.


Not sure what you mean by "recommendations"... what sort of data are you planning for this text box to hold?


2- after a configuration is made, how hard would it be to save it? Can I have a txt file that would store a quote number followed by the true/false of each checkbox. I know java has quite a bite of "sandboxing" built in.
3- same question, but instead of saving it, emailing it.


For both of these, you would need a servlet (or some similiar program) running on the web server. The applet actually runs on the client machine, only it's code is downloaded by the browser from your site. Unless you go to a lot of trouble and expense to make a signed "trusted" applet, you won't be able to save a text file on the users computer. (You *could* open a stream to another program running on your server, have it write a file on the server, then redirect the user to that file. However, it would still require the user to download the file themselves, and your server would slowly fill up with these files.) Email is the same, you'd have to send the data to another process running on your server and have it email the data to the user.


4- a warning box. This should be relatively easy I'd think. I was thinking if you select a configuration that isn't recommended it changes the background color of the List to Red.


Take a look at the Dialog class for the warning box. And you could just use setBackground( Color.red ) on the list to make it red.


5- disabling checkboxes. I was thinking there should be something like setState.Disabled. Something where it would gray out options that are no longer possible

That method is setEnabled( false )
Matthew Helling
Greenhorn

Joined: Mar 18, 2004
Posts: 17
Thanks again Nate
I'll hit things tonite and show you what it looks like in a bit.
About the recommendations. I was thinking of adjusting the gui so that the right hand side was split into two panes, upper and lower. The upper pane would be the list of systems (as it is now) and the lower pane would be 5 different labels. For example
If the user selects 1000 users and email, we would want to recommend fairly large storage capacity. Something like that.
I'll finish the applet in pure applet form first, then I'll worry about streams/emails etc. In my design specs that's part of phase 2 anyway. Phase 1 is internal use only, and I don't need email for that.
Matt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: applet gui issues