View unanswered posts | View active topics It is currently Tue May 21, 2019 10:04 pm



Reply to topic  [ 6 posts ] 
Java Help! 
Author Message
User avatar

Joined: Mon Aug 18, 2008 7:58 pm
Posts: 1093
Gender: Male
Reply with quote
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:

Code: show
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) {

}
}

_________________
ImageImage

Image
Current Demo: None! Go check it out!


Wed Jan 11, 2012 8:41 pm
Profile
User avatar

Joined: Tue Apr 06, 2010 4:47 am
Posts: 2081
Location: At home, working and playing
Gender: Male
Reply with quote
Bankai wrote:
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:
Please don't quote boxes, it breaks them. -Friendly section moderator

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
Profile
User avatar

Joined: Sat Aug 16, 2008 8:38 am
Posts: 6668
Location: Darkest Antartica
Country: Pakistan (pk)
Gender: Male
Skype: Thaiberium
Currently Playing: The Game
Reply with quote
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
Code:
public class Game extends Applet()

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.

_________________
Image


Sat Jan 14, 2012 1:53 am
Profile
User avatar

Joined: Fri Sep 17, 2010 12:31 am
Posts: 2215
Gender: N/A
Reply with quote
SS wrote:
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
Code:
public class Game extends Applet()

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.

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.

_________________
Image


Sat Jan 14, 2012 3:47 pm
Profile
User avatar

Joined: Mon Aug 18, 2008 7:58 pm
Posts: 1093
Gender: Male
Reply with quote
Nevermind guys, I figured it out. Now it works fine. I originally used:

Code:
public void begin()


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.

_________________
ImageImage

Image
Current Demo: None! Go check it out!


Sat Jan 14, 2012 8:23 pm
Profile
User avatar

Joined: Sat Aug 16, 2008 8:38 am
Posts: 6668
Location: Darkest Antartica
Country: Pakistan (pk)
Gender: Male
Skype: Thaiberium
Currently Playing: The Game
Reply with quote
G0L3M wrote:
SS wrote:
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
Code:
public class Game extends Applet()

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.

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.

Because you're doing procedural stuff. The basics. What I know is a step up.

_________________
Image


Sun Jan 15, 2012 10:07 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

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

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software for PTF.