Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    31
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Displaying an array in a Jpanel

    Hello

    I am developing a game called "Angry Tank", 2 tanks on a landscape trying to destroy eachother as fast as possible. At the moment its only playable in the console. I am adding a GUI but i have no idea how to display my landscape (stored in an array). A friend of mine advised me to use a Jlabel for each coordinate but that would require 2600 Jlabels (+ adding them on a Jpanel) , I think there more efficient ways. Pls some suggestions.

    Thanks in advance!

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Why not use a JTable instead? It renders like that of a grid which sounds to be what you are looking to do, and will let you modify what you need at any time. Can be listened and reacted too as well.
    That assumes a matrix style layout is what you are looking for.

  • #3
    New Coder
    Join Date
    Nov 2011
    Posts
    31
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Why not use a JTable instead? It renders like that of a grid which sounds to be what you are looking to do, and will let you modify what you need at any time. Can be listened and reacted too as well.
    That assumes a matrix style layout is what you are looking for.
    Ok i will try this on another forum they suggested this "Look at using a JPanel as an area to draw on. Override the paintComponent method and draw your shapes there."

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by jdruwe View Post
    Ok i will try this on another forum they suggested this "Look at using a JPanel as an area to draw on. Override the paintComponent method and draw your shapes there."
    Yes, a draw would also be fine, but it just comes down to what you need.
    If the game style is like that of say minesweeper, or tic-tac-toe then a jtable or matrix of buttons, panels, etc, make the most sense. If its moving something from 0,0 to 10,2 then drawing may make more sense.
    End result you can do either with both approaches. I assumed that a matrix of components made more sense since I thought that the Array is a requirement for landscape. If its just to track coordinate, then I'd say that drawing will be easier.

  • Users who have thanked Fou-Lu for this post:

    jdruwe (03-01-2012)

  • #5
    New Coder
    Join Date
    Nov 2011
    Posts
    31
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Yes, a draw would also be fine, but it just comes down to what you need.
    If the game style is like that of say minesweeper, or tic-tac-toe then a jtable or matrix of buttons, panels, etc, make the most sense. If its moving something from 0,0 to 10,2 then drawing may make more sense.
    End result you can do either with both approaches. I assumed that a matrix of components made more sense since I thought that the Array is a requirement for landscape. If its just to track coordinate, then I'd say that drawing will be easier.
    The array contains elements (landscape element "x", air element " ", tank element "A" or "B" and a shot element "°")
    I need exact coordinates they will never be decimal ^^ cause i round my shot results, so i guess a jtabel makes more sense. But if i need a jlabel or something else for each coordinate i need 2600 of them xD (landscape: 26*100) and they advised me not to do for a better maintenance
    Last edited by jdruwe; 03-01-2012 at 03:57 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
    •