JFrame help
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: JFrame help

  1. #1
    Join Date
    Aug 2009
    Posts
    3

    JFrame help

    Below is the code to generate the random color,size and position of rectangles in a JFrame. my question is how can i make sure that the rectangle drawn is entirely inside the JFrame? Asume the frame is 500x500


    class DrawPanel extends JPanel {

    public void paintComponent(Graphics g){

    Graphics2D g2 = (Graphics2D) g;

    int r = (int) (Math.random() * 250);
    int gr = (int) (Math.random() * 250);
    int b = (int) (Math.random() * 250);

    g.setColor(new Color(r,gr,b));

    int ht = (int) ((Math.random() * 120) + 10);
    int width = (int) ((Math.random() * 120) + 10);
    int x = (int) ((Math.random() * 40) + 10);
    int y = (int) ((Math.random() * 40) + 10);

    g.fillRect(x,y,ht,width);

  2. #2
    Join Date
    Aug 2009
    Posts
    3

    Re: JFrame help

    how to delete this thread.

  3. #3
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: JFrame help

    I don't think you can delete threads, but the mods may be able to.
    I take it you want to delete it as it is a duplicate post of http://forums.codeguru.com/showthrea...91-JFrame-help
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center