Results 1 to 3 of 3
  1. #1
    chimpbacca is offline Member
    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0

    Default Hi! lil help? paintcomponent() and text displayed in same window?

    Hi,

    I'm not great at programming yet, so i'll cut to the chase

    i have a box class that takes in height, length, width and calculates surface area and volume.

    I just wanted to show off and draw the cubes and boxes and display their dimensions in a window.

    I'm pretty sure you can display text in a JPanel but i really don't know which components to use.

    I'd have a JFrame... with a JPanel? split it in two and have one side the text dimensions, on the other side a representation of the cuboid.

    Could i pass the measurements taken in as doubles to paintcomponent() and draw the rectangle in proportion to its measurements?

    It's a pipe dream seeing as i have like two days to do this but it would be really satisfying.

    Any ideas people can give me would be great !

    Please ask me to clarify any points to understand my problem, i'd ask my brother he's an IT guy but he's just started a new job for the govt that he has to drive 2 hours to.

    Thanks !!

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default

    Quote Originally Posted by chimpbacca View Post
    I'm pretty sure you can display text in a JPanel but i really don't know which components to use.
    Sounds like a job for a JLabel or a JTextField.

    Quote Originally Posted by chimpbacca View Post
    Could i pass the measurements taken in as doubles to paintcomponent() and draw the rectangle in proportion to its measurements?
    No, but you're on the right track. Extend JPanel and override paintComponent(Graphics g). You can't pass anything as parameters to that method, but you can pass them into the constructor (or a setter) in that class, then access them that way.

    Recommended reading: Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)
    Painting in AWT and Swing
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    chimpbacca is offline Member
    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0

    Default Thanks for the ideas !

    I hear the JLabel, must be like a label in vb where you say .text = MyString (different command of course) Then use gridLayout maybe...

    cool.

    i'll check out the reading and see how i go !

    Thank You !

Similar Threads

  1. Help with paintComponent!
    By joeyea in forum Java 2D
    Replies: 6
    Last Post: 12-27-2010, 01:59 PM
  2. paintComponent vs paintComponents
    By alacn in forum New To Java
    Replies: 5
    Last Post: 07-26-2010, 03:33 AM
  3. Replies: 4
    Last Post: 01-10-2010, 07:48 AM
  4. paintComponent is not working
    By spazattack in forum New To Java
    Replies: 1
    Last Post: 12-18-2009, 03:48 AM
  5. change url in parent window from child window
    By rakesh_n_mehta in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 07-09-2009, 12:17 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •