Image in an application

I hit a road block. . .

Page 1 of 1

2 Replies - 1726 Views - Last Post: 16 September 2005 - 07:57 PM Rate Topic: -----

#1 Jeda  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 21-June 05

Image in an application

Post icon  Posted 31 August 2005 - 07:01 AM

I am trying to create a simple TicTacToe in an application and I came upon a road block. I created a test to see if where I clicked something came up, so I created a drawString. It works, my problem is trying to get an X in the first box using drawImage. From there I could probably figure out the rest.

I researched in two Java programming books: One by Annita Millspaugh and the other by Harvy & Paul Deitel. The Deitel book help me a great deal, but as I mentioned I am now against a brick wall.

I have attached what I have and put comments in where I could use the help.

In an applet, URL can be used. How, if possible, can URL be used in an application.

I might try to use an array, once I figure out how to use it. I know how to create an array, just need to think on how I would like to use it.

I will not lie, this is a final project that must be done before Sept. 20. I just need a little insight on how to get the place where I click to show the image and tell it whether it has been played or not. I have an image in the first square, but when I click the square next to it or below it the image disappears.

After that is done, I must figure out how to make Player One and Player Two switch back and forth depending on the turn. Okay, well, that was to much information. . .sorry.

If I fail this time--which will be my third time--I will not go back and take it agian and I will GIVE UP on Java completely.

Thanks for all the help.

Attached File(s)


This post has been edited by Jeda: 14 September 2005 - 07:04 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Image in an application

#2 1lacca  Icon User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: Image in an application

Posted 06 September 2005 - 09:54 AM

I am not sure if it was part of your assignment to use drawing and so on, but you can solve this problem in a very simple way:
Create a JPanel with a 3x3 GridLayout. Put a JButton into each cell. With this, you have avoided the problem of dealing with mouse coordinates, as you can simply use the actions of the buttons to determine which position was clicked, and also the drawing part is simple, as you can easily set the icon (image) displayed by the buttons.
As you have mentioned using an array to store the state of the game is the way to go.

If it is part of the assignment to use drawing, mouse listeners, etc., then dont draw onto the (J)Frame, but create a Canvas and also attach the mouselistener to it, as dealing with the coordinates is much easier... Also check the Graphics classes in the API, or google for a tutorial on them.
Was This Post Helpful? 0
  • +
  • -

#3 Drift-O-Manaic  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 83
  • Joined: 19-August 05

Re: Image in an application

Posted 16 September 2005 - 07:57 PM

If you are making an application and want to put put an image in it the easiest way that i have found to do so is by using Visual J++. In J++ you can easily make windows applications and if you switch the form editor to Visual Basic you can put picture boxes on your form. If you can get your hands on J++ it will make you life so much easier.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1