How To Draw A Rectangle In Java Jframe
Draw rectangles, use the drawRect() method. To fill rectangles, employ the fillRect() method : Shape « 2d Graphics GUI « Java
Draw rectangles, use the drawRect() method. To fill rectangles, use the fillRect() method
import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JFrame; import javax.swing.JPanel; public class Rectangles extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; g2d.setColor( new Color(212, 212, 212)); g2d.drawRect(10, xv, 90, 60); g2d.setColor( new Color(31, 21, i)); g2d.fillRect(250, 195, 90, threescore); } public static void principal(String[] args) { Rectangles rects = new Rectangles(); JFrame frame = new JFrame("Rectangles"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(rects); frame.setSize(360, 300); frame.setLocationRelativeTo(cipher); frame.setVisible(truthful); } }
Related examples in the same category
| i. | Creating Bones Shapes | ||
| 2. | fillRect (int, int, int, int) method draws a solid rectangle | ||
| 3. | Creating a Shape Using Lines and Curves | ||
| 4. | Combining Shapes | ||
| 5. | Depict line | | |
| 6. | Draw a Polygon | | |
| seven. | Draw an oval outline | ||
| eight. | Draw a (Round)rectangle | | |
| ix. | Fill a polygon | | |
| x. | Fill a solid oval | ||
| 11. | Fill a (Circular)rectangle | | |
| 12. | Change font | | |
| xiii. | Depict rectangle two | | |
| 14. | Depict Arc | | |
| 15. | Depict Ellipse | | |
| 16. | Fill a Rectangle 2 | | |
| 17. | Fill Arc ii | | |
| 18. | Draw text | | |
| xix. | Describe unicode string | | |
| 20. | Shape combine | | |
| 21. | Effects | | |
| 22. | Mouse drag and drop to describe | | |
| 23. | Arc demonstration: scale, move, rotate, sheer | | |
| 24. | Hypnosis Screw | | |
| 25. | GlyphVector.getNumGlyphs() | ||
| 26. | Resize a shape | ||
| 27. | Rectangle with rounded corners drawn using Coffee 2D Graphics API | ||
| 28. | Compares ii ellipses and returns true if they are equal or both cypher. | ||
| 29. | Compares two lines are returns true if they are equal or both zilch. | ||
| thirty. | Creates a diagonal cantankerous shape. | ||
| 31. | Creates a diamond shape. | ||
| 32. | Creates a new Stroke-Object for the given type and with. | ||
| 33. | Creates a region surrounding a line segment by 'widening' the line segment. | ||
| 34. | Creates a triangle shape that points downward. | ||
| 35. | Creates a triangle shape that points up. | ||
| 36. | Generate Polygon | ||
| 37. | Polygon with float coordinates. | ||
| 38. | Polyline 2nd | ||
| 39. | Serialises a Shape object. | ||
| forty. | Tests two polygons for equality. If both are nada this method returns true. | ||
| 41. | Spousal relationship two rectangles | ||
| 42. | Summate Intersection Clip | ||
| 43. | Draws a shape with the specified rotation near (10, y). | ||
| 44. | Checks, whether the given rectangle1 fully contains rectangle ii (fifty-fifty if rectangle ii has a top or width of zero!). | ||
| 45. | Reads a Point2D object that has been serialised by the writePoint2D(Point2D, ObjectOutputStream)} method. | ||
| 46. | Returns a point based on (x, y) but constrained to exist inside the bounds of a given rectangle. | ||
| 47. | RectListManager is a grade to manage a listing of rectangular regions. | ||
| 48. | Make full Rectangle2D.Double and Ellipse2D.Double | | |
| 49. | This program demonstrates the diverse 2D shapes | |
Source: http://www.java2s.com/Code/Java/2D-Graphics-GUI/DrawrectanglesusethedrawRectmethodTofillrectanglesusethefillRectmethod.htm
Posted by: woodovesibly.blogspot.com

0 Response to "How To Draw A Rectangle In Java Jframe"
Post a Comment