how to create a draw Rectangle in java
import javax.swing.JFrame;
import java.awt.Rectangle;
import javax.swing.JComponent;
import java.awt.Graphics2D;
import java.awt.Graphics;
import java.awt.Color;
public class ChrismasTree {
public static void main(String[] args) {
JFrame window = new JFrame();
window.setTitle("Christmas Tree");
window.setSize(800, 1000);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setVisible(true);
DrawingComponent DC = new DrawingComponent();
window.add(DC);
}
}
class DrawingComponent extends JComponent{
public void paint(Graphics graph0){
Graphics2D graph = (Graphics2D) graph0;
graph.setColor(Color.LIGHT_GRAY);
graph.draw(new Rectangle(0, 710, 70, 60));
graph.setColor(Color.BLUE);
graph.draw(new Rectangle(70, 600, 50, 100));
graph.setColor(Color.BLACK);
}
}
Also in Java:
- java file download
- how to ask user for his location in android
- how to get length of integer in java
- fibonacci sequence in java recursion
- java flood fill
- java stream to list
- store string elements in character array in java
- how to exit a for loop in java
- write an infinite loop java
- java for
- java methods
- eliminar el primer caracter de un string java
- java print type of object
- how to create a circle in java
- formatting an integer in java
- action on long press of edit edittext
- reentrantreadwritelock java
- when super add by constructor in java
- one line if statement java
- how to initialize main in java
- how to find length of array in java
- keep jframe on top
- java string to character stream
- change java version command line debian