Results 1 to 3 of 3
- 11-08-2010, 12:19 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 2
- Rep Power
- 0
how to fill and show an array with graphic components?
I'm trying to program tetris, as I don't have that much experience I'm thinking of starting primitively.
My Idea is a board(which is an array) filled with blanks and figure square(for the time being, there is only one figure square which contains of 1 block of 50x50) put in a loop refreshing the y coord of the figure square +1.
I want to fill a 2d array with this BlankSquareComponent(which is just a grey filled 50x50 rectangle I made.
Now I know how to make a array board using empty spaces with the String class but I'm quite lost on how to do this. Is this possible and how should I do this?
Thanks in advance
here is the code so far...
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JComponent;
public class TetrisBoard extends JComponent
{
private BlankSquareComponent [][] board;
private BlankSquareComponent BlankSquareComponent;
private static final int ROWS = 15;
private static final int COLUMNS = 5;
public TetrisBoard()
{
board = new BlankSquareComponent[ROWS][COLUMNS];
for (int i = 0; i < ROWS; i++ )
for(int j = 0; j < COLUMNS; j++)
board[i][j] = BlankSquareComponent;
}
//I should have a paintComponent, but no idea what to do with it :/
}
- 11-08-2010, 12:46 AM #2
Senior Member
- Join Date
- May 2010
- Posts
- 436
- Rep Power
- 4
I don't think that this is going to be a simple exercise, and I would suggest that you separate out the model/logic portion of the code into its own set of class and the the GUI code into another set of classes, that you solve the model code first, simply and then work on the GUI portion. Doing it this way will help immensely later when you want to upgrade your code with increased complexity. Also, have you read the Swing graphics or 2D graphics tutorials yet? If not, you'll probably want to before tackling this.
- 11-08-2010, 09:19 AM #3
Member
- Join Date
- Nov 2010
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Window needs to be re-sized to show components?
By mbutler755 in forum AWT / SwingReplies: 2Last Post: 10-09-2010, 01:18 AM -
fill object of array with char
By begginer12 in forum New To JavaReplies: 1Last Post: 12-05-2009, 02:11 AM -
(Trying to) fill HSB (Hue|Saturation|Brightness) array
By courteous in forum New To JavaReplies: 1Last Post: 01-19-2009, 07:49 AM -
Using reflection to create, fill, and display an array
By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 08:15 PM -
Array Fill Test
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:45 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks