Results 1 to 4 of 4
  1. #1
    gladwda is offline Member
    Join Date
    Oct 2011
    Rep Power

    Default application translate to an applet


    At the moment I'm learning to change an application into an applet in order to run it online.
    The issue I am having however is in learning how to do this. I have read through the how to make applets tutorial on oracle's site however I'm struggling with adapting it to my specific code due to the fact that I integrate JFrame as well as Canvas. It is as follows:

    Java Code:
    ***import stuff removed to save space***
    public class Game extends Canvas {
       private BufferStrategy buffage;
    ***private boolean/arraylists/ints initialised removed to save space***
    public Game() {
          JFrame theFrame = new JFrame("Name Goes Here");
          JPanel thePanel = (JPanel) theFrame.getContentPane();
          thePanel.setPreferredSize(new Dimension(800,600));
          theFrame.addWindowListener(new WindowAdapter() {
             public void windowClosing(WindowEvent e) {
          addKeyListener(new KeyInputHandler());
          buffage = getBufferStrategy();
       private void startGame() {
    Now if I just change the Game class to Game extends Canvas, that throws out createBufferStrategy obviously as it derives from Canvas. Yet I need to implement JApplet.
    Someone told me that I "could still use a canvas with either just having 2 classes one that extends applet and 1 that extends canvas and use applet.add(canvas)", but everytime I try to work this out I hit a wall, I'm a newbie to coding and so I'm a bit panicky at how this should look. I'd have no problem if I had an example to work off, but I can't find a single piece of code anywhere where someone has had two classes, implementing Canvas in an Applet in this way. Perhaps I am blind.

    Could somebody please help me out? I'm really keen on learning! But it's been a bit of a brick wall the last few days trying to sort this out, I'm sure its simple but I can't get it unfortunately :/

    Thank you!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

    Default Re: application translate to an applet

    Please clarify: why are you mixing AWT (Canvas) and Swing (JFrame)? Why not one or the other (usually Swing)?

    Also, have you considered using Java Web Start instead?

  3. #3
    gladwda is offline Member
    Join Date
    Oct 2011
    Rep Power

    Default Re: application translate to an applet

    Well I need Canvas because of the getBufferStrategy, I'm only using JFrame to set up my window, key listener etc.
    It made sense in the application because I didn't have to extend anything else.

    Could I do without it in an Applet? Realising that I can define the dimensions in the html. If so does that present me with a new problem regardin the keyListener and so on?

    As for webstart, I didn't really want the user to have to launch the game, as some technophobes find it a bit intimidating I think, rather than launching inside the browser.

  4. #4
    gladwda is offline Member
    Join Date
    Oct 2011
    Rep Power

    Default Re: application translate to an applet

    If I drop JFrame entirely and go with this:

    public void init() {

    canvas = (Canvas)add(new Canvas());

    new Thread(this).start();

    That could work,
    only when I try to extend Applet it tells me that it cannot find the class?

Similar Threads

  1. Translate from C# to Java
    By Squezee in forum Java 2D
    Replies: 2
    Last Post: 02-07-2011, 07:07 PM
  2. How to translate english to hindi
    By nitin_sinha in forum Advanced Java
    Replies: 2
    Last Post: 12-20-2010, 10:44 PM
  3. translate - scale problem
    By gmseed in forum Java 2D
    Replies: 0
    Last Post: 11-16-2010, 09:31 PM
  4. Can translate?
    By workmason in forum New To Java
    Replies: 3
    Last Post: 10-22-2010, 09:11 AM
  5. Translate from C to java
    By ighor10 in forum New To Java
    Replies: 6
    Last Post: 03-27-2010, 10:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts