Movable Helloword Statement Import Java.awt.Color; Import Java.awt.Cursor; Import Java.awt.Font; Import Java.awt.Point; Import java.awt.event.MouseEvent;
Import Javax.swing.JLabel; Import Javax.swing.JWindow; Import Javax.swing.event.MouseInputListener;
public class Guihelloworld extends JWindow {private static final long serialversionuid = 1L; JLabel Titlelbl; Font Guihelloworldfont;
Public Guihelloworld () {Guihelloworldfont = new Font ("Young Circle", Font.Italic, 28);
This.getcontentpane (). SetBackground (New Color (0x99ff66)); This.setbounds (400, 200, 200, 60); This.setlayout (NULL);
TITLELBL = new JLabel ("Hello world!"); Titlelbl.setfont (Guihelloworldfont); Titlelbl.setopaque (TRUE); Titlelbl.setbackground (New Color (0X66CC00)); Titlelbl.setbounds (0, 0, 200, 60); This.add (TITLELBL);
Mouse event Handling class Mouseeventlistener MouseListener = new Mouseeventlistener (this); Titlelbl.addmouselistener (MouseListener); Titlelbl.addmousemotionlistener (MouseListener); This.setvisible (TRUE); }
public static void Main (string[] args) {new Guihelloworld ();}}
Class Mouseeventlistener implements Mouseinputlistener {point origin;//mouse Drag to move the target component Guihelloworld frame;
Public Mouseeventlistener (Guihelloworld frame) {This.frame = frame, origin = new Point ();}
public void mouseclicked (MouseEvent e) {//TODO auto-generated method stub
}
public void mousepressed (MouseEvent e) {//TODO auto-generated method Stub origin.x = E.getx (); origin.y = E.gety ();}
public void mousereleased (MouseEvent e) {//TODO auto-generated method stub
}
public void mouseentered (MouseEvent e) {//TODO auto-generated method Stub this.frame.setCursor ( Cursor.getpredefinedcursor (Cursor.move_cursor)); }
public void mouseexited (MouseEvent e) {//TODO auto-generated method Stub this.frame.setCursor ( Cursor.getpredefinedcursor (Cursor.default_cursor)); }
public void mousedragged (MouseEvent e) {//TODO auto-generated method stub point P = This.frame.getLocation (); this.frame . setlocation (p.x + (E.getx ()-origin.x), P.y + (E.gety ()-ORIGIN.Y)); }
public void mousemoved (MouseEvent e) {//TODO auto-generated method stub
}
}
Software Engineering P37 Exercise Four program code