aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Converting an Application into JApplet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Converting an Application into JApplet" Watch "Converting an Application into JApplet" New topic
Author

Converting an Application into JApplet

chander shivdasani
Ranch Hand

Joined: Oct 09, 2007
Posts: 206

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.

Where am i going wrong??


Enjoy, Chander
SCJP 5, Oracle Certified PL/SQL Developer
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42276
    
  64
Why are you creating a JFrame? JApplet is a top-level container to which you can add the JPanel.


Ping & DNS - my free Android networking tools app
chander shivdasani
Ranch Hand

Joined: Oct 09, 2007
Posts: 206

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 ?
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
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.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42276
    
  64
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.
chander shivdasani
Ranch Hand

Joined: Oct 09, 2007
Posts: 206

Thanks a lot everyone. I got how to go about it. I am currently reading the tutorial on applet.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Converting an Application into JApplet