The eight swing drawing of Java GUI programming (swing)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.