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("幼圆", 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);      // 鼠标事件处理类   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; // 鼠标拖拽想要移动的目标组件  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

}

}

GuiHelloWorld的更多相关文章

  1. 软件工程——移动的HelloWorld

    package disiti;       import java.awt.Color;   import java.awt.Cursor;   import java.awt.Font;   imp ...

  2. 可移动的 HelloWorld

    package com.home.test; import java.awt.Color;import java.awt.Cursor;import java.awt.Font;import java ...

随机推荐

  1. ios 百度地图使用

    第一步.引入 1.下载SDK  地址http://developer.baidu.com/map/index.php?title=iossdk/sdkiosdev-download 2.解压出Baid ...

  2. mysql列的处理

    MySQL 添加列,修改列,删除列 示例:ALTER TABLE tb_financial MODIFY CREATE_TIME DATETIME(3) DEFAULT NULL COMMENT '录 ...

  3. MySql常用命令集Mysql常用命令4

    说明: 用中括号([])括起来的部分表示是可选的,用大括号({})括起来的部分是表示必须 从中选择其中的一个. 1 FROM子句 FROM 子句指定了Select语句中字段的来源.FROM子句后面是包 ...

  4. yii2 下拉菜单

    model public static function getCatlist(){ $cat = ['0' => '暂无分类']; $res = self::find()->asArra ...

  5. ROS教程3 ROS自定义msg类型及使用

    1ROS自定义msg类型及使用 http://blog.csdn.net/u013453604/article/details/72903398 首先创建一个空的package单独存放msg类型(当然 ...

  6. 1.4 Genymotion模拟器安装

    如果你符合下述三种情况的话,你可以考虑安装一个Genymotion Android模拟器: 没有真机调试,只能用模拟器 嫌SDK内置的AVD启动速度,运行速度慢 电脑配置还可以,最好4G内存以上 如果 ...

  7. 转载 【.NET基础】--委托、事件、线程(1) https://www.cnblogs.com/chengzish/p/4559268.html

    [.NET基础]--委托.事件.线程(1)   1,委托 是存放方法的指针的清单,也就是装方法的容器 A, 新建winform项目[01委托],项目中添加dg_SayHi.cs 委托类 用于存储方法 ...

  8. ethereum/EIPs-191 Signed Data Standard

    https://github.com/ethereum/EIPs/blob/master/EIPS/eip-191.md eip title author status type category c ...

  9. jenkins编译jar包 报connection连接错误

    原因是因为编译启动连接了注册中心 eureka.client.service-url.defaultZone=http://localhost:8093/eureka/ eureka.client.r ...

  10. C语言程序设计II—第四周教学

    第四周教学总结(18/3-24/3) 教学内容 本周的教学内容为:第七章 数组 7.2 二维数组 课前准备 在博客园发布作业:2019春第四周作业 第三周作业讲解视频:A Programing Vid ...