I have 3 separate questions. I'm trying to develop a program that displays several vocabulary lists and has a row of buttons at the top for selecting the lists. These buttons don't appear until I re-size the window. Does anyone know why this occurs? Second, I've extended the JPanel class to implement the Mouse Listener event listener. The main class declaration, which extends the JFrame class, implements an Action Listener. Is there any way to implement both listeners in the main class declaration? Third and finally, I've attempted to draw a test string on an extension of a JPanel, but nothing shows up. Again, what am I doing wrong? I've attached the appropriate .java file if you need it, rather than just waste a bunch of space on this thread with my code. Any help would be greatly appreciated.

Recommended Answers

All 5 Replies

(1) The buttons show up in my machine (JDK 1.6). So it seems to be some problem with your machine. You may use Button of AWT rather than JButton of swing which is a lightweight component and does not show up among any AWT stuff. However, your case is OK. Since you put all the buttons into one separated container so that no conflict occurs, and even JButton shoud show up. If you simply put a JButton into a canvas (e.g. Applet) it wouldn't show up.
(2) You did not set up Layout manager correctly. I modified your code with BorderLayout. It works. (See attached file)
(3) Should we call the class ClickyLatinHelp as a driver class rather then "main class" ? One class may implement several interfaces. Since ActionListener and MouseListener both are interfaces the driver class may implement both.
I am noticed that :
Your code:

if (showeng = true) {
				showeng = false;
			}else {
				showeng = true;
			}
		}

is not correct. It should be if (showeng == true)... rather than if (showeng=true)

First thing: setVisible AFTER the GUI has been built.


Another way to toggle a boolean is to set it to its ! value;
showeng = !showeng; // toggle flag

A class can implement many interfaces.
this is done by
class className implements iterface1,interface2, interfcae3 {
}

Thank you all for your help, it works like a charm now that I modified it with your suggestions. Tong1, thanks for fixing my Java code. NormR1, one I set visible after building the gui, everything showed up right away without me resizing. Also, thanks for the tip about toggling booleans. new programmer, thanks for showing me how to implement multiple interfaces.

If your problem is solved please change the status of your post to "Solved".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.