I am learning "Swing by example" by translating an good working simple AWT applet into a Swing Applet. To keep it very simple (and understand the basic first) I only add a button to an applet_surface and a button_actionlistener to that button.
Now i'm running to a brick wall... seems like I can not find a solution why my Swing applet is not working :-(
AWT Applet code
Swing applet code
Both examples compiles without errors, but when loading the applets into a browser via an html page...:
- The AWT applet shows the [quit] button on the applet_surface
- The Swing version shows nothing :-(
Question What have I forgotten in the Swing version?
Do I need use a JFrame first to which I add the JButton before it gets visible on screen?
Whenever you override any of the painting methods, always call the super class implementation as the first thing. In this case: super.paint(g). Or, if you follow Lester's advice, super.paintComponent(g) inside paintComponent.
I am learning "Swing by example" by translating an good working simple AWT applet into a Swing Applet.
Wrong approach. It is NOT a one to one conversion. You should read the section from the Swing tutorial on How to Make Applets to learn the proper approach.
As everybody has stated you should NOT override the paint() method. However, a JApplet does not have a paintComponent() method. If you want to add custom painting then there is a section on custom painting in the tutorial to read as well.
posted 8 years ago
I guess it is back to "Ground Zero" /"Square One" regarding to Swing Applet building:-)
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.