how to create a draw rectangle in java

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

showing results for - "how to create a draw rectangle in java"
Beatrice
05 Oct 2018
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}
33
queries leading to this page
how to create a jframe javadraw rectangle using javafxhow to create a jframe in javagraphics draw rectangle javajframe examplehow to use jframe in javajframe java examplejframe example codehow to make a jframe in javadraw rectangle with java swingjpaint drawing a rectangle javawhy do we use jframe in javacreate new jframe javahow to declare a j frame in javajframe in javajava new jframejava is jframe built injava swing create framejframe tutorialhow to draw a rectangle in java jpainthow to make a jframejframe basiscshow to make jframe in javahow to creat jfram in javadraw rectangle javadraw a rectangle canavaswhich method is used to draw a rectangle on a canvashow to create a new jframe in javaworking with jframejframe package in javachange layout of jpanel javacreate a jframe in javahow to write jframe in javadraw a rectanglecreate jframe in javajframe java tutorialjava swing create rectanglehow to make a standard jframe in javadraw rectangle and fill rectangle in javause javax swing jframejava jframe tutorialdraw a rectangle in canvajava create rectanglehow to create differents jframe in javamake rectangle java swingjava draw a rectanglecreating frame in java using jframecreate a rectangle class to represent a rectangle javajframe set up codehow to draw rectanglemake a jframejava jpaint how to make your program draw a rectanglecreating rectangle in javajava a program to draw a rectangle using swing import javax swing jframe 3bhow to draw in jframehow to create jframe java simple jframe windowswing jframe examplehow to set jframeways to create jframe in javahow to create a jframehow to create a draw rectangle in java