I have made a game called Tic Tac Toe. It is a standalone application right now . I want to convert it into an Applet. Below is the code showing my progress in converting it into an applet.
The Problem out here is when i run the program, two windows pop up. One for the applet and one for the frame in which the actual game is there. I want to add the frame on the applet window. I tried doing it but its not working.
chander shivdasani wrote:The problem is in accessing JApplet. How do i do that. In the paint function, i am adding g.add(panel1). But there is no function called add in g. So how do i add all the panels to the JApplet ?
A JApplet has a contentPane just like a JFrame. I usually add my JPanel's to the JApplet's contentPane. But if you read the Sun tutorial on applets, it will tell you all this and more. It's highly recommended reading.
Joined: Mar 22, 2005
You shouldn't add anything to the GUI in the paint method - that's what init is for. Instead of "window.add(p4)" and "window.setBackground(BACKGROUND)" you'd just use "getContentPane().add(p4)" and "getContentPane().setBackground(BACKGROUND)", thus calling the JApplet's methods.