I've made pong and was wondering how I could embed it (it was made in java). I'm new to java so if you could explain it, that would be helpful, but if you can't that's ok. Thanks in advance :icon_mrgreen:.

thanks, i'm trying it now

dang, the problem is that i am not using swing, here is the code

import java.awt.Button;
import processing.core.PApplet;
import processing.core.PImage;
import javax.swing.JApplet;
public class Pong extends PApplet {
    float x = 70;
    int y = 10;
    int ballX = 200;
    int ballY = 180;
    float x3 = ballX-40;
    float y3 = 380;
    int x2 = 200;
    int y2 = 380;
    PImage b;
    Button z;


    double ballVeloX = -4;
    double ballVeloY = -2;

    boolean skey = false;
    boolean akey = false;
    boolean kkey = false;
    boolean lkey = false;

    boolean singlePlayer = false;
    boolean twoPlayer = false;
    boolean onSplash = true;

    int gameState = 0;

    int paddleVelo = 0;

    public void setup() {
        size(400, 400);
        stroke(255);
        //b = loadImage("splash.png-3.0");
    }

    public void draw() {

        if (gameState == 0) {

        //  z = new Button("Welcome To Pong! Press 1 for One Player or 2 for two player.");
            //z.setBounds(0,0,400,400);
        //  add(z);
        //background(b);



            if (singlePlayer == true) {
                gameState = 1;
            }
            if (twoPlayer == true) {
                gameState = 2;
            }
        }
        if (gameState == 1) {

            background(0);
            ballX += ballVeloX;
            ballY += ballVeloY;

            if (skey == true) {
                x = (float) (x + 1.6);
            }
            if (akey == true) {
                x = (float) (x - 1.6);
            }

            if (x3 + 80 >= 400) {

                x3 = 400 - 80;
            }
            if (x3 - 10 == 0) {
                x3 = 80;
            }
            if (ballX == 0) {
                ballVeloX = -ballVeloX;
            }
            if (ballX == 400) {
                ballVeloX = -ballVeloX;
            }

            // paddle AI
            if (ballX < x3) {
                x3 -= 3.7;
            }
            if (ballX > x3) {
                x3 += 3.7;
            }

            // Paddle condition
            if ((ballX > x && ballX < x + 80) && ballY <= y + 10) {
                ballVeloY = -ballVeloY;
            }
            if ((ballX > x3 - 10 && ballX < x3 + 80) && ballY == y3 - 10) {
                ballVeloY = -ballVeloY;
            }

            if (ballY < y || ballY > y3) {

                ballX = 200;
                ballY = 180;

                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {

                    e.printStackTrace();
                }
            }

            rect(x, y, 80, 10);
            rect(x3, 380, 80, 10);
            ellipse(ballX, ballY, 20, 20);
        }

        if (gameState == 2) {
            background(0);

            ballX += ballVeloX;
            ballY += ballVeloY;

            if (skey == true) {
                x = x + 3;
            }
            if (akey == true) {
                x = x - 3;
            }
            if (lkey == true) {
                x2 = x2 + 3;
            }
            if (kkey == true) {
                x2 = x2 - 3;
            }

            if (ballX == 0) {
                ballVeloX = -ballVeloX;
            }
            if (ballX == 400) {
                ballVeloX = -ballVeloX;
            }

            // Paddle condition
            if ((ballX > x && ballX < x + 80) && ballY <= y + 10) {
                ballVeloY = -ballVeloY;
            }
            if ((ballX > x2 && ballX < x2 + 80) && ballY == y2 - 10) {
                ballVeloY = -ballVeloY;
            }

            if (ballY < y || ballY > y2) {

                ballX = 200;
                ballY = 180;

                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {

                    e.printStackTrace();
                }
            }

            background(0);
            rect(x, y, 80, 10);
            rect(x2, y2, 80, 10);
            ellipse(ballX, ballY, 20, 20);
        }
    }

    public void keyPressed() {
        if (key == 's') {
            skey = true;
        }
        if (key == 'a') {
            akey = true;
        }

        if (key == 'k') {
            kkey = true;
        }
        if (key == 'l') {
            lkey = true;
        }
        if (key == '1') {
            singlePlayer = true;
        }
        if (key == '2') {
            twoPlayer = true;
        }
    }

    public void keyReleased() {
        if (key == 's') {
            skey = false;
        }
        if (key == 'a') {
            akey = false;
        }

        if (key == 'k') {
            kkey = false;
        }
        if (key == 'l') {
            lkey = false;
        }
    }

}

it works, but i need to know what to do to get it online

update: i know what that does, but I need how to accualy embed it in a website, not just get it ready

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.