Results 1 to 2 of 2
  1. #1
    soulrain is offline Member
    Join Date
    Dec 2011
    Rep Power

    Default How To Get A Java Program Embedded Into A Webpage.

    Hi all and thanks in advance.

    I have made a little java game using eclipse:

    import java.applet.Applet;
    import acm.program.*;
    import java.awt.*;
    import java.awt.event.*;

    public class ufo2game extends GraphicsProgram{

    private static final int UFO_WIDTH = 40;
    private static final int UFO_HEIGHT = UFO_WIDTH/2;
    private static final int UFO_SPEED = 5;
    private static final int BULLET_SPEED = 10;
    private static final int BULLET_DIAM = 5;
    private static final int DELAY = 10;

    public void run(){

    while (!gameOver()){




    public void setup(){

    ufo = new GRect(UFO_WIDTH, UFO_HEIGHT);
    add(ufo, getWidth(), 0);
    ufoToLeft = true;

    private boolean gameOver(){

    return (ufo == null) || (ufo.getY()>=getHeight() - UFO_HEIGHT);

    public void mouseClicked(MouseEvent e){

    if (bullet == null){

    bullet = new GOval(BULLET_DIAM, BULLET_DIAM);
    add(bullet, (getWidth()-BULLET_DIAM)/2, getHeight()-BULLET_DIAM);

    private void moveUFO(){

    if (ufoToLeft){

    ufo.move(-UFO_SPEED, 0);
    ufoToLeft = false;
    ufo.move(0, UFO_HEIGHT);

    } else {

    ufo.move(UFO_SPEED, 0);
    if (ufo.getX()>=getWidth()-UFO_WIDTH){

    ufoToLeft = true;
    ufo.move(0, UFO_HEIGHT);




    private void moveBullet(){

    if (bullet != null){

    bullet.move(0, -BULLET_SPEED);



    private void checkForCollisions(){



    private void collideWithUFO(){

    if (bullet != null){

    GObject collObj = getElementAt(bullet.getX(), bullet.getY());
    if (collObj == ufo){

    remove (ufo);
    remove (bullet);
    ufo = null;
    bullet = null;




    private void moveOffScreen(){

    if (bullet != null){

    if (bullet.getY()<=-BULLET_DIAM){

    bullet = null;



    private GRect ufo;
    private GOval bullet;
    private boolean ufoToLeft;


    I was curious how I go about getting this into a webpage similar to how this is:


    I see that the source code for the above page is:

    <applet archive="Breakout.jar"
    width=408 height=608>

    <strong>Note:</strong> This version has extra features that you aren't required to implement for the
    assignment (like sound effects, and the ball bouncing off the paddle at different angles).
    You are only responsible for implementing the features described in the Assignment 3 handout.
    But you can certainly add these capabilities for extra credit!
    But I have little idea how to turn my program that I have written into an applet. I have messed around placing the entire code into a new class that extends Applet but with no luck.

    If anyone can explain this to me or point me in the right direction, I would appreciate it!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default Re: How To Get A Java Program Embedded Into A Webpage.

    First step would be to understand how applets work and are used. Check this tutorial
    Lesson: Java Applets (The Java™ Tutorials > Deployment)
    Basically the browser calls methods the the applet to get it started, no main() method.
    The applet class is a Container that you add your GUI components to.

Similar Threads

  1. Java for embedded
    By daniil in forum Advanced Java
    Replies: 2
    Last Post: 04-19-2011, 08:07 AM
  2. Some problems with Java DB(Embedded)
    By Jstn455 in forum JDBC
    Replies: 2
    Last Post: 04-08-2011, 09:03 AM
  3. Putting the Applet program on webpage
    By sarwar1234 in forum New To Java
    Replies: 29
    Last Post: 10-06-2010, 07:49 AM
  4. Embedded Java Middleware in STB Technologies
    By neel_vk in forum Jobs Offered
    Replies: 1
    Last Post: 08-11-2009, 03:46 PM
  5. i need a IDE for embedded java
    By santhosh_el in forum AWT / Swing
    Replies: 2
    Last Post: 04-29-2009, 08:23 AM

Posting Permissions

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