digibutter.nerr Forum Index
Hey [you]! If you haven't noticed, this is now the old digibutter forums. Go over to the new site!
digibutter.nerr
It's Hi-Technicaaal!

Oh God
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    digibutter.nerr Forum Index -> digiblogger

How does I learned to java?
Press Zr twice
0%
 0%  [ 0 ]
lolwut
50%
 50%  [ 1 ]
What's a java?
50%
 50%  [ 1 ]
Total Votes : 2

Author Message
Bananatank
Vampire


Joined: 14 May 2008
Posts: 465

HP: 5 MP: 0 Lives: 0



PostPosted: Fri Nov 14, 2008 10:26 pm   Reply with quote

How does I learned java? Oh wait. awesome Anyways this is just something I threw together to figure out how to do movement in java
Code:
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class MovementExample extends Applet implements KeyListener
{
   int x=40,y=40,key = 0,collide=0;
   char reset;
   SolidObject object = new SolidObject();
   public void init()
   {
      addKeyListener(this);
      setFocusable(true);
   }
   public void paint(Graphics draw)
   {
      setSize(500,500);
      draw.fillOval(x, y, 20, 20);
      draw.fillRect(100, 100, 100, 100);
      if(x+20 >= 100 && x <= 200)
      {
         if(y+20 >= 100 && y <= 200)
         {
            draw.drawString("Oh dear you ran into the square of death(press r)", 100, 10);
            collide = 1;
         }
      }
      else if(x == 500 || y == 500)
      {
         x=40;
          y=40;
      }
      else if( x == 0 || y ==0)
      {
         x=40;
         y=40;
      }
      
   }
   public void keyPressed(KeyEvent keys) {
      key=keys.getKeyCode();
      if(collide == 0)
      {
      if( key == 39)
         x=x+5;
      else if( key == 37)
         x=x-5;
      else if( key == 40)
         y=y+5;
      else if( key == 38)
         y=y-5;
      }
      repaint();
   }
   public void keyReleased(KeyEvent keys)
   {
   }
   public void keyTyped(KeyEvent keys)
   {
      if (collide == 1)
      {
         reset = keys.getKeyChar();
         if(reset == 114)
         {
            x = 40;
            y = 40;
            collide = 0;
         }
      }
   }
}

EDIT: How does I @ overided?
Back to top
Sovietkip shop    
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    digibutter.nerr Forum Index -> digiblogger
All times are GMT - 5 Hours
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group