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
edit
1. Does your code respect Swing's single threaded rule?
2. does your GUI mix AWT and Swing components?
luck, db
There are no new questions, but there may be new answers.
D. Brown
Greenhorn
Joined: Sep 20, 2012
Posts: 12
posted
0
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==============
D. Brown
Greenhorn
Joined: Sep 20, 2012
Posts: 12
posted
0
That should be, call to updateUI(), not call to update().
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
as Darryl hinted/suggested, the problem is this line
1. there no reason to use AWT Canvas (excluding for Multimedia, OpenGL/CL, or there are a few good 3rd party libraries based on AWT)
2. AWT Canvas is heavyweight Component, then is basically always on top of lightweight JMenu & JMenuItem, have to change lightweight status for Swing JComponents (I'd not suggest)
3. put Icon /ImageIcon to the JLabel , for dices could be JButton the best of ways (layed by GridLayout)
4. in the case that you want to use painting then to change Canvas to the JPanel or JComponent, have to override PreferredSize for resizable contents
D. Brown
Greenhorn
Joined: Sep 20, 2012
Posts: 12
posted
0
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.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.