aspose file tools
The moose likes Beginning Java and the fly likes Problem with Switch statements! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with Switch statements!" Watch "Problem with Switch statements!" New topic

Problem with Switch statements!

Thijs Haitjema

Joined: Sep 27, 2003
Posts: 1
I have to make some applets for school with a dice. If the comuter makes me a number with math.random I want to show a picture of a dice with that number of dots on it. but I don't know how to work with a Switch statement. and where I have to put them in my applet?( under the init() stuff or where else?)
So I would appreciate it if you would help me.
Thijs Haitjema
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24189

Welcome to JavaRanch!
Sun's online Java Tutorial has a section on applets which would help you understand how applets are put together, and what the "init" and "start" methods are for.
As far as random numbers goes, to get a random number from 0 to 5, inclusive (six different possibilities), you could use the java.util.Random class:

You could then use this number as an index into an array of Image objects.

[Jess in Action][AskingGoodQuestions]
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9056
Here is a page from the JavaRanch Cattle Drive that may help you understand switch.

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Consider Paul's rocket mass heater.
subject: Problem with Switch statements!