• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Battleships - guys please help me out!

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey everyone

I posted the program three times already - each time with great help: thanks. But I really need you guys to help me out NOW. I have created a simple BattleShips program, consisting of a 2X2 array, with 10 spaces. It displays the board, with the column number (char) above it and the row number (int) next to it. The program works just fine as it is, but I really want to add some GUI to it. I have imported GridLayout - java.awt - (if you run the class you will see how it looks) but I don't know how to implement it into my BattleShips.

I basically need to shadow the spaces of the array (whether it contains a value or not) with GridLayout to allow the user to click on the space to show the value of the array.

A miss (or blank space) = 'M' and all other values (ship, battleship, aircraft carrier) = 'X' (for a hit).

Guys I really need you to help me out with it. Can anybody place GridLayout over the spaces of the array?

Thanks. The code follows:



 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First the Main program when hitting just Enter and no Column at the Column prompt you will get an Exception



Mark
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The other program that is an Applet, displays all the Buttons in the Applet window. But since you used GridLayout you can only have the Grid in the display, not Text or other Stuff, now you could nest Layouts like BorderLayout, and put a Panel with the GridLayout in that and place it in the center, and use North and South for other Panels for text and other stuff.

I'd read up on Swing and also not use an Applet.

Mark
 
PI day is 3.14 (march 14th) and is also einstein's birthday. And this is merely a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic