• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Converting an Application into JApplet

 
chander shivdasani
Ranch Hand
Posts: 206
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you creating a JFrame? JApplet is a top-level container to which you can add the JPanel.
 
chander shivdasani
Ranch Hand
Posts: 206
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 206
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot everyone. I got how to go about it. I am currently reading the tutorial on applet.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic