hello everyone.. Is there a method to link to an URL when we click on applets? i.e I wrote an applet drawn with two rectangles.My idea is to link to an URL when I click on one of the rectangles. Can I do this??If so,how can I do this? please help me. thanks chaitu
You can use showDocument(URL) method in AppletContext -- i.e.,
If you use this form of the method, the new page will replace your applet; if you want the applet to stay, there's an overloaded version that takes a second argument, a String "target" that names an HTML frame in which to display the other document.
Thanks Mr.Ernest Friedman-Hill ,it worked. My applets are to be loaded online.But there is a refresh problem with my applets.If I maximize the webpage having my applets,the content of my applet is getting changed. What should I do to avoid such problems?? Please reply me thanks chaitu
Resizing the window may cause the stop() method and then the start() method of your applet to be called. You need to make sure you implement the applet lifecycle methods correctly, or resizing and browsing can mess your applet up. For example, you should set up your GUI in the init() method, not the start() method. Also, anything that you do in start(), you should undo in stop().
Aaaaaaaak! You're setting up your GUI in the paint() method! That's crazy! paint() is called every time the window is partially obscured, resized, or even moved, so obviously, your GUI is going to grow many buttons very quickly! Move everything from paint() that doesn't directly use the Graphics object "g" into the init() method -- i.e., creating the buttons, calling add() on them, etc. The "drawing" code does indeed belong in the paint() method, so that you can leave where it is.