Results 1 to 2 of 2
  1. #1
    OBLITERATOR is offline Member
    Join Date
    Mar 2010
    Posts
    1
    Rep Power
    0

    Default Fill in rectangle partially (clip?)

    Hello, I've searched the forum and I couldn't find any answers so here's my problem:

    I have to partially fill in a rectangle, i'll express the idea using O's:

    OOOOO
    O-O- O
    OOOOO
    O----O

    (-= white "squares/areas")

    more or less, basically I leave out certain white areas here's my code:

    Java Code:
    import javax.swing.*;
    import java.awt.*;
    
    public class Drawing{
      public static void main(String[] args) {
        Drawing d = new Drawing();
      }
    
      public Color(){
        JFrame frame = new JFrame("faces");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MyComponent());
        frame.setSize(800,600);
        frame.setVisible(true);  
      }
    
      public class MyComponent extends JComponent{
        public void paint(Graphics g){
          int height;
          int width;
          g.clipRect(1,1,50,40);
          g.setColor(Color.black);
          g.fillRect(1,1,10,40);
          g.fillRect(2,1,50,10);
          //g.fillRect(6,2,50,20);
        }
      }
    }
    the two g.fillRect lines that are NOT commented out fill in the first collumn and first row respectively, however I cant manage to fill a different row (3rd)....
    (and individual squares within a given row column)

    Any ideas?

    pd g.clipRect(1,1,50,40) making the start coords 0,0 doesnt seem to make any difference...






    SOLVED
    Last edited by OBLITERATOR; 03-07-2010 at 03:13 PM.

  2. #2
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    You'll have to divide your rectangle into a grid of rectangles, and paint the spaces in that grid that you want painted. Probably a 2D array of something like GridPoint that you can activate/deactivate depending on whether you want it filled or not(or it tracks its own color) and also give it a draw/paint method.
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

Similar Threads

  1. JSP partially renders sometimes
    By lisalu22 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 02-23-2010, 05:45 PM
  2. Replies: 7
    Last Post: 04-14-2009, 07:12 PM
  3. sound clip
    By f_the_cook in forum Advanced Java
    Replies: 4
    Last Post: 10-17-2008, 05:19 PM
  4. How to Clip an Image
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-23-2008, 11:24 PM
  5. How to Fill a Rectangle in Java
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:10 PM

Posting Permissions

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