Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Converting an Application into JApplet

 
Ranch Hand
Posts: 206
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot everyone. I got how to go about it. I am currently reading the tutorial on applet.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic