The Graphics class can be interpreted as a brush. It is a drawing class that Java provides for us. Use it to draw: straight drawLine (int x1, int y1, int x2, int y2) rectangle drawrect (int x, int y, int width, int height) round drawoval (int x, int y , int width,int height) fills the rectangle fillRect (int x,int y, int width, int height) fills the circle filloval (int x,int y, int width, int height) figure Slices drawImage (Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int s imageobserver observer) string DRA WString (attributedcharacteriterator iterator, int x, int y) set brush color setcolor (color c) Set font setfont (font font), etc. Functional drawings are generally performed on JPanel For example we draw a circle, a rectangle package draws;import javax.swing.*;import java.awt.*;/*** Swing Drawing technology * Created by Admin on 2017/7/19.*/public class DRAW1 extends Jframe{mypanel mypanel;public static void Main (string[] args) {DRAW1 draw1 = new Draw1 ();} Public Draw1 () {mypanel = new Mypanel (); This.add (Mypanel); this.settitle ("notepad"); This.setresizable (false); This.setlocation (this.setsize); this.setdefaultcloseoperation (jframe.exit_on_close);; This.setvisible (True);}} //An area for drawing and displaying drawings//Inheriting the parent class Jpanelclass Mypanel extends jpanel{//JPanel There is a method (paint) inherited after the need to rewrite//graphics is a brush is an important class of drawing class/ /This method does not need to be explicitly called, run time system will automatically call//the following conditions will also call paint//maximize and minimize the window when//change form large hours//repaint () method is called public void paint (Graphics Graphics) {///1. Call the parent class to complete the initialization task Super.paint (graphics);//simply draw a circle using this method drawoval parameter is x-coordinate y-coordinate width height units are pixels//x-coordinates and y-coordinates for distance our GUI The position of the upper left corner of the interface is Pixel Graphics.drawoval (ten, Ten, ()); Graphics.draw3drect (.);}}
Java GUI programming (swing) eight swing drawing