• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating Graphics/Dice  RSS feed

 
D Doemer
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone --

Only 4 more weeks of this course to go. This week I'm having an exceptional amount of trouble, as I've moved from Ohio to Florida while trying to complete this class at the same time.

Here are the directions:

1. Create a class called DiceView which extends JPanel and implements ActionListener.
2. Create a private data member to hold an instance of Dice
3. Create a setter method for the Dice instance
4. Create a public method for the ActionListener called actionPerformed which does the following:
*Checks if the ActionEvent action command is "Roll"
*If so, check the Dice instance to ensure it is non-null
*If the dice is non-null, roll() the dice
*Call repaint()
5. Create a public method for the component called paintComponent, which does the following:
*Gets the size of the JPanel and sets local variables width and height
*Clears the rectangular area of the JPanel
* Draws a rectangle (or rounded rectangle) to fill most of the area in the JPanel (this represents the side of the dice)
*If the dice is not null, displays the value of the dice within that rectangle
*If the dice is null, displays "No Dice" in that rectangle


It's number 3 where I'm getting lost. He says nothing about a getter method, yet everywhere I look online it talks about setters and getters going together. And after that one, I'm lost the rest of the way. If anyone could help a little, I'd really appreciate it. I'm in a real time crunch for this one. Thanks so much in advance. Here is what I've written so far, though I'm sure it's probably incorrect.


 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Diana Oswald wrote:It's number 3 where I'm getting lost. He says nothing about a getter method, yet everywhere I look online it talks about setters and getters going together.


There's a lot of lazy design where people just automatically generate getter and setter methods for an attribute. But there's no rule which says you have to have either, or both. If you need a getter, write one, and if you need a setter, write one. In this case the specifications ask for a setter, so that's what you should write. (It looks like you already did, though.)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!