可移动的 HelloWorld
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
}
}
可移动的 HelloWorld的更多相关文章
- 使用webstorm+webpack构建简单入门级“HelloWorld”的应用&&引用jquery来实现alert
使用webstorm+webpack构建简单入门级"HelloWorld"的应用&&构建使用jquery来实现 1.首先你自己把webstorm安装完成. 请参考这 ...
- Idea下用SBT搭建Spark Helloworld
没用过IDEA工具,听说跟Eclipse差不多,sbt在Idea其实就等于maven在Eclipse.Spark运行在JVM中,所以要在Idea下运行spark,就先要安装JDK 1.8+ 然后加入S ...
- 菜鸟学Struts2——HelloWorld
写在前面 自从工作后就过上了只有一个月记忆的生活,太健忘,很多学过的东西因为用得少便忘记了,第二次学习struts,为了以后便于查阅,开始自己的博客之旅.Struts的学习还是从Hello World ...
- 初识AngularJS 之 HelloWorld和数据绑定
1.Hello World 我用的开发工具是 atom ,大家有需要的话可以找我要安装包嘻嘻 第一步: 写入以下代码: <!DOCTYPE html> <html ng-ap ...
- java环境搭建和写出一个Helloworld
一.安装环境和配置环境变量(必要环节) 安装java并配置环境变量 :在"系统变量"中设置3项属性,JAVA_HOME,PATH,CLASSPATH(大小写无所谓),若已存在则点击 ...
- Delphi_01_控制台版HelloWorld
对于Windows下的控制台编程,我相信很多人都不陌生.而C语言开始的著名的“Hello world”程序基本是学习编程的第一步.我想对于 RAD开发,大家熟悉的一般都是GUI编程,而对于consol ...
- Quartz —— 从 HelloWorld 开始
1.Quartz 是用来完成任务调度的. 2.Quartz 的三个核心概念:调度器.任务.触发器. (1)Job:通过实现该接口来定义需要执行的任务. public interface Job { / ...
- 转载文章——从HelloWorld学习操作系统
转载地址:https://my.oschina.net/hosee/blog/673628?p=%7b%7bcurrentPage+1%7d%7d 本文就将系统性的串联起那些知识点,方便复习和回顾.本 ...
- AngularJS 系列 01 - HelloWorld和数据绑定
目录导读: AngularJS 系列 学习笔记 目录篇 前言: 好记性不如烂键盘,随笔就是随手笔记,希望以后有用. 本篇目录: 1. Hello World 2. AngularJS中的数据绑定 3. ...
- iOS系列 基础篇 01 构建HelloWorld,剖析并真机测试
iOS基础 01 构建HelloWorld,剖析并真机测试 前言: 从控制台输出HelloWorld是我们学习各种语言的第一步,也是我们人生中非常重要的一步. 多年之后,我希望我们仍能怀有学习上进的心 ...
随机推荐
- leetcode 7. Reverse Integer [java]
public int reverse(int x) { long res = 0; while (x != 0){ res = res* 10 + x % 10; x /= 10; } if(res ...
- 解决input框黄色背景问题(转)
input:-webkit-autofill { box-shadow: 0 0 0px 1000px white inset !important;} <form action="l ...
- swift的@objc总结
One can explicitly write @objc on any Swift declaration that can be expressed in Objective-C. @objc相 ...
- 在linux系统下安装配置apacheserver
我所用的是centos linux系统,但apache的服务在linux系统都大同小异.像ubuntu redhat等等. now let us go! 如有问题, 欢迎直邮: zhe ...
- Blinker 后台数据分析
如何解析出后台服务器认证信息,供自己的设备连接. 测试程序 天气 增加了 Debug输出信息功能 1手机APP添加控件信息 2硬件烧录程序 #define BLINKER_PRINT Serial ...
- QT数据类型
typedef signed char int8_t;typedef short int16_t;typedef int int3 ...
- ethereum/EIPs-1271 smart contract
https://github.com/PhABC/EIPs/blob/is-valid-signature/EIPS/eip-1271.md Standard Signature Validation ...
- python3 练习题 day02
'''1.有变量name = "aleX leNb" 完成如下操作:1) 移除 name 变量对应的值两边的空格,并输出处理结果2) 移除name变量左边的"al&q ...
- centos 6.5 gogs迁移外部仓库报错
安装gogs git软件后,使用迁移外部仓库功能,提示“你没有获得导入本地仓库的权限”,发现是因为使用的ssh的链接进行导入 目前gogs咱不支持,随后使用github的https链接导入,依然报错 ...
- Python基础(3)if_else、for、while、break与continue
1.if ... else a=6 if a>=5: print("The a is bigger than 5") else: print("The a is s ...