File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Bidimensional array to GUI? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Bidimensional array to GUI?" Watch "Bidimensional array to GUI?" New topic
Author

Bidimensional array to GUI?

Frank Ramirez
Greenhorn

Joined: Feb 12, 2010
Posts: 17
Hello eveyone
I'm working on a school project.
It is basically a maze. I have to read it from a file and create a bidimensional array with the data from the file.
I already have my bidimensional array. Now I'm trin to go a little bit extra. I want to create a GUI that displays my maze. I have a method to populate my array from the txt file. Here it is:


Is there any way that I can create some kind of GUI based in the data I get from this method? I was thinking on something like "Minesweeper" where the maze will be hidden and then the player has to go guession on all the little buttons.
Is it possible? Can anybody point me in the right direction to do this?

Thanks
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Sure, there are many ways to represent a 2-dimensional array in a GUI. I'd consider the array to be part of the "model", which is part of the program logic and this code should not change, or only change minimally, if used with another GUI library. As a simple example, here's a small bit of code I created to help demo a similar set up (kind of like a very simplistic BattleShip game). In this code, the model that holds the 2-D array is called MyGridModel:



Feel free to ask any questions if this doesn't make sense.
Frank Ramirez
Greenhorn

Joined: Feb 12, 2010
Posts: 17
Thank you for your answer. I'm studying your code, it totally makes sense and will be a great reference to follow in my maze. Now I have another question:
I have a very little experience with GUI. I have always played in NetBeans with the Design view in JFrames and graphically added and removed buttons, field texts, etc. Is there any way to do that with this code? I mean, when I used JFrames, there is always code automatically generated that I can't change, but I can use the Design view to play with it using NetBeans. I'd like to use the design mode to add some buttons, etc.
Thanks again, you have been very helpful
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Frank Ramirez wrote:Thank you for your answer. I'm studying your code, it totally makes sense and will be a great reference to follow in my maze. Now I have another question:
I have a very little experience with GUI. I have always played in NetBeans with the Design view in JFrames and graphically added and removed buttons, field texts, etc. Is there any way to do that with this code? I mean, when I used JFrames, there is always code automatically generated that I can't change, but I can use the Design view to play with it using NetBeans. I'd like to use the design mode to add some buttons, etc.
Thanks again, you have been very helpful


My advice is to toss out the design view and learn to code Swing by hand using the Sun Swing tutorials as a guide. Then later you can apply this understanding to NetBeans generated code, sure, but first learn the basics. Much luck!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bidimensional array to GUI?