• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with Switch statements!

 
Thijs Haitjema
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
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
haitjema@hotmail.com
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.
 
Marilyn de Queiroz
Sheriff
Posts: 9063
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a page from the JavaRanch Cattle Drive that may help you understand switch.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic