1. Preparations for wuziqi

Source: Internet
Author: User
I. java. AWT. Toolkit ----- used to obtain the screen size, that is, width and height.

Int width = toolkit. getdefatooltoolkit (). getscreensize (). width; get the screen width

Int Height = toolkit. getdefatooltoolkit (). getscreensize (). height; get the screen height

Ii. javax. Swing. joptionpane ------- used to set the pop-up box

Joptionpane. showmessagedialog (parentcomponent, string message); set the pop-up information box.

Int result = joptionpane. showconfirmdialog (parent, string message). The confirmation box is displayed.

Result = 0, it is "yes"

Result = 1, it is "no"

Result = 2, it is "canceled ";

String STR = joptionpane. showinputdialog ("input information:") sets the pop-up input box and returns the input information.

3. java. AWT. event. mouselistener ------- interface of the mouse event

There are many methods, but the most important of them is

(1) Public void mouseclicked (mouseevent e ){}

(2) Public void mousepressed (mouseevent e ){}

(3) Public void mousereleased (mouseevent e ){}

If you implement the mouselistener interface, you must implement all the methods. However, if you inherit the mouseadapter, you only need to implement the necessary methods.

Note: execution sequence of the mouselistener event

Click the mouse and the execution sequence is: mousepressed ---> mousereleased ---> mouseclicked

Common mouseevent methods:

(1) E. getx ();

(2) E. Gety ();

4. java. AWT. Graphics ----- used for plotting

(1) G. drawstring (string STR, int X, int y); draw a string in the figure (x, y.

(2) g. drawoval (int x, int y, int width, int height); draw a hollow ellipse in the figure. X and Y are the upper left corner of the ellipse.

(3) g. filloval (int x, int y, int width, int height); draw a solid ellipse in the figure.

(4) g. drawrect (int x, int y, int width, int height); draw a hollow rectangle in the figure.

(5) g. fillrect (int x, int y, int width, int height );

(6) g. setcolor (color C); set the color of the drawing.

(7) g. setfont (font F); set the font.

(8) g. drawimage (bufferedimage I); draw an image and talk about it later.

V. java. AWT. image. bufferedimage and javax. ImageIO. ImageIO ---- import and draw images

Bufferedimage image = ImageIO. Read (new file ("demo.jpg "));

G. drawimage (image );

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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.