Java language GUI programming internal class and mouse events Classic 1

Source: Internet
Author: User

/* Time: March 21, 2015 09:53:44 Program Purpose: Understand the role of the inner class and the processing of the mouse event source file name: Testinner.java point: 1, the nature and usage of the Inner Class 2, defines the inner class as the benefit of the ordinary inner class-----  The inner class can directly access the properties and method 3 of the outer class, allowing for clearer organizational logic to prevent access to classes that should not be accessed by other classes: The class does not allow or requires other classes to access it. Mouse Events mouse Event two listener interface for MouseListener, Mousemotionlistener 1, MouseListener interface has five methods to handle is press, release, click , entering or leaving State 2, the Mousemotion interface has two methods for handling the mouse button pressing and dragging on the component and the mouse cursor entering the component but no key
*/import Java.awt.*;import java.awt.event.*;
public class Testinner { frame f = new Frame ("Internal test Class"),  textfield tf = new TextField (in);   public Testi Nner () {  f.add ("Press the left mouse button and drag"), Borderlayout.north)   f.add (TF, "South");   F.setbounds (    f.addmousemotionlistener (), New Innermouse ());   F.addmouselistener (New Innermouse ());     f.setvisible (True);   }   public static void Main (string[] args) {  new testinner ();  }  private class Innermouse Implements Mousemotionlistener, MouseListener {    public void mousepressed (MouseEvent e) {    string s = ("mouse presses" + "," + "position" + e.getpoint ());    tf.settext (s);   }  & nbsp; public void mousereleased (MouseEvent e) {   tf.settext ("Mouse in component released" + E.getpoint ());   }    public void mouseentered (MouseEvent e) {    tf.settext ("Mouse enters form component" + e.getpoint ());   }  public void mouseexited (MouseEvent e) {    tf.settext ("Mouse moves out of form component");   }    public void mouseclicked (MouseEvent e) {    tf.settext ("Mouse click on component (Press and release), position" + e.getpoint ());   }    public void mousedragged (MouseEvent e) {   tf.settext Called when the mouse is pressed and dragged on the component (+ e.getpoint ());   }
public void mousemoved (MouseEvent e) {tf.settext ("the mouse cursor is moved to the component but no key is called" + e.getpoint ()); }
}}

Java language GUI programming internal class and mouse events Classic 1

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.