Results 1 to 3 of 3
  1. #1
    randomjavaguy is offline Member
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Unhappy 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 :/

    }

  2. #2
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    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.

  3. #3
    randomjavaguy is offline Member
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Default

    Quote Originally Posted by curmudgeon View Post
    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.
    MY text book covered a small proportion of the 2d graphics, like how to make different shapes, colors, line thickness etc but that's pretty much it. As for swing, it only covered javax.swing.JComponent....

Similar Threads

  1. Window needs to be re-sized to show components?
    By mbutler755 in forum AWT / Swing
    Replies: 2
    Last Post: 10-09-2010, 02:18 AM
  2. fill object of array with char
    By begginer12 in forum New To Java
    Replies: 1
    Last Post: 12-05-2009, 03:11 AM
  3. (Trying to) fill HSB (Hue|Saturation|Brightness) array
    By courteous in forum New To Java
    Replies: 1
    Last Post: 01-19-2009, 08:49 AM
  4. Replies: 0
    Last Post: 04-23-2008, 09:15 PM
  5. Array Fill Test
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 09:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •