Results 1 to 2 of 2
- 03-07-2010, 01:52 AM #1
Member
- Join Date
- Mar 2010
- Posts
- 1
- Rep Power
- 0
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:
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)....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); } } }
(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...
SOLVEDLast edited by OBLITERATOR; 03-07-2010 at 03:13 PM.
- 03-07-2010, 04:59 AM #2
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
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
-
JSP partially renders sometimes
By lisalu22 in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 02-23-2010, 05:45 PM -
how to draw a fill rectangle using mouse and paintComponent?
By java_fun2007 in forum New To JavaReplies: 7Last Post: 04-14-2009, 07:12 PM -
sound clip
By f_the_cook in forum Advanced JavaReplies: 4Last Post: 10-17-2008, 05:19 PM -
How to Clip an Image
By Java Tip in forum java.awtReplies: 0Last Post: 06-23-2008, 11:24 PM -
How to Fill a Rectangle in Java
By Java Tip in forum java.awtReplies: 0Last Post: 06-22-2008, 11:10 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks