C. Alan

Ranch Hand
+ Follow
since Dec 17, 2004
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 C. Alan

I was thinking in addition to that, that since the read buffer was not being closed that the information was not being flushed from there... at least I think that is how I learned it.

Pardon me,.. I don't mean to be confusing the issues.
18 years ago
Could you be just a bit more specific about the problem you are having? My guess is that the information is not appearing in the file that you are writing to?

Which one line is working?
18 years ago
I am using the following code to send a text file to the printer:

The print project opens, and then it closes, but the file is not being printed... I know the file is being created properly, because I am dumping it to the desktop for verification purposes. What am I missing?
[ May 03, 2005: Message edited by: C. Alan ]
18 years ago
I know it's vague.. the idea was to get you started on your project, and then as you progress, we can help you work through different aspects.
18 years ago
Ok, I think I understand what you are trying to do... I'll start with some rough psuedocode and see if that helps you understand. (This is just how I would do it, and there are many different ways it can be done)



The actual code for dynamically creating buttons is not too hard... do the buttons need listeners?

The loop will look something like this:

Now, to create the panel, you just need a loop to extract the elements. Depending on which version of Java that you have, you will have to cast the button back when you want to add it to your panel or frame, ie:
myPanel.add((JButton)flightNumbers.get(i)
myPanel.add((JLabel)flightTimes.get(i)

Does that get you going a little?

[ April 28, 2005: Message edited by: C. Alan ]
[ April 28, 2005: Message edited by: C. Alan ]
18 years ago
I can probably get you a start, but I don't at all understand what you are trying to do. Are you trying to display labels and text fields dynamically?

From where are you retrieving the data?
18 years ago
I have a tough time remembering what goes with what also. Paint and repaint deal with the graphics class, so in your example, they won't do anything.

Validate makes sure that the component has a valid layout. The API's are a little vague on invalidate, but my assumption (probably incorrect) would be that it removes the layout of the component.

Revalidate, IIRC, has to do with handling component changes due to some kind of an event...as in a button says "on", and then when you click it, it says "off", etc.

Pack resizes your window to use each components preferred size. I think if you remove your validate and repaint statements, the frame should size properly so that your components fit.

I also find it useful when I get confused to use the glossary from here:
http://mindprod.com/jgloss/

It's interesting that you used show, and not set visible. I thought show was depricated, but I just discovered that JFrame inherits the show method of the Window class which is not deprecated..
18 years ago
I apologize for the duplicate post, but I figured out the solution to my own problem, which usuallly happens five minutes after I ask the question (even if I spet 6 hours trying to figure it out)

Anyway, I made some modifications:

Then in the listener:

Now I am able to get the index of the button pushed, and I can use the index to correlate to the proper account...woot!

It's not pretty, but it works.
18 years ago
I have an app that admittedly is homework, but it is not a requirement of the assignment. I have a radioButton group of accounts...simple enough, and we have five accounts. Since I like making things harder than they need to be, I decided to create the group dynamically (after all, at some point I might have more than 5 accounts). I also decided it should really be in a scroll panel also, otherwise there will be no room for expansion.

The code to create the button group is pretty trivial:

Basic listener code

I am stuck on the listener part....if I do a getText(), it returns the name of the last button added. I can do a buttonGroup.getSelection() which returns a unique value for each button, but I need to be able to either retrieve the position of the button within the group, or then text of the button to really do anything useful with it.

Anybody have an idea how I can accomplish this? There has to be a way to do it, I just can't see it.
[ March 20, 2005: Message edited by: C. Alan ]
18 years ago
In other words, you are looking for a project?

Umm... how about a java based Yatzee? Or a simple calculator, a do it yourself checkbook registry..... what are youn interested in? I am interested in computer forensics, so I created some small applications that help me with that (such as file comparison, hashing, etc.) I have gone through the questions, and picked up on projects others were doing for assignments.

Here are some sites that have projects (along with code):
http://www.ozersenturk.com/opp/default.asp?show=java
http://mindprod.com/projects/projects.html
http://courses.cs.vt.edu/~cs1054/fall2003/projects.html

A google search will turn up project ideas that are used for computer science classes. They may not be as cool as a dice game, but they usually teach some important concepts.

Good luck.
19 years ago

And they don't want people changing it at all.



Which is why Microsoft had to pay Sun $20 million..

http://java.sun.com/lawsuit/
19 years ago
This is probably stating the obvious, but have you already removed the directiories also? Uninstalling won't remove those, and I had that same problem when I tried to do a reinstall... I had forgotten to delete the directory.
19 years ago
Without knowing exactly what you want to do if there isn't an int in there,or how it is getting the input, you could do something like this:

That bit of codewill not even allow a char other than a digit to be entered. I borrowed it from Sun's website. If you want it to display a message, you could change the code to maybe something like this:

19 years ago
Without seeing exactly waht is going on, and not having your code in front of me, is there some other component that may somehow be interfering? I can't think of anything else right off hand, and I guess I can't think of ever having run into that particular problem before. I have had weird things happen with graphics when I tried to stuff them into a space where they wouldn't fit properly, and java resized them for me.

I know, not much help...sorry.
19 years ago
I don't know how much help this will be, but let's see if I understand your problem clearly before I make any suggestions.

The FileChooser only shows .jar files and directories...that much I understand. What you are saying is that if a user types in another file with a different extension, then it will go ahead and open the file, even if it isn't a .jar file? And you want only jar files selected??

I've been tinkering around with your problem for a little bit, and I only see two ways that you could accomplish this. One would be to make the text field non-editable. The other option would be to check the input, and if the extension didn't match what you wanted, then empty the textfield. The only problem with this is that I don't think one can directly act on the textfield in a filechooser. I seem to remember having run across that problem for an assignment once.

SO I really only see a couple of options. One, that you create your own filechooser class. Two, check the extension of the file entered, and if it doesn't match .jar, create a new FileChooser. The final option is to maybe extend fileChooser.... I'm seeing if that can be done because I never considered doing it that way.

One other question...you mentioned that you didn't want the file chooser to close unless a .jar file was selected. What happens if your user wants to back out of the filechooser without selecting a file at all?
19 years ago