how to create a rectangle in java

Solutions on MaxInterview for how to create a rectangle in java by the best coders in the world

showing results for - "how to create a rectangle in java"
Sophie
13 Jan 2017
1import javax.swing.JFrame;
2import java.awt.Rectangle;
3import javax.swing.JComponent;
4import java.awt.Graphics2D;
5import java.awt.Graphics;
6import java.awt.Color;
7
8public class ChrismasTree {
9    public static void main(String[] args) {
10        JFrame window = new JFrame();
11        window.setTitle("Christmas Tree");
12        window.setSize(800, 1000);
13        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
14        window.setVisible(true);
15        DrawingComponent DC = new DrawingComponent();
16        window.add(DC);
17    }
18}
19
20class DrawingComponent extends JComponent{
21    public void paint(Graphics graph0){
22        Graphics2D graph = (Graphics2D) graph0;
23
24        graph.setColor(Color.LIGHT_GRAY);
25        graph.draw(new Rectangle(0, 710, 70, 60));
26
27        graph.setColor(Color.BLUE);
28        graph.draw(new Rectangle(70, 600, 50, 100));
29
30        graph.setColor(Color.BLACK);
31    }
32}
queries leading to this page
creating a moving rectangle in javajava draw rectangle around a point javajava rectangle examplerectangle components javadraw a rect in javarectangle program in javahow to draw a rectanglel in javajava create a rectangle objecthow to draw rectangle in javarectangle class in javahow to draw a rectangle in java jpaintjava rectangle methodhow to initialize a rectangle javamake a rectangle with java forrectangle functions in javahow to draw a rectangle javadraw rectangle in javahow to use java rectangle classcreate a rectangle class to represent a rectangle javajava create rectanglehow to make a rectangle in javacreating rectangle in javadraw a rectangle javamethod for draw rectangle in javajava draw a rectanglerectangle import javaimport rectangle javahow to draw rectangle javajava swing rectanglehow to make rectangle in javahow to create a rectangle in javajava swing create rectanglehow to draw a rectangle with a bend in javadraw rectangle and fill rectangle in javahow to make a rectangle class in javajava constructor rectangle examplewhat is rectangle in javahow to import rectangle class in javajava swing draw rectanglehow to draw a rectangle using std draw javajava program rectangle1rectangle component javajava draw rectanglehow to use rectangle class in javajava code to draw rectangledraw rectangle with java swingrectangle in javahow to create a rectangle class in javahow to make rectangle object javarectangle javajava a program to draw a rectangle using swing java rectanglejava how to draw a rectanglehow to draw a rectangledraw rectangle javahow to draw a rectangle in javaclass rectangle in javahow to draw a filled rectangle in javahow to render a rectangle javajava create a rectanglewrite a class named rectangle to represent rectangles in javamake rectangle java swingrectangle program in java using objectdraw a rectangle in java swingjava swing draw rectangle 2bhow to create a rectangle in java