/* 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