Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Bidimensional array to GUI?

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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!
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic