The most basic application of applets--drawing lines on applets

Source: Internet
Author: User
Tags gety

Importjavax.swing.*;Importjava.awt.*;Importjava.awt.event.*; Public classDrawLineextendsJAppletImplementsmouselistener,mousemotionlistener{intX1,y1,x2,y2;//int screenx,screeny;//Dimension screen;Stroke sk=NewBasicstroke (2.0f);  Public voidinit () {//Screen=toolkit.getdefaulttoolkit (). Getscreensize();//screenx= (int) screen.getwidth ();//screeny= (int) screen.getheight ();//SetBounds ((screenx-400)/2, (screeny-700)/2,700); Addmouselistener ( This); Addmousemotionlistener ( This); }     Public voidPaint (Graphics g) {graphics2d GG=(graphics2d) G;        Gg.setstroke (SK);    Gg.drawline (x1, y1, x2, y2); } @Override Public    voidmouseclicked (MouseEvent arg0) {//TODO auto-generated Method Stub} @Override Public voidmouseentered (MouseEvent arg0) {//TODO auto-generated Method Stub} @Override Public voidmouseexited (MouseEvent arg0) {//TODO auto-generated Method Stub            }     Public voidmousepressed (MouseEvent arg0) {//X1=arg0.getx (); //y1=arg0.gety ();} @Override Public voidmousereleased (MouseEvent arg0) {//TODO auto-generated Method Stub} @Override Public voidmousedragged (MouseEvent arg0) {x2=Arg0.getx (); Y2=arg0.gety (); X1=x2; Y1=Y2;    Repaint (); } @Override Public voidmousemoved (MouseEvent arg0) {point P=NewPoint (X2,y2);        SYSTEM.OUT.PRINTLN (P); //System.out.println ("Y" +this.y2);     }}

The most basic application of applets--drawing lines on applets

Related Article

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.