A few questions...

S

Si

I have to design a small game which features a grid of clickable squares. I
have already written most of the code and I just need to implement this in a
GUI.

- What is the best object to use which would allow the visible content of a
square to change (possibly an image/text) when clicked? How would I do this?
Are buttons my only option?

- How do I put an image on a button?

- How do I display images in a Java GUI (e.g. a GIF or JPEG)?

- How would I write and retreive game scores to and from an XML file?

Sorry for the basic questions, but I'm very new to Java GUIs.

TIA.
 
J

jonathanmcdougall

I have to design a small game which features a grid of clickable squares.
I
have already written most of the code and I just need to implement this in a
GUI.

- What is the best object to use which would allow the visible content of a
square to change (possibly an image/text) when clicked? How would I do this?
Are buttons my only option?

JButton's could do, but also JLabel's (with mouse listener) or, at worst, a
subclass of JComponent that you would make yourself.
- How do I put an image on a button?

Look up JButton.JButton() and JAbstractButton.setIcon().
- How do I display images in a Java GUI (e.g. a GIF or JPEG)?

Look up JLabel and ImageIcon.
- How would I write and retreive game scores to and from an XML file?

Write your own parser or google for something like 'xml java'. Personnaly,
I often used JDOM (www.jdom.org).


Jonathan
 
R

Roedy Green

- What is the best object to use which would allow the visible content of a
square to change (possibly an image/text) when clicked? How would I do this?
Are buttons my only option?

The other option is a Canvas in AWT or JPanel in Swing with a custom
paint method.

Any component can detect being clicked if you hook in at the right
place.

The simplest conceptually for what you are doing would be a grid of
buttons with images implanted on them. Only if that is too slow
should you worry about something else.

When you do your own canvas you can use division to figure out which
square was clicked from the co-ordinates within the whole component,
rather than testing each square in turn the way AWT would do it with
buttons.
 
G

Gregory A. Swarthout

Si said:
I have to design a small game which features a grid of clickable squares. I
have already written most of the code and I just need to implement this in a
GUI.

- What is the best object to use which would allow the visible content of a
square to change (possibly an image/text) when clicked? How would I do this?
Are buttons my only option?

- How do I put an image on a button?

- How do I display images in a Java GUI (e.g. a GIF or JPEG)?

- How would I write and retreive game scores to and from an XML file?

Sorry for the basic questions, but I'm very new to Java GUIs.

TIA.

Do your own homework.
 
T

Thomas J. Clancy

Read your javadocs. It's all there. :)

Si said:
I have to design a small game which features a grid of clickable squares. I
have already written most of the code and I just need to implement this in a
GUI.

- What is the best object to use which would allow the visible content of a
square to change (possibly an image/text) when clicked? How would I do this?
Are buttons my only option?

- How do I put an image on a button?

- How do I display images in a Java GUI (e.g. a GIF or JPEG)?

- How would I write and retreive game scores to and from an XML file?

Sorry for the basic questions, but I'm very new to Java GUIs.

TIA.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top