| |

|
|
|
 |
|
 |
| |
12-16-2007, 10:35 PM
|
#1
|
|
Do you know where my Papi is?
Join Date: Jan 2007
Location: thanks for the help on the paper! go to labor/employment section to read it
Age: 5
Posts: 3,877
|
soooo.....anyone here know java?
I'm having mucho problems with my project in java right now....
I never learned the nuances of how to debug a KeyListener....
anyone know how to program in java, or I ought to debug a key listener?
(code will be posted if asked)
|
The ignorant ask "what is my effect on the world?"
The enlightened ask "What does the world know about itself?"
The Bear
I am The Bear
The Bear
|
|
|
Today
|
|
|
|
Sponsored Links
__________________
Tell Your Friends About Ballot.com!
|
|
|
|
12-16-2007, 11:36 PM
|
#2
|
|
Question, what is it that everybody has, and some pirates and theives try to take....
Join Date: Mar 2007
Location: Googling Kanada. Did you mean Canada?
Age: 25
Posts: 5,143
|
Re: soooo.....anyone here know java?
look anything like this?...
public class KeyHandler implements KeyListener
{
public void keyPressed(KeyEvent event)
{
switch (event.getKeyCode())
{
case KeyEvent.VK_LEFT:
case KeyEvent.VK_RIGHT:
}
}
}
|
|
|
|
|
12-16-2007, 11:50 PM
|
#3
|
|
Do you know where my Papi is?
Join Date: Jan 2007
Location: thanks for the help on the paper! go to labor/employment section to read it
Age: 5
Posts: 3,877
|
Re: soooo.....anyone here know java?
yes that's precisely what it looks like.
the problem is that it does absolutely nothing!
|
The ignorant ask "what is my effect on the world?"
The enlightened ask "What does the world know about itself?"
The Bear
I am The Bear
The Bear
|
|
|
12-16-2007, 11:53 PM
|
#4
|
|
Moderator
Staff
Join Date: Feb 2007
Posts: 7,315
|
Re: soooo.....anyone here know java?
I hate Java so much, but its a love hate relationship.
I know many languages but Java is only something I've messed with, ie downloading a .js and reverse engineering it or altering the parameters to my liking.
But I've never built anything from the raw.
I got into Flash because it was supposed to replace Java, boy were they wrong on that.
|
American People 08'
|
|
|
12-16-2007, 11:54 PM
|
#5
|
|
Do you know where my Papi is?
Join Date: Jan 2007
Location: thanks for the help on the paper! go to labor/employment section to read it
Age: 5
Posts: 3,877
|
Re: soooo.....anyone here know java?
lol ahah flash replace java?!
|
The ignorant ask "what is my effect on the world?"
The enlightened ask "What does the world know about itself?"
The Bear
I am The Bear
The Bear
|
|
|
12-16-2007, 11:54 PM
|
#6
|
|
Moderator
Staff
Join Date: Feb 2007
Posts: 7,315
|
Re: soooo.....anyone here know java?
Quote:
Originally Posted by The_Bear
lol ahah flash replace java?!
|
Yeah little did they understand, this is of course way back when Macromedia was emerging onto 'tha scene.'
|
American People 08'
|
|
|
12-16-2007, 11:56 PM
|
#7
|
|
Moderator
Staff
Join Date: Feb 2007
Posts: 7,315
|
Re: soooo.....anyone here know java?
Oh btw, I didn't get to read your paper in full as you had requested. I did want to and I even have it bookmarked, I will do so tonight.
|
American People 08'
|
|
|
12-16-2007, 11:58 PM
|
#8
|
|
Do you know where my Papi is?
Join Date: Jan 2007
Location: thanks for the help on the paper! go to labor/employment section to read it
Age: 5
Posts: 3,877
|
Re: soooo.....anyone here know java?
here's the code if anyone cares:
The MAIN class
Code:
import java.awt.* ;
import java.awt.event.* ;
import javax.swing.* ;
import java.awt.font.* ;
import java.awt.geom.* ;
public class project3{
public static void main(String[] args)
{
JFrame window = new JFrame();
window.setTitle("Tetris");
commenceGame begin = new commenceGame();
begin.setFocusable(true);
begin.init();
begin.startAnimation();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setFocusable(true);
window.getContentPane().add(begin);
window.pack();
window.setVisible( true );
}}
Pieces - does the matrix manipulation
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Pieces{
public int x;
public int y;
public int cross[][] = {{1,1,1},
{0,1,0}};
private int leftL[][] = {{2,2,2},
{2,0,0}};
private int rightL[][] = {{3,3,3},
{0,0,3}};
private int leftS[][] = {{0,4,4},
{4,4,0}};
private int rightS[][] = {{5,5,0},
{0,5,5}};
private int square[][] = {{6,6},
{6,6}};
private int tetris[][]= {{7,7,7,7}};
private int blankSquare[][] ={{0}};
public int startPlaceY;
public int startPlaceX;
public int shape;
public int replacement_board[][];
public Pieces()
{
x = 0;
y = 1;
startPlaceX = 4;
startPlaceY = 0;
shape = (int)(Math.random()*7);
replacement_board = new int[20][10];
}
public int[][] drawIt(int[][]temp2_board, boolean por)
{
//1
//temp2_board = replacement_board;
makeTetris(temp2_board);
//if(por) makeCross(temp2_board);//2
// temp2_board = replacement_board;
// else reMakeCross(replacement_board);
/* switch(shape)
{
case 0:
makeCross(temp2_board);
break;
case 1:
makeLeftL(temp2_board);
break;
case 2:
makeRightL(temp2_board);
break;
case 3:
makeLeftS(temp2_board);
break;
case 4:
makeRightS(temp2_board);
break;
case 5:
makeSquare(temp2_board);
break;
case 6:
makeTetris(temp2_board);
break;
}
*/
return temp2_board;
}
public int[][] makeCross(int[][]temp)
{
replacement_board= temp;
for(int i=0;i<temp.length;i++)
{
for(int j = 0;j<temp[0].length;j++)
{
temp[i][j] = 0;
}
}
int color;
for(int i = 0;i<2;i++)
{
for(int j = 0;j<3;j++)
{
color = cross[i][j];
temp[startPlaceX+i][startPlaceY+j] = color;
}
}
return(temp);
}
//this method is designed to take the initial condition and create the new matrix
public int[][] makeLeftL(int[][]temp)
{
for(int i=0;i<temp.length;i++)
{
for(int j = 0;j<temp[0].length;j++)
{
temp[i][j] = 0;
}
}
int color;
for(int i = 0;i<2;i++)
{
for(int j = 0;j<3;j++)
{
color = leftL[i][j];
temp[startPlaceX+i][startPlaceY+j] = color;
}
}
return temp;
}
public int[][] makeRightL(int[][]temp)
{
for(int i=0;i<temp.length;i++)
{
for(int j = 0;j<temp[0].length;j++)
{
temp[i][j] = 0;
}
}
int color;
for(int i = 0;i<2;i++)
{
for(int j = 0;j<3;j++)
{
color = rightL[i][j];
temp[startPlaceX+i][startPlaceY+j] = color;
}
}
return temp;
}
public int[][] makeLeftS(int[][]temp)
{
for(int i=0;i<temp.length;i++)
{
for(int j = 0;j<temp[0].length;j++)
{
temp[i][j] = 0;
}
}
int color;
for(int i = 0;i<2;i++)
{
for(int j = 0;j<3;j++)
{
color = leftS[i][j];
temp[startPlaceX+i][startPlaceY+j] = color;
}
}
return temp;
}
public int[][] makeRightS(int[][]temp)
{
for(int i=0;i<temp.length;i++)
{
for(int j = 0;j<temp[0].length;j++)
{
temp[i][j] = 0;
}
}
int color;
for(int i = 0;i<2;i++)
{
for(int j = 0;j<3;j++)
{
color = rightS[i][j];
temp[startPlaceX+i][startPlaceY+j] = color;
}
}
return temp;
}
public int[][] makeSquare(int[][]temp)
{
for(int i=0;i<temp.length;i++)
{
for(int j = 0;j<temp[0].length;j++)
{
temp[i][j] = 0;
}
}
int color;
for(int i = 0;i<2;i++)
{
for(int j = 0;j<2;j++)
{
color = square[i][j];
temp[startPlaceX+i][startPlaceY+j] = color;
}
}
return temp;
}
public int[][] makeTetris(int[][]temp)
{
for(int i=0;i<temp.length;i++)
{
for(int j = 0;j<temp[0].length;j++)
{
temp[i][j] = 0;
}
}
int color;
for(int i = 0;i<4;i++)
{
for(int j = 0;j<1;j++)
{
color = tetris[j][i];
temp[startPlaceX+i][startPlaceY+j] = color;
}
}
return temp;
}
public int[][] makeBlankSquare(int[][]temp, boolean check)
{
int color;
for(int i = 0;i<1;i++)
{
for(int j = 0;j<1;j++)
{
if(check) color = blankSquare[i][j];
else color = 0;
temp[startPlaceX+i][startPlaceY+j] = color;
}
}
return temp;
}
public void moveDown(int[][]board)
{
//startPlaceY++;
startPlaceY++;
replacement_board = board;
System.out.println(startPlaceY);
//temp[startPlaceX+i][startPlaceY+j] = color;
/*
replacement_board = board;
if(board[startPlaceY][startPlaceX] &&
board[startPlaceY+1][startPlaceX] &&
board[startPlaceY-1][startPlaceX] &&
board[startPlaceY][startPlaceX+1] &&
board[i][j]==1) board[i][j]=0;
for(int i=0;i<board.length;i++)
{
for(int j = 0;j<board[0].length;j++)
{
System.out.print(board[i][j] + " ");
}
System.out.println();
}
System.out.println();
*/
//System.out.println(startPlaceY);
//makeCross(board);
//return replacement_board;
}
public void moveXLeft(int [][]temp)
{
startPlaceX--;
//startPlaceY+= change;
}
public void moveXRight(int [][]temp)
{
startPlaceX++;
makeCross(replacement_board);
//startPlaceY+= change;
}
public int[][] killLiving(int[][]temp)
{
for(int i = 0;i<temp.length;i++)
{
for(int j = 0;j<temp[0].length;j++)
{
if(temp[i][j]!= 0)
{
temp[i][j] = -1;
}
}
}
return temp;
}
}
|
The ignorant ask "what is my effect on the world?"
The enlightened ask "What does the world know about itself?"
The Bear
I am The Bear
The Bear
|
|
|
12-16-2007, 11:59 PM
|
#9
|
|
Do you know where my Papi is?
Join Date: Jan 2007
Location: thanks for the help on the paper! go to labor/employment section to read it
Age: 5
Posts: 3,877
|
Re: soooo.....anyone here know java?
commenceGame - does the outputing
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class commenceGame extends JPanel
{
public int x;//starting x location of block
public int y;//starting y location of block
public int width;//width of block
public int height;//height of block
public int board[][];
/*{{-1,-1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1},
{-1,-1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1}};//game play board*/
public int temp_storage_board[][];
public int xBoard;//width of board matrix
public int yBoard;//height of board matrix
public Timer animationTimer;
public int ANIMATION_DELAY;
Pieces piece1;//the piece that gets modified
Pieces piece2;//the piece that is the result of the modification
public commenceGame()
{
xBoard = 10;
yBoard = 20;
width = 40;
height = 40;
x = 5;
y = 0;
board = new int[xBoard][yBoard];
//this is the board where pieces appear
temp_storage_board = new int[xBoard][yBoard];//this is the main board
piece1 = new Pieces();
piece1.drawIt(board, true);
// piece2 = new Pieces();
// piece2.drawIt(board, false);
ANIMATION_DELAY = 500;
}
public void init()
{
JPanel panel = new beginGame();
add(panel);
}
public class beginGame extends JPanel
{
public beginGame()
{
setPreferredSize(new Dimension(400,800));
setBackground(Color.white);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
temp_storage_board = board;
for (int i = 0 ; i < xBoard; i++)
{
for (int j = 0 ; j < yBoard; j++)
{
if(temp_storage_board[i][j] == 1) drawCross(g2, i, j);
else if(temp_storage_board[i][j] == 2) drawLeftL(g2, i, j);
else if(temp_storage_board[i][j] == 3) drawRightL(g2, i, j);
else if(temp_storage_board[i][j] == 4) drawLeftS(g2, i, j);
else if(temp_storage_board[i][j] == 5) drawRightS(g2, i, j);
else if(temp_storage_board[i][j] == 6) drawSquare(g2, i, j);
else if(temp_storage_board[i][j] == 7) drawTetris(g2, i, j);
else if(temp_storage_board[i][j] == -1) drawDeadSquare(g2, i, j);
}
}
}
public void drawCross(Graphics2D g2, int x, int y)
{
// piece1.makeCross(board, true);
g2.setColor(Color.red);
g2.fillRect(x*width,y*height,width,height);
g2.setColor(Color.black);
g2.drawRect(x*width,y*height,width,height);
}
//else if (board[i][x] == 2)
public void drawLeftL(Graphics2D g2, int x, int y)
{
// piece1.makeLeftL(board, true);
g2.setColor(Color.red);
g2.fillRect(x*width,y*height,width,height);
g2.setColor(Color.black);
g2.drawRect(x*width,y*height,width,height);
}
//else if (board[i][x] == 3)
public void drawRightL(Graphics2D g2, int x, int y)
{
// piece1.makeRightL(board, true);
g2.setColor(Color.cyan);
g2.fillRect(x*width,y*height,width,height);
g2.setColor(Color.black);
g2.drawRect(x*width,y*height,width,height);
}
//else if (board[i][x] == 4)
public void drawLeftS(Graphics2D g2, int x, int y)
{
// piece1.makeLeftS(board, true);
g2.setColor(Color.orange);
g2.fillRect(x*width,y*height,width,height);
g2.setColor(Color.black);
g2.drawRect(x*width,y*height,width,height);
}
//else if (board[i][x] == 5)
public void drawRightS(Graphics2D g2, int x, int y)
{
// piece1.makeRightS(board, true);
g2.setColor(Color.yellow);
g2.fillRect(x*width,y*height,width,height);
g2.setColor(Color.black);
g2.drawRect(x*width,y*height,width,height);
}
//else if (board[i][x] == 6)
public void drawSquare(Graphics2D g2, int x, int y)
{
// piece1.makeSquare(board, true);
g2.setColor(Color.blue);
g2.fillRect(x*width,y*height,width,height);
g2.setColor(Color.black);
g2.drawRect(x*width,y*height,width,height);
}
//else if (board[i][x] == 7)
public void drawTetris(Graphics2D g2, int x, int y)
{
// piece1.makeTetris(board, true);
g2.setColor(Color.green);
g2.fillRect(x*width,y*height,width,height);
g2.setColor(Color.black);
g2.drawRect(x*width,y*height,width,height);
}
// else if (board[i][x] == 0)
public void drawBlankSquare(Graphics2D g2, int x, int y)
{
// piece1.makeBlankSquare(board, true);
g2.setColor(Color.white);
g2.fillRect(x*width,y*height,width,height);
}
//else if (board[i][x] == -1)
public void drawDeadSquare(Graphics2D g2, int x, int y)
{
// piece1.makeDeadSquare(board, true);
g2.setColor(Color.gray);
g2.fillRect(x*width,y*height,width,height);
}
}
public void startAnimation()
{
if (animationTimer == null)
{
animationTimer = new Timer(ANIMATION_DELAY, new TimerHandler());
animationTimer.start();
}
else
{
if (!animationTimer.isRunning())
animationTimer.restart();
}
}
public class TimerHandler implements ActionListener
{
public void actionPerformed(ActionEvent actionEvent)
{
// System.out.println("aP");
piece1.moveDown(board);
// piece1.moveXLeft(board);
piece1.drawIt(board, true);
repaint();
if (piece1.startPlaceY> 20)
piece1.killLiving(board);
//y += size;
//if (y > height) y = 10;
}
public class KeyHandler implements KeyListener
{
public void keyPressed(KeyEvent event)
{
switch (event.getKeyCode())
{
case KeyEvent.VK_LEFT:
piece1.moveXLeft(board);
//x -= size;
break;
case KeyEvent.VK_RIGHT:
piece1.moveXRight(board);
//x += size;
break;
}
repaint();
}
public void keyReleased(KeyEvent event) {}
public void keyTyped(KeyEvent event) {}
}
}
}
@ tengig - look at the syntax of my keylistener. Its at the bottom of this function.
it does nothing.
It doesn't move left or right, despite the fact that I know the function that it calls will move it left or right.
|
The ignorant ask "what is my effect on the world?"
The enlightened ask "What does the world know about itself?"
The Bear
I am The Bear
The Bear
|
|
|
12-17-2007, 12:00 AM
|
#10
|
|
Do you know where my Papi is?
Join Date: Jan 2007
Location: thanks for the help on the paper! go to labor/employment section to read it
Age: 5
Posts: 3,877
|
Re: soooo.....anyone here know java?
Quote:
Originally Posted by johnflesh
Oh btw, I didn't get to read your paper in full as you had requested. I did want to and I even have it bookmarked, I will do so tonight.
|
take your time.
I've handed in both the papers.
I think the one I wrote about the NRA as well as the one I wrote about the welfare reform debate of 1995 were good papers.
If you wanna read em, yell, and I'll come running.
|
The ignorant ask "what is my effect on the world?"
The enlightened ask "What does the world know about itself?"
The Bear
I am The Bear
The Bear
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
| |