File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes New here; please help( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "New here; please help(",): Play Shape; A program that reads a shape number!?!?!?!? " Watch "New here; please help(",): Play Shape; A program that reads a shape number!?!?!?!? " New topic
Author

New here; please help(",): Play Shape; A program that reads a shape number!?!?!?!?

Mark Goodman
Greenhorn

Joined: Apr 26, 2005
Posts: 2
hi people, i am sorry for the begging title but i am desperate; so let me get into the problem straight and stop wasting your time even more :roll: ;
i am trying to make a program that reads a shape number (1=circle, 2=oval, 3=square, 4=rectangle) and the x and y co-ordinates (of the upper left hand corner of the bounding box) from three textfields then draws the shape at those co-ordinates when a button is pressed.

I have started and ended up with making the three text field and the draw buttom; but i don't know what to do know ; i don't know how to make the program draws the shapes; 1=circle, 2=oval, etc...
Please help; your help will be very appreciated.
thank you
Mark Goodman
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
I would recommend using a switch statement that draws a different shape depending on the value of a user-defined variable...


Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Mark Goodman
Greenhorn

Joined: Apr 26, 2005
Posts: 2
hi jeff, and thank you for your help, but i am not familiar with a switch statment; is there a webiste i can check; or can you tell me the line of code that is used
thank you
Mark Goodman
M Beck
Ranch Hand

Joined: Jan 14, 2005
Posts: 323
here is a good tutorial on switch. there's really only two things to remember about it:
  • only "int"'s can be "case"'s (unless you're writing Java 5.0), and
  • you need to "break" after each "case".
  • Jeff Bosch
    Ranch Hand

    Joined: Jul 30, 2003
    Posts: 804
    M Beck wrote:
    you need to "break" after each "case".


    Actually, that's not a requirement. Suppose, for example, that you want one action to occur on several cases. To do that you can "stack" the case statements. Also, you may want to build functionality by having a heirarchy of processing, in which case you omit the break after the relevant statements. (My boss is calling me or I'd write examples.) Whenever you do something like this, though, document in comments your reasons why.

    Also, a char is an integer type, so you could do something like:


    Hope that helps!
    [ April 27, 2005: Message edited by: Jeff Bosch ]
    M Beck
    Ranch Hand

    Joined: Jan 14, 2005
    Posts: 323
    true, Jeff, but i was deliberately simplifying a bit to keep it on the beginner-forum level. after all, if the gentleman comes asking what a switch statement even is, it might not be polite to pummel him with fall-throughs right off the bat, right?
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: New here; please help(",): Play Shape; A program that reads a shape number!?!?!?!?
     
    Similar Threads
    How to display components as well as draw?
    Help with getting new points
    *PLEASE HELP!!!*
    Why does it not show the new coordinates?!!??!!
    How to properly create an applet with an Input field and some shapes.