Software Engineering P37 Exercise Four program code

Source: Internet
Author: User
Tags gety

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

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.