Author |
Message |
Bankai
Joined: Mon Aug 18, 2008 7:58 pm Posts: 1093
Gender: Male
|
Ok, so I'm going to get a head start on my AP Computer Science final, so I got BlueJ 3.0 (what we use @ school) and JDK (7u2)? We should use 1.6.20 but oh well. My problem is, the applet I am using won't show anything because it wasn't "initialized" If anyone can fix this, I'd be very glad! CODE USED: import java.applet.*; import java.awt.*; import objectdraw.*; import java.lang.Object; import java.lang.String; import java.net.*; import java.awt.event.*; import javax.swing.*;
/** * Class Game - write a description of the class here * * @author ("Bankai") * @version (v0.1) */ public class Game extends KeyWindowController { // Create objects for the game VisibleImage P1; Image I; Image Town; Toolkit kit = Toolkit.getDefaultToolkit(); VisibleImage Pallet; AudioClip hohoho; AudioClip BTTLE; double playerx = 98; double playery = 140; boolean rightkey = false; boolean leftkey = false; boolean upkey = false; boolean downkey = false; VisibleImage P12; Image Two; double walk; VisibleImage P13; Image Three; VisibleImage WL1; Image WLa; VisibleImage WL2; Image WLb; int Stance = 0; VisibleImage WU1; Image WUa; VisibleImage WU2; Image WUb; VisibleImage WD1; Image WDa; VisibleImage WD2; Image WDb; VisibleImage Grass; Image Gr; VisibleImage BAT; Image BTTL; int plntx = 300; int plnty = 140; boolean battle= false; boolean start = true; double x; double y; VisibleImage Bird; Image Pidgey; /** * Called by the browser or applet viewer to inform this JApplet that it * has been loaded into the system. It is always called before the first * time that the start method is called. */
public void init() { // Drawing the items declared setSize(400,400); I = kit.createImage("PlayerS.png"); Town = kit.createImage("House.png"); Pallet = new VisibleImage(Town, 66, 46, canvas); WLa = kit.createImage("PlayerA.png"); WLb = kit.createImage("PlayerA2.png"); Two = kit.createImage("PlayerD.png"); Three = kit.createImage("PlayerD2.png"); WUa = kit.createImage("PlayerW.png"); WUb = kit.createImage("PlayerW2.png"); WDa = kit.createImage("PlayerS.png"); WDb = kit.createImage("PlayerS2.png"); P12 = new VisibleImage(Two, playerx, playery, canvas); P13 = new VisibleImage(Three, playerx, playery, canvas); WL1 = new VisibleImage(WLa, playerx, playery, canvas); WL2 = new VisibleImage(WLb, playerx, playery, canvas); WU1 = new VisibleImage(WUa, playerx, playery, canvas); WU2 = new VisibleImage(WUb, playerx, playery, canvas); WD1 = new VisibleImage(WDa, playerx, playery, canvas); WD2 = new VisibleImage(WDb, playerx, playery, canvas); Gr = kit.createImage("Grass4Sq.png"); BTTL = kit.createImage("Battle1.png"); BAT = new VisibleImage(BTTL, 0, 0, canvas); Grass = new VisibleImage(Gr, plntx, plnty, canvas); BAT.hide(); Pidgey = kit.createImage("Pidgey.png"); Bird = new VisibleImage(Pidgey, plntx, plnty, canvas); Bird.hide(); hohoho = getAudioClip(getCodeBase(), "pallet.wav"); BTTLE = getAudioClip(getCodeBase(), "wild.wav"); hohoho.play(); if((rightkey == true) && (upkey == true)) { playerx = playerx - 2; }
if((leftkey == true) && (upkey == true)) { playerx = playerx - 2; }
if((downkey == true) && (upkey == true)) { upkey = false; }
if((downkey == true) && (leftkey == true)) { playerx = playerx + 2; }
if((downkey == true) && (rightkey == true)) { playerx = playerx - 2; }
if((rightkey == false) &&(Stance == 0)) { P1 = new VisibleImage(I, playerx, playery, canvas); } }
public void onKeyPress(int e, Location p) { p = new Location (playerx, playery); switch(e) {
case KeyEvent.VK_D: rightkey = true; Stance = 1; if(((walk >= 0) &&(walk < 2) &&(Stance == 1))) { P12.show(); walk = walk + 0.5; playerx = playerx + 2; P12.moveTo(playerx, playery); P1.hide(); P13.hide(); WL1.hide(); WL2.hide(); WD1.hide(); WD2.hide(); WU1.hide(); WU2.hide(); } else { if((walk >= 2) &&(walk < 3.1)) { P13.show(); walk = walk + 0.4; playerx = playerx + 2; P13.moveTo(playerx, playery); P1.hide(); P12.hide(); WL1.hide(); WL2.hide(); WD1.hide(); WD2.hide(); WU1.hide(); WU2.hide(); if(walk > 3.1) { walk = 0; } }
} break;
case KeyEvent.VK_A: leftkey = true; Stance = 3;
if(((walk >= 0) &&(walk < 2) &&(Stance == 3))) { WL1.show(); walk = walk + 0.5; playerx = playerx - 2; WL1.moveTo(playerx, playery); P1.hide(); WL2.hide(); P12.hide(); P13.hide(); WD1.hide(); WD2.hide(); WU1.hide(); WU2.hide(); } else { if((walk >= 2) &&(walk < 3.1)) { WL2.show(); walk = walk + 0.4; playerx = playerx - 2; WL2.moveTo(playerx, playery); P1.hide(); WL1.hide(); P12.hide(); P13.hide(); WD1.hide(); WD2.hide(); WU1.hide(); WU2.hide(); if(walk > 3.1) { walk = 0; } }
} break;
case KeyEvent.VK_W: upkey = true; Stance = 4; if(((walk >= 0) &&(walk < 2) &&(Stance == 4))) { WU1.show(); walk = walk + 0.5; playery = playery - 2; WU1.moveTo(playerx, playery); P1.hide(); P13.hide(); WL1.hide(); WL2.hide(); WU2.hide(); P12.hide(); WD1.hide(); WD2.hide(); } else { if((walk >= 2) &&(walk < 3.1)) { WU2.show(); walk = walk + 0.5; playery = playery - 2; WU2.moveTo(playerx, playery); P1.hide(); P13.hide(); WL1.hide(); WL2.hide(); P12.hide(); WD1.hide(); WD2.hide(); WU1.hide(); if(walk > 3.1) { walk = 0; } } } break;
case KeyEvent.VK_S: downkey = true; Stance = 0; if(((walk >= 0) &&(walk < 2) &&(Stance == 0))) { WD1.show(); walk = walk + 0.5; playery = playery + 2; WD1.moveTo(playerx, playery); P1.hide(); P13.hide(); WL1.hide(); WL2.hide(); WU2.hide(); P12.hide(); WD2.hide(); WU2.hide(); } else { if((walk >= 2) &&(walk < 3.1)) { WD2.show(); walk = walk + 0.5; playery = playery + 2; WD2.moveTo(playerx, playery); P1.hide(); P13.hide(); WL1.hide(); WL2.hide(); P12.hide(); WU1.hide(); WU2.hide(); WD1.hide(); if(walk > 3.1) { walk = 0; } } } break; } x = p.getX(); y = p.getY(); if ((Grass.contains(p) == true) && (battle == false)) { battle = true; hohoho.stop(); BTTLE.play(); BAT.show(); Grass.hide(); Bird.show(); rightkey = false; upkey = false; downkey = false; leftkey = false; } else if ((Grass.contains(p) == false) && (battle == true)) { battle = false; BTTLE.stop(); hohoho.play(); } } public void onKeyRelease(int e, Location p) { p = new Location (playerx, playery); switch(e) { case KeyEvent.VK_D: rightkey = false; break;
case KeyEvent.VK_A: leftkey = false; break;
case KeyEvent.VK_W: upkey = false; break;
case KeyEvent.VK_S: downkey = false; break; } x = p.getX(); y = p.getY(); } public void onMouseClick(Location p) { } }
_________________Current Demo: None! Go check it out!
|
Wed Jan 11, 2012 8:41 pm |
|
|
Michael
Joined: Tue Apr 06, 2010 4:47 am Posts: 2081 Location: At home, working and playing
Gender: Male
|
Someone may fix it for you here but ill see what i can do about it. I use netbeans so if it acts differently on my computer, i understand
|
Sat Jan 14, 2012 1:14 am |
|
|
SS
Joined: Sat Aug 16, 2008 8:38 am Posts: 6670 Location: Darkest Antartica Country:
Gender: Male
Skype: Thaiberium
Currently Playing: The Game
|
Been a while since I did Java, let me take a look. Just a quick observation, you're using implementation inheritance. Not that I frown on it, I'm just curious why you would. That and why you have one gigantic class for everything. Also since you're trying to make an applet, why isn't it like I feel like it doesn't make sense if you have an init() method in a goddamn KeyWindowController() subclass. I'd go back to the drawing board and to redesigning the structure of your program.
|
Sat Jan 14, 2012 1:53 am |
|
|
Nick
Joined: Fri Sep 17, 2010 12:31 am Posts: 2229
Gender: N/A
|
I have a feeling that this is what he was taught, what you suggested to me in my C++ codes (and Tid) was never even mentioned to me in class.
_________________
|
Sat Jan 14, 2012 3:47 pm |
|
|
Bankai
Joined: Mon Aug 18, 2008 7:58 pm Posts: 1093
Gender: Male
|
Nevermind guys, I figured it out. Now it works fine. I originally used: before this and it wasn't working. I re-did that and I added a newer version of ObjectDrawInvoker.jar But another thing.. When I Run Controller() it shows as the title, "panel0". I would like to change this.
_________________Current Demo: None! Go check it out!
|
Sat Jan 14, 2012 8:23 pm |
|
|
SS
Joined: Sat Aug 16, 2008 8:38 am Posts: 6670 Location: Darkest Antartica Country:
Gender: Male
Skype: Thaiberium
Currently Playing: The Game
|
Because you're doing procedural stuff. The basics. What I know is a step up.
|
Sun Jan 15, 2012 10:07 am |
|
|
Who is online |
Users browsing this forum: No registered users and 1 guest |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|