How to display a matrix graphically?

Asked

Viewed 1,157 times

2

I have a matrix Tabuleiro[][] tabuleiro = New Tabuleiro[20][20].

It contains objects from a class not yet implemented, which will have some values, such as cell color and a position marker.

I would like to know if it is possible to display this matrix graphically, for example the fields of the board, as follows:

inserir a descrição da imagem aqui

That is, that graphically represent this matrix, in a very basic way.

  • 2

    Welcome to the OS in English! Visit the Help Center (http://answall.com/help) to learn more about how to ask questions! As you put it, your question is very broad, and a simple "Yes, it is possible" would answer it but would obviously leave you unsatisfied. Be more specific about your problem and show us what you tried so we can help you better.

  • The point is that I don’t know anything about a graphical interface. And I wanted to know an easy method to represent this table graphically.

  • So, Eduardo, as the colleague has already commented your question is very wide. There are several ways to draw something similar. An image, by the way, is still a two-dimensional matrix of pixels. I suggest you edit the question to at least provide more information about what should be "drawn" at each position of your matrix (where is the code of the "Board" class?). Also, if you "know nothing" of graphical interface, it will not be with an issue that your doubts will all be solved. How about starting with something simpler, and posting your doubts here slowly? :)

  • You can, for example, try to draw a unit of this class: http://zetcode.com/gfx/java2d/basicdrawing/

1 answer

1

Can you create a panel and set its size, for example 50x50.

Then you make a loop within another loop, to be able to make the rows and columns of the matrix and creates for each position a panel new.

for(int i = 0; i<n_linhas;i++){
   for(int j=0; i<n_colunas;j++){
       //cria um novo panel, define borda,tamanho,posição inicial
}

The initial position of panel, you take into account the size you set, and the size of each panel. Then you set the starting position to be width: i*height,j*width.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.