D. Brown

Greenhorn
+ Follow
since Sep 20, 2012
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 D. Brown

Michael, thank you. This is very helpful.

Dave
9 years ago
Michael, this does run the way I want it to. Thanks. I'm still studying it to understand how it works. (I'm pretty new at this.)

I'm also still wondering two things. Why would the program behave differently if it was compiled using NetBeans vs. with Eclipse? And, why would the program run with flipper=true, but not run with flipper=false? If I come to understand your version of the program, I don't need the answers to these questions, but I am curious about them.

Thanks,
Dave

9 years ago
Ok, so I read the tutorial on "Concurrency in Swing." Also the prerequisite tutorials, "Concurrency." I'm not sure I quite ever found a sentence that said, "Your program won't work because..." but I see that if I want anything to change in Swing, say with an animation, I will need to run it in a thread. So I now have a thread for calculating prime numbers and appending them to the JTextArea. But there are some strange things happening with it.

!. If I initialize boolean variable flipper as "true," the program launches, calculating primes right out of the gate. But I want the user to start with flipper = false, so that the user will start the program generating primes by clicking on the JButton. But if I initialize flipper as "false," I don't see any primes being generated. I can't figure out why not.

2. If I compile the program in Eclipse, it runs OK. If I click on the button, the generation of prime numbers stops until I click the button again. Then the process picks up where it left off. That's what I want. But if I compile the program in NetBeans, I get a different behavior. If I stop the generation of prime, it cannot be resumed. Both are using the same JDK. Why would it be different between the two?

3. In the South Region, the line .setAlignmentX(Component.RIGHT_ALIGNMENT) for the button and the label seems to produce a left alignment, but setAlignmentX(Component.RIGHT_ALIGNMENT) seems to produce left alignment.

Any insight is appreciated!

Here's my code:

9 years ago
BTW -- I've been wondering. What is the reference to "OP?"

Thanks.
9 years ago
Thanks, to all. Yes, I'm looking for insight as opposed to being given the solution. And it's still not clear to me why my approach doesn't work. The numbers advance correctly with each pair of mouse clicks, but I don't see why the loop won't continue to append new numbers without the clicks.

Thanks for any explanations.

9 years ago
Jeyram, thanks. But why wouldn't my code work?
9 years ago
As an exercise, I am writing a program that continuously generates prime numbers. There is a button on the GUI to (hopefully) start and stop the process. When the numbers are being generated, they are to continuously append to a JTextArea in the center region of Border Layout. I have created the outline, but have not yet entered the algorithm to find the prime numbers. (I have a command-line model that works. But I want it in a GUI.) Instead, for developmental purposes, I have nested loops that advance integers: 1, 2, 3, etc. -- In place of the prime numbers. Same concept, though, as far as writing to the JTextArea goes.

Here is my problem. When I click the button, the number advances by one, then waits for the next click. The next two clicks advance the number, but only by one more. (The idea should be that one click should stop it and the next click resume. Hence the two clicks to advance one number.) I thought the loops would let it continue to append numbers until I click to stop it, but that's not what happens. So -- have I done something incorrectly, or is there some characteristic of the loops I've used or JTextArea that is keeping me from getting what I envision? Here is my code:

9 years ago
That was interesting reading. I'm still digesting it. I think I get the heavyweight/lightweight business now, and how it's causing the problem.
9 years ago
That should be, call to updateUI(), not call to update().
9 years ago
I did my best to trim the code down and do the SSCCE thing. Below are the DiceRoller (main) class and the Roll Dice class. I have also attached one graphic image of a die. I guess you can copy it 5 times and name the new files "two.jpg" etc.

There are still two calls to update(), but they're commented out.

While trimming the code down and making sure it would still compile, I ran into something interesting. When I removed the scroll area from the center region, the problem went away. When I put the scroll area back in, the problem re-appeared. Why would that happen??

The teacher for the class I'm taking compiled the program on his computer, and he did not see the problem. I think he's using a Mac.

When I first start the program, I can get to File | Exit ok. After the first dice roll, I can get to File, but Exit is gone.

All insight is appreciated.

I tried to attach the source as files. But I got a scolding from the forum program, first saying that I couldn't attach files with extension .java, and then that I couldn't attach files with an extension .txt. I couldn't find anything about this in a FAQ, but I concluded that source should be posted in the message. So it's below.

Dave

==============DiceRoller.java==============




9 years ago
Ok, this takes care of it:

menuBar.updateUI();

Is that the best solution?
9 years ago
I have written a dice roller program with "File" and "Help" menus. The File menu has "New Game" and "Exit" menu items. When the program first starts, I can click on "File" and see the "New Game" and "Exit" menu items, but after the first dice roll, I can't see the "Exit" menu item any more. I'm guessing that the repaint() call has done something to cover it up. The accelerator keys still work.

Does this problem sound familiar? I can't find any obvious refernce to it when I Google or search this site. I can post code if necessary.

I have tried this with same result with:

Eclipse Juno, Linux Iced Tea 1.6
Eclipse Helios, Linux Iced Tea 1.6
Eclipse Juno Windows 32 (Vista), Java 1.7

Thanks for any advice.

9 years ago