Your first Java program

zhaozj2021-02-16  96

Import java.awt. *;

Import java.awt.event. *;

Class MyButton Extends Button

{

Private mybutton friend;

Public void setfriend (MyButton Friend)

{

THIS.FRIEND = Friend;

}

Public MyButton (String Name)

{

Super (Name);

ENABLEVENTS (AWTEVENT.MOUSE_MOTION_EVENT_MASK);

}

Protected Void ProcessMouseMotionEvent (MouseEvent E)

{

Setvisible (false);

Friend.setVisible (TRUE);

}

}

Public Class TestmyButton

{

Public static void main (string args [])

{

MyButton btn1 = new mybutton ("You come to catch me");

MyButton btn2 = new mybutton ("You come to catch me");

Btn1.setfriend (btn2);

Btn2.setfriend (btn1);

Btn1.setvisible (TRUE);

Frame f = new frame ("IT315");

F.setBackground; Color.Red;

f.addwindowListener (New MyWindowListenter ());

F.Add (btn1, "north");

F.Add (btn2, "south");

F.setsize (300, 300);

F.setVisible (TRUE);

Btn1.setvisible (false);

}

}

Class MyWindowListenter Extends WINDOWADAPTER

{

Public void WINDOWCLOSIG (WindowEvent E)

{

E.GETWINDOW (). setvisible (false);

((Window) E.GETComponent ()). Dispose ();

System.exit (0);

}

}

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

New Post(0)