Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Intializing Applet
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
jamonathin




PostPosted: Wed Dec 21, 2005 2:47 pm   Post subject: Intializing Applet

Hey all, wanted to get back into making games (as some of you may know) and i'm just going to start with a basic brickout style game. But i cant seem to get anything to start. How do I go about initializing my applet?

Here's my code. The only part I wanna see right now is refresh();. The other stuff is there for later on.
Java:

import java.awt.*;

public class Tetris
{
        Thread fThread;
        Image offScreenImage;
        Graphics offScreenGraphics;
       
        int xPlayer = 100;
        int yPlayer = 20;
        int gameSpeed = 4;
       
        int bxSize = 30; // Block - x size.
        int bySize = 30; // Block - y size.
       
        int maxx = 360;
        int maxy = 360;
       
        boolean keyUp = false;
        boolean keyDown = false;
        boolean keyLeft = false;
        boolean keyRight = false;
       
        //       2-D map
        byte fMap[];
        static final byte W = 1;                                // wall
        static final byte O = 0;                                // opening
        static final int mapWidth = 12;
        static final int mapHeight = 12;
       
        public void map ()
        {
                //       Making a map - 2D
                byte[] map=
                {
                                O,O,O,O,O,O,O,O,O,O,O,O,
                                O,O,O,O,O,W,W,O,O,O,O,O,
                                O,O,O,O,W,W,W,W,O,O,O,O,
                                O,O,O,W,W,W,W,W,W,O,O,O,
                                O,O,W,W,W,W,W,W,W,W,O,O,
                                O,W,W,W,W,W,W,W,W,W,W,O,
                                O,O,O,O,W,W,W,W,O,O,O,O,
                                O,O,O,O,O,O,O,O,O,O,O,O,
                                O,O,O,O,O,O,O,O,O,O,O,O,
                                O,O,O,O,O,O,O,O,O,O,O,O,
                                O,O,O,O,O,O,O,O,O,O,O,O,
                                O,O,O,O,O,O,O,O,O,O,O,O,
                };
                fMap=map;
        }
        public void refresh () 
        {
                for (int i = 0 ; i < maxx / 2 ; ++i)
                {
                        offScreenGraphics.setColor(new Color (i / (maxx / 2), i / (maxx / 2), i / (maxx / 2)));
                        offScreenGraphics.fillRect(i, i, maxx - i, maxy - i);
                }              
               
        }
       
        public void move ()
        {
                while (true)
                {
                        if (keyLeft && xPlayer - gameSpeed > 0)
                        {
                                xPlayer -= gameSpeed;
                        }
                        else if (keyRight && xPlayer + gameSpeed < maxx)
                        {
                                xPlayer += gameSpeed;
                        }
                }
        }
               
        public void main (String []args)
        {
                refresh ();
               
        }
       
}
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Wed Dec 21, 2005 2:48 pm   Post subject: (No subject)

code:
public void init


That's in even the most basic applet tutorial.

Google is your friend, especially with "site:java.sun.com".
jamonathin




PostPosted: Thu Dec 22, 2005 10:32 am   Post subject: (No subject)

Yeah turns out i needed
Java:

extends Applet implements Runnable

and
Java:

public void run()

I saw those in the other example, but I thought they were just user created names, not that init and run were needed Doh!.
jamonathin




PostPosted: Thu Dec 22, 2005 10:33 am   Post subject: (No subject)

Yeah turns out i needed
Java:

extends Applet implements Runnable

and
Java:

public void run()

I saw those in the other example, but I thought they were just user created names, not that init and run were needed Doh!.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: