KeyListener Difficulties
Hello everyone. I'm currently making my first Java game, kinda like tetris.
I recently switched my code from an applet to using frames and can't figure out a way to attach my keyListener to the frame or canvas for listening.
I can only figure out ways to call it from inside static methods, and it alters non-static variables so I get lots of errors.
here's my code... it's sloppy and in only 3 seperate classes... sorry for all the confusion it may cause...
========================================================
TetrisCODE CLASS
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.URL;
publicclass TetrisCODEextends JAppletimplements KeyListener, ActionListener{
Block next =new Block((int)Math.round(Math.random() * 6) + 1);
Block current =new Block((int)Math.round(Math.random() * 6) + 1);
Garbage Garb =new Garbage();
DisplayPanel canvas;
boolean keys_pressed[] =newboolean[115];
String display ="menu";
boolean sound =true;
JTextArea output;
JScrollPane scrollPane;
JPanel contentPane;
Thread Thread1;
Thread Thread2;
Thread Thread3;
int score;
int lines;
int level;
int x = 1;
/*
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*::::::: GAME CALL STATEMENTS ::::::
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
publicvoid newGame(){
newPiece();
startThreads();
//Audio Initiation
//AudioClip background = getAudioClip(getCodeBase(), "tetris.au");
//background.loop();
}
publicvoid endGame(){
Garb.refresh();
stopThreads();
}
/*
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*::::::::::::: THREADS :::::::::::::
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
int SENSITIVITY = 60;
Runnable r1 =new Runnable(){
publicvoid run(){
while(true){
if (keys_pressed[KeyEvent.VK_LEFT]){
if(current.moveLeft(Garb)){
testAndAddPiece(current, Garb);
}
}elseif(keys_pressed[KeyEvent.VK_RIGHT]){
if(current.moveRight(Garb)){
testAndAddPiece(current, Garb);
}
}
if (keys_pressed[KeyEvent.VK_DOWN]){
if (!testAndAddPiece(current, Garb)) current.moveDown();
}
if (keys_pressed[113] && SENSITIVITY > 5) SENSITIVITY -= 5;
if (keys_pressed[112]) SENSITIVITY += 5;
/*if (keys_pressed[114] && sound) {background.stop();}
else if (keys_pressed[114] && !sound) {
background.loop();
}*/
try{ Thread.sleep(SENSITIVITY);}
catch(InterruptedException e){return;}
if(!(keys_pressed[KeyEvent.VK_DOWN] || keys_pressed[KeyEvent.VK_RIGHT] || keys_pressed[KeyEvent.VK_LEFT])){Thread1.suspend();}
}
}
};
Runnable r2 =new Runnable(){
publicvoid run(){
while(true){
//System.out.println("PAINT THREAD");
//canvas.repaint();
contentPane.repaint();
try{ Thread.sleep(15);}
catch(InterruptedException e){return;}
}
}
};
finalint SLOWEST_SPEED = 400;
Runnable r3 =new Runnable(){
publicvoid run(){
while(true){
//System.out.println("MOVE THREAD");
if (!testAndAddPiece(current, Garb)) current.moveDown();
try{ Thread.sleep((int)(SLOWEST_SPEED - (((SLOWEST_SPEED) * Math.pow(Math.E, .3 * level)) / (SLOWEST_SPEED + Math.pow(Math.E, .3 * level) - 1))));}
catch(InterruptedException e){return;}
}
}
};
publicvoid startButtonThread(){
if(Thread1 ==null){
Thread1 =new Thread(r1,"Buttons");
Thread1.setPriority(10);
} Thread1.start();
}
publicvoid stopButtonThread(){
Thread1.stop();
}
publicvoid startPaintThread(){
if(Thread2 ==null){
Thread2 =new Thread(r2,"Paint");
Thread2.setPriority(2);
} Thread2.start();
}
publicvoid stopPaintThread(){
Thread2.stop();
}
publicvoid startMoveThread(){
if(Thread3 ==null){
Thread3 =new Thread(r3,"Move");
Thread3.setPriority(5);
} Thread3.start();
}
publicvoid stopMoveThread(){
Thread3.stop();
}
publicvoid startThreads(){
startButtonThread();
startPaintThread();
startMoveThread();
}
publicvoid stopThreads(){
stopButtonThread();
stopPaintThread();
stopMoveThread();
}
/*
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*::::::::::::: INITIATION :::::::::::::
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
publicvoid init(){
//Canvas & Listeners
//addKeyListener(this);
canvas =new DisplayPanel();
setContentPane(canvas);
canvas.setBackground(Color.BLACK);
//canvas.addKeyListener(this);
//Game Statements
newGame();
}
public TetrisCODE(){
addKeyListener(this);
}
class DisplayPanelextends JPanel{
publicvoid paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(new Color(62,62,62));
for(int x = 2; x <= 13; x++){
g.drawLine(x*20,0,x*20,600);
}
for(int x = 0; x <= 30; x++){
g.drawLine(40,x*20,260, x*20);
}
Garb.draw(g);
next.draw(g);
current.draw(g);
g.setFont(new Font("Veranda", Font.PLAIN, 18));
g.setColor(Color.GRAY.darker());
g.drawString("Score: " + score, 300, 200);
g.drawString("Lines: " + lines, 300, 230);
g.drawString("Level: " + level, 300, 260);
g.setFont(new Font("Veranda", Font.PLAIN, 16));
g.drawString("F1 - Lower Sensitivity", 280, 360);
g.drawString("F2 - Raise Sensitivity", 280, 390);
g.drawString("F3 - Toggle Sound", 280, 420);
g.setFont(new Font("Times New Roman", Font.PLAIN, 10));
g.drawString("?2005 Doug Kelkhoff", 300, 580);
}
}
publicvoid keyPressed(KeyEvent evt){
System.out.println("LISTENING");
int key = evt.getKeyCode();
keys_pressed[evt.getKeyCode()] =true;
if(Thread1.isAlive()) Thread1.resume();
if (key == KeyEvent.VK_UP){
if(current.rotateRight(Garb)){
testAndAddPiece(current, Garb);
}
}if (key == 32){
current.drop(Garb);
testPiece(current, Garb);
}
}
publicvoid keyReleased(KeyEvent evt){
int key = evt.getKeyCode();
keys_pressed[evt.getKeyCode()] =false;
}
publicvoid keyTyped(KeyEvent evt){
}
/*
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*:::::::::::::: MENU ::::::::::::::::::
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
public JMenuBar createMenuBar(){
JMenuBar menuBar;
JMenu menu, submenu;
JMenuItem menuItem;
JRadioButtonMenuItem rbMenuItem;
JCheckBoxMenuItem cbMenuItem;
//Create the menu bar.
menuBar =new JMenuBar();
//Build the first menu.
menu =new JMenu("Game");
menu.setMnemonic(KeyEvent.VK_G);
menu.getAccessibleContext().setAccessibleDescription(
"Game Options");
menuBar.add(menu);
//a group of JMenuItems
menuItem =new JMenuItem("New Game",KeyEvent.VK_N);
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, ActionEvent.ALT_MASK));
menuItem.getAccessibleContext().setAccessibleDescription("Creates a New Game");
menuItem.addActionListener(this);
menuItem.setActionCommand("NewGame");
menu.add(menuItem);
/*
ImageIcon icon = createImageIcon("images/middle.gif");
menuItem = new JMenuItem("Both text and icon" , icon);
menuItem.setMnemonic(KeyEvent.VK_B);
menu.add(menuItem);
menuItem = new JMenuItem(icon);
menuItem.setMnemonic(KeyEvent.VK_D);
menu.add(menuItem);
//a group of radio button menu items
menu.addSeparator();
ButtonGroup group = new ButtonGroup();
rbMenuItem = new JRadioButtonMenuItem("A radio button menu item");
rbMenuItem.setSelected(true);
rbMenuItem.setMnemonic(KeyEvent.VK_R);
group.add(rbMenuItem);
menu.add(rbMenuItem);
rbMenuItem = new JRadioButtonMenuItem("Another one");
rbMenuItem.setMnemonic(KeyEvent.VK_O);
group.add(rbMenuItem);
menu.add(rbMenuItem);
//a group of check box menu items
menu.addSeparator();
cbMenuItem = new JCheckBoxMenuItem("A check box menu item");
cbMenuItem.setMnemonic(KeyEvent.VK_C);
menu.add(cbMenuItem);
cbMenuItem = new JCheckBoxMenuItem("Another one");
cbMenuItem.setMnemonic(KeyEvent.VK_H);
menu.add(cbMenuItem);
//a submenu
menu.addSeparator();
submenu = new JMenu("A submenu");
submenu.setMnemonic(KeyEvent.VK_S);
menuItem = new JMenuItem("An item in the submenu");
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_2, ActionEvent.ALT_MASK));
submenu.add(menuItem);
menuItem = new JMenuItem("Another item");
submenu.add(menuItem);
menu.add(submenu);
//Build second menu in the menu bar.
menu = new JMenu("Another Menu");
menu.setMnemonic(KeyEvent.VK_N);
menu.getAccessibleContext().setAccessibleDescription(
"This menu does nothing");
menuBar.add(menu);
*/
return menuBar;
}
publicvoid actionPerformed(ActionEvent e){
if("NewGame".equals(e.getActionCommand())){
newGame();
}
}
public Container createContentPane(){
contentPane =new DisplayPanel();
contentPane.setBackground(Color.BLACK);
return contentPane;
}
/** Returns an ImageIcon, or null if the path was invalid. */
protectedstatic ImageIcon createImageIcon(String path){
java.net.URL imgURL = TetrisCODE.class.getResource(path);
if (imgURL !=null){
returnnew ImageIcon(imgURL);
}else{
System.err.println("Couldn't find file: " + path);
returnnull;
}
}
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
privatestaticvoid createAndShowGUI(){
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
//Create and set up the window.
JFrame frame =new JFrame("Tetris");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
TetrisCODE game =new TetrisCODE();
frame.setJMenuBar(game.createMenuBar());
frame.setContentPane(game.createContentPane());
//Display the window.
frame.setSize(450, 670);
frame.setVisible(true);
}
publicstaticvoid main(String[] args){
javax.swing.SwingUtilities.invokeLater(new Runnable(){
publicvoid run(){
createAndShowGUI();
}
});
}
/*
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*::::::::: PRIVATE METHODS ::::::::::::
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
privatevoid newPiece(){
current = next;
current.changeX(5 + (int)(current.size() - current.getDistanceRight() - current.getDistanceLeft())/2);
current.changeY(0);
next =new Block((int)Math.round(Math.random() * 6) + 1);
score += 10;
}
privateboolean testAndAddPiece(Block a, Garbage g){
if(g.testPiece(a)){
int x = g.addPiece(a);
if(x == 4){score += 1200; lines += 4; g.setWave(true, current.getColor(),"12", 42); newPiece();
}elseif(x == 3){score += 600; lines += 3; g.setWave(true, current.getColor(),"5", 35); newPiece();
}elseif(x == 2){score += 200; lines += 2; newPiece();
}elseif(x == 1){score += 50; lines += 1; newPiece();
}elseif(x == -1){score = 0; lines = 0; level = 0;//endGame();
}else newPiece();
if(lines / 10 >= level + 1){ level++;/*g.setWave(true, Color.WHITE, "30", 60);*/}
returntrue;
}
returnfalse;
}
privateboolean moveRight(Block b, Garbage g){
if(b.moveRight(g)){
return g.testPiece(b);
}
returnfalse;
}
privateboolean moveLeft(Block b, Garbage g){
if(b.moveLeft(g)){
return g.testPiece(b);
}
returnfalse;
}
privateboolean testPiece(Block a, Garbage g){
return g.testPiece(a);
}
}
=========================================================
BLOCK CLASS
import java.awt.Color;
import java.awt.Graphics;
publicclass Block{
boolean a[][];
String name;
Color c;
int X;
int Y;
public Block(int aname){
if (aname == 1){
// T PIECE
a =newboolean[3][3];
a[0][1] =true;
a[1][1] =true;
a[2][1] =true;
a[1][2] =true;
c = Color.MAGENTA;
name ="T";
}elseif (aname == 2){
// Z PIECE
a =newboolean[3][3];
a[0][1] =true;
a[1][1] =true;
a[1][2] =true;
a[2][2] =true;
c = Color.RED;
name ="Z";
}elseif (aname == 3){
// BACKWARDS Z PIECE
a =newboolean[3][3];
a[1][1] =true;
a[2][1] =true;
a[0][2] =true;
a[1][2] =true;
c = Color.GREEN;
name ="bZ";
}elseif (aname == 4){
// L PIECE
a =newboolean[3][3];
a[1][0] =true;
a[1][1] =true;
a[1][2] =true;
a[2][2] =true;
c = Color.ORANGE;
name ="L";
}elseif (aname == 5){
// BACKWARDS L PIECE
a =newboolean[3][3];
a[1][0] =true;
a[1][1] =true;
a[1][2] =true;
a[0][2] =true;
c = Color.BLUE;
name ="bL";
}elseif (aname == 6){
// STRAIGHT PIECE
a =newboolean[4][4];
a[2][0] =true;
a[2][1] =true;
a[2][2] =true;
a[2][3] =true;
c = Color.CYAN;
name ="S";
}elseif (aname == 7){
// SQUARE PIECE
a =newboolean[2][2];
a[0][0] =true;
a[0][1] =true;
a[1][0] =true;
a[1][1] =true;
c = Color.YELLOW;
name ="Sq";
}
X=14 + (int)(a.length - getDistanceRight() - getDistanceLeft())/2 ;
Y=4;
}
publicvoid rotateLeft(Garbage g){
boolean copy[][] =newboolean[a.length][a.length];
for (int i = 0; i < a.length; i++){
for (int j = 0; j < a.length; j++){
copy[i][j] = a[i][j];
}
}
for(int x = 0; x < a.length; x++){
for(int y = 0; y < a.length; y++){
a[y][a.length - 1 - x] = copy[x][y];
}
}
}
//Returns TRUE if a piece is added after rotating Right
publicboolean rotateRight(Garbage g){
boolean copy[][] =newboolean[a.length][a.length];
String rotate ="true";
//Copys the Array
for (int i = 0; i < a.length; i++){
for (int j = 0; j < a.length; j++){
copy[i][j] = a[i][j];
}
}
//Rotates Piece & Tests to see if rotated piece is legit
for(int y = 0; y < a.length; y++){
for(int x = 0; x < a.length; x++){
a[x][y] = copy[y][a.length - 1 - x];
if (a[x][y] && rotate.equals("true") && g.getCoordinateValue(X + x,Y + y)){
rotate ="false";
}
}
}
//if (rotate.equals("move")) {
//Moves piece away from RIGHT edge if necessary
if((X + a.length - getDistanceRight()) > 13){
int z = (X + a.length - getDistanceRight()) - 13;
for(int y = 0; y < z; y++){
if(!moveLeft(g)) rotate ="false";
//return g.testPiece(this);
}
}
//Moves piece away from LEFT edge if necessary
if((X + getDistanceLeft()) < 2){
int z = 2 - (X + getDistanceLeft());
for(int y = 0; y < z; y++){
if(!moveRight(g)) rotate ="false";
//return g.testPiece(this);
}
}
//}
//Rotates the piece back if there will be conflicts if rotated.
if (rotate.equals("false") || rotate.equals("abandon")){
for (int i = 0; i < a.length; i++){
for (int j = 0; j < a.length; j++){
a[i][j] = copy[i][j];
}
}
return g.testPiece(this);
}
return g.testPiece(this);
}
publicint getX(){
return X;
}
publicint getY(){
return Y;
}
publicvoid changeX(int eX){
X = eX;
}
publicvoid changeY(int eY){
Y = eY;
}
publicboolean moveLeft(Garbage g){
boolean OK =true;
if (X > 2-getDistanceLeft()){
for(int i = 0; i < a.length - getDistanceBottom(); i++){
for(int j = getDistanceLeft(); j < a.length - getDistanceRight(); j++){
if(a[j][i] && g.getCoordinateValue(X + j - 1, Y + i)){OK =false; j = a.length; i = a.length;}
}
}
if(OK){X--;returntrue;}
}
returnfalse;
}
publicboolean moveRight(Garbage g){
boolean OK =true;
if ( X < (13 + getDistanceRight() - a.length)){
for(int i = 0; i < a.length - getDistanceBottom(); i++){
for(int j = a.length - getDistanceRight() - 1; j >= getDistanceLeft(); j--){
if(a[j][i] && g.getCoordinateValue(X + j + 1, Y + i)){OK =false; j = -1; i = a.length;}
}
}
if(OK){X++;returntrue;}
}
returnfalse;
}
publicvoid moveDown(){
if (Y + a.length - getDistanceBottom() <= 29) Y++;
}
publicvoid moveUp(){
Y--;
}
publicvoid drop(Garbage g){
while(!g.testPiece(this)){
moveDown();
}
}
public Color getColor(){
return c;
}
publicint size(){
return a.length;
}
publicboolean getCoordinateValue(int Ex,int Ey){
return a[Ex][Ey];
}
publicvoid draw(Graphics g){
for(int b = 0; b < a.length; b++){
for(int d = 0; d < a.length; d++){
if(a[b][d]){
g.setColor(c);
g.fillRect(20 * (X + b), 20 * (Y + d), 20, 20);
g.setColor(c.darker());
g.drawRect(20 * (X + b), 20 * (Y + d), 20, 20);
}
}
}
}
publicint getDistanceRight(){
//RETURNS THE DISTANCE FROM THE OUTER SHELL OF THE BLOCK
//TO THE FIRST OCCURANCE OF THE PIECE (FROM THE RIGHT)
int dist = 0;
for (int x = a.length - 1; x >= 0; x--){
for (int y = 0; y < a.length; y++){
if (a[x][y])return (a.length - x - 1);
}
}
return 0;
}
publicint getDistanceLeft(){
//RETURNS THE DISTANCE FROM THE OUTER SHELL OF THE BLOCK
//TO THE FIRST OCCURANCE OF THE PIECE (FROM THE LEFT)
int dist = 0;
for (int x = 0; x < a.length; x++){
for (int y = 0; y < a.length; y++){
if (a[x][y])return x;
}
}
return 0;
}
publicint getDistanceBottom(){
//RETURNS THE DISTANCE FROM THE OUTER SHELL OF THE BLOCK
//TO THE FIRST OCCURANCE OF THE PIECE (FROM THE Bottom)
int dist = 0;
for (int y = a.length - 1; y >= 0; y--){
for (int x = 0; x < a.length; x++){
if (a[x][y])return (a.length - y - 1);
}
}
return 0;
}
}
=========================================================
GARBAGE CLASS
publicclass Garbage{
Color a[][];
/*Color c;
int r;
int g;
int b;
*/int x, waveLength;
LinkedList waves =new LinkedList();
public Garbage(){
a =new Color[30][30];
/*c = Color.BLACK;
r = Math.round((200 - c.getRed()) / 6 - 1);
g = Math.round((200 - c.getGreen()) / 6 - 1);
b = Math.round((200 - c.getBlue()) / 6 - 1);*/
}
publicint refresh(){
for(int x = 0; x < a.length; x++){
for(int y = 0; y < a.length; y++){
a[x][y] =null;
}
}
return -1;
}
publicint addPiece(Block b){
for(int y = b.size() - b.getDistanceBottom() - 1; y >= 0; y--){
for(int x = b.getDistanceLeft(); x < b.size() - b.getDistanceRight(); x++){
if (b.getCoordinateValue(x,y) && a[b.getX() + x][b.getY() + y] ==null){
a[b.getX() + x][b.getY() + y] = b.getColor();
}
}
}
if(a[7][1] !=null)return refresh();
return testLines();
}
publicint[] topRow(){
int c[] =newint[15];
for(int x = 0; x < 15; x++){
int y = 0;
c[x] = 30;
while(y < 30){
if(a[x][y] !=null){
c[x] = y;
y = 30;
}
y++;
}
}
return c;
}
publicint highestGarbage(){
int c[] = topRow();
int y = 30;
for(int x = 0; x < c.length; x++){
if(c[x] < y) y = c[x];
}
return y;
}
publicboolean testPiece(Block b){
if(b.getY() + b.size() - b.getDistanceBottom() >= highestGarbage()){
int c[] = topRow();
for (int i = b.getDistanceLeft(); i <= b.size() - b.getDistanceRight() - 1; i ++){
for (int j = b.size() - b.getDistanceBottom() - 1; j >= 0; j--){
if(b.getY() + b.size() - b.getDistanceBottom() >= 30){
returntrue;
}elseif (b.getCoordinateValue(i, j) && a[b.getX() + i][b.getY() + j + 1] !=null){
returntrue;
}
}
}
}
returnfalse;
}
publicvoid draw(Graphics graphic){
if(waves.size() != 0){
boolean isGray =true;
for(int i = 2; i < 13; i++){
for(int j = 0; j < 30; j++){
if(a[i][j] !=null){
graphic.setColor((Color)a[i][j]);
graphic.fillRect(20 * (i), 20 * (j), 20, 20);
graphic.setColor(a[i][j].darker());
graphic.drawRect(20 * i, 20 * j, 20, 20);
}else{
isGray =true;
for(int k = 0; k < waves.size(); k++){
if(i + j > ((wave)waves.get(k)).getX() && i + j < ((wave)waves.get(k)).getX() + Integer.parseInt(((wave)waves.get(k)).getDistance())){
graphic.setColor(new Color(((wave)waves.get(k)).getColor().getRed()+((wave)waves.get(k)).getRed()*(i+j-((wave)waves.get(k)).getX()),
((wave)waves.get(k)).getColor().getGreen()+((wave)waves.get(k)).getGreen()*(i+j-((wave)waves.get(k)).getX()),
((wave)waves.get(k)).getColor().getBlue()+((wave)waves.get(k)).getBlue()*(i+j-((wave)waves.get(k)).getX())));
isGray =false;
}
}
if(isGray) graphic.setColor(new Color(62,62,62));
graphic.drawRect(20 * i, 20 * j, 20, 20);
}
}
}
for(int k = 0; k < waves.size(); k++){
if(((wave)waves.get(k)).getX() > 0) ((wave)waves.get(k)).Xminus();
else{waves.remove(k);}
}
}else{
for(int i = 2; i < 13; i++){
for(int j = 0; j < 30; j++){
if(a[i][j] !=null){
graphic.setColor((Color)a[i][j]);
graphic.fillRect(20 * (i), 20 * (j), 20, 20);
graphic.setColor(a[i][j].darker());
graphic.drawRect(20 * i, 20 * j, 20, 20);
}
}
}
}
}
publicvoid setWave(boolean t, Color a, String dist,int duration){
wave w =new wave(a, dist, duration);
waves.addLast(w);
}
publicint testLines(){
boolean FullLine =true;
int Lines = 0;
for(int y = a.length - 1; y >= 0; y--){
for(int x = 2; x < 13 ; x++){
if(a[x][y] ==null) FullLine =false;
}
if (FullLine){
for(int b = y; b > 0; b--){
for(int c = 2; c < 15; c++){
a[c][b] = a[c][b - 1];
}
}
Lines++;
y++;
}
FullLine =true;
}
return Lines;
}
publicboolean getCoordinateValue(int x,int y){
if(a[x][y] !=null)returntrue;
elsereturnfalse;
}
publicclass wave{
Color c;
String distance;
int redOffset;
int greenOffset;
int blueOffset;
int xOffset;
public wave(Color a, String b,int duration){
c = a;
distance = b;
int dist = Integer.parseInt(b);
redOffset = (int)((62 - a.getRed()) / dist + 1) - 1;
greenOffset = (int)((62 - a.getGreen()) / dist + 1) - 1;
blueOffset = (int)((62 - a.getBlue()) / dist + 1) - 1;
xOffset = duration;
}
public Color getColor(){
return c;
}
public String getDistance(){
return distance;
}
publicint getRed(){
return redOffset;
}
publicint getGreen(){
return greenOffset;
}
publicint getBlue(){
return blueOffset;
}
publicint getX(){
return xOffset;
}
publicvoid Xminus(){
xOffset--;
}
}
}
well, that's all of it... I hope someone can make sense of this and hopefully get back to me with a solution.
Thanks in advance,
Doug.

