Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-29-2012, 10:19 AM   PM User | #1
jdruwe
New Coder

 
Join Date: Nov 2011
Posts: 31
Thanks: 8
Thanked 0 Times in 0 Posts
jdruwe is an unknown quantity at this point
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!
jdruwe is offline   Reply With Quote
Old 02-29-2012, 02:47 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 03-01-2012, 10:15 AM   PM User | #3
jdruwe
New Coder

 
Join Date: Nov 2011
Posts: 31
Thanks: 8
Thanked 0 Times in 0 Posts
jdruwe is an unknown quantity at this point
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."
jdruwe is offline   Reply With Quote
Old 03-01-2012, 01:41 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
jdruwe (03-01-2012)
Old 03-01-2012, 03:53 PM   PM User | #5
jdruwe
New Coder

 
Join Date: Nov 2011
Posts: 31
Thanks: 8
Thanked 0 Times in 0 Posts
jdruwe is an unknown quantity at this point
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..
jdruwe is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:13 AM.


Advertisement
Log in to turn off these ads.