package com.home.test;

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(" Juvenility ", 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; // Drag and drop the target component you want to move
 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

}

}

Movable HelloWorld More articles about

  1. Use webstorm+webpack Build a simple entry level “HelloWorld” Application && quote jquery To achieve alert

    Use webstorm+webpack Build a simple entry level "HelloWorld" Application && Build using jquery To achieve 1. First of all, you put it yourself webstorm installation is complete . Please refer to this ...

  2. Idea Next use SBT build Spark Helloworld

    Never used IDEA Tools , It's said that Eclipse almost ,sbt stay Idea In fact, it is equal to maven stay Eclipse.Spark Running on the JVM in , So we need to Idea Run under spark, You need to install JDK 1.8+ Then join S ...

  3. Rookie Science Struts2——HelloWorld

    Write it at the front I've lived a life with only one month memory since I worked , Too forgetful , A lot of things I have learned are forgotten because I use them less , A second study struts, For future reference , Start your own blog journey .Struts We should learn from Hello World ...

  4. First time to know AngularJS And HelloWorld And data binding

    1.Hello World The development tool I use is    atom   , You can ask me to install the package if you need it First step : Write the following code : <!DOCTYPE html> <html ng-ap ...

  5. java Environment building and writing a Helloworld

    One . Install environment and configure environment variables ( Necessary links ) install java And configure environment variables : stay " System variables " Set in 3 Item properties ,JAVA_HOME,PATH,CLASSPATH( Case doesn't matter ), Click... If it already exists ...

  6. Delphi_01_ Console version HelloWorld

    about Windows Console programming under , I believe many people are familiar with . and C The famous beginning of language “Hello world” Programming is basically the first step in learning programming . I think for RAD Development , What we are familiar with is GUI Programming , And for consol ...

  7. Quartz —— from HelloWorld Start

    1.Quartz It's used to schedule tasks . 2.Quartz Three core concepts of : Scheduler . Mission . trigger . (1)Job: Define the tasks to be performed by implementing the interface . public interface Job { / ...

  8. Reprint an article —— from HelloWorld Learning the operating system

    Reprinted address :https://my.oschina.net/hosee/blog/673628?p=%7b%7bcurrentPage+1%7d%7d This paper will systematically connect those knowledge points , Easy to review and review . Ben ...

  9. AngularJS series 01 - HelloWorld And data binding

    Directory guide : AngularJS series Learning notes Contents Preface : Better a good memory than a bad keyboard , Essays are notes , I hope it will be useful in the future . This directory : 1. Hello World 2. AngularJS Data binding in 3. ...

  10. iOS series The basic chapter 01 structure HelloWorld, Analysis and real machine test

    iOS Basics 01  structure HelloWorld, Analysis and real machine test Preface : Output from console HelloWorld It's our first step in learning all kinds of languages , It's also a very important step in our lives . After many years , I hope we can still have the heart of learning and progress ...

Random recommendation

  1. [PHP][ Bit conversion accumulation ] Simple encryption application of XOR operation

    The sign of XOR is ^. Bitwise exclusive or operation , Perform a logical bitwise XOR operation on each bit of the bitwise or binary number of the equal length binary pattern . The result of the operation is that if a bit is different, the bit is 1, Otherwise, this bit is 0. xor The inverse of an operation is itself , That is to say, two exclusive or the same number ...

  2. zabbix centos 6.4 install

    -- Download address http://www.zabbix.com/download.php -- Environmental Science centos6.4-x86-64 zabbix 2.2 x64 -- Installation package required rpm -ivh unix ...

  3. master Tiles frame ( One )---Tiles Introduction and Tiles Framework and Architecture

    master Tiles frame ( One )---Tiles Introduction and Tiles Framework and Architecture introduction This tutorial is about This tutorial describes how to use Tiles Framework to create reusable presentation components .( When it was first created ,Tiles The frame is ...

  4. php Get this Monday 、 Sunday time , Last week, Monday 、 Sunday time , On the first day of the month , The last day of the month , The first day of last month , Last day time

    Statement of rights : This article is an original blog article , No reprint without the permission of the blogger . // Monday of this week // @$timestamp , A time stamp of a week , The default is the current time // @is_return_timestamp , whether ...

  5. SAVEPOINT Mark

    create table duo(               -- Create a table                 v_xuhao number(3),                v_name varch ...

  6. String Convert to Map

    Map<String,Integer> rulsMap = new Gson().fromJson(cachedobj.toString(),new TypeToken<Map< ...

  7. Mybatis ResultMap Collection Composite primary key

    <resultMap type="XX" id="XXMap">          <id property="id" c ...

  8. Jboss Jmx-Console and Jboss web-console Security Settings

    1. Introduce If you expose your JBoss Server through network ( For example, by starting the server to use options B 0.0.0.0 Or by changing jboss.bind.address For the first time 0.0.0.0 stay .../jboss/server/d ...

  9. The file or assembly could not be loaded “log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821” Or one of its dependencies . The system cannot find the specified file .

    I've been searching the Internet for a long time , There are many places to modify the configuration file , There are also heavy loads log4net Of . As the article : Use Common.Logging And log4net Component version compatibility of I checked and found that in the project package In bag Log4net ...

  10. How to do system optimization -JVM Optimize it VisualVM

    Hello everyone , Here is 「 Talk about system optimization 」, And update at the following address Blog Garden :http://www.cnblogs.com/changsong/ Know about columns :https://zhuanlan.zhihu.com/yo ...