Java Applet Getting Started 18

zhaozj2021-02-11  231

Getting started with Java Applet

YY435

Pacific Network Academy

Fourth day

Mouse Event Example 2

The source code of this example is as follows:

Import java.awt. *;

Import java.applet. *;

Public Class Mouse Extends Applet

{

String msg = "";

/ / Define a string variable to store the message you want to output.

Public Boolean MouseEnter (Event E, INT X, INT Y)

{

Msg = "You come in, I hate! Take it! Take it !! Take the mouse!"

Repaint (); // Re-painting screen

Return true; // Return true boolean value

}

Public Boolean MouseExit (Event E, INT X, INT Y)

{

Msg = "You remove the mouse, don't go! Why don't you move your mouse?";

Repaint ();

Return True;

}

Public void Paint (Graphics G)

{

g.drawstring (MSG, 4, 20); // Display Message

}

}

转载请注明原文地址:https://www.9cbs.com/read-4724.html

New Post(0)