软件工程——移动的HelloWorld
| package disiti; | |
| 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的更多相关文章
- 软件工程——HelloWorld
#include main(){ printf("Hello World\n"); }
- 软件工程(C编码实践篇)学习心得
孟繁琛 + 原创作品转载请注明出处 + <软件工程(C编码实践篇)>MOOC课程 http://mooc.study.163.com/course/USTC-1000002006 软件工程 ...
- 软件工程(C编码实践篇)总结
陆伟丹 + 原创作品转载请注明出处 + <软件工程(C编码实践篇)>MOOC课程http://mooc.study.163.com/course/USTC-1000002006 对软件工程 ...
- 《hello--world团队》第一次作业:团队亮相
项目 内容 这个作业属于哪个课程 2016级计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 实验五 团队作业:软件研发团队组建 团队名称 <hello--world团队> ...
- OSGI框架—HelloWorld小实例
OSGi(Open Service Gateway Initiative)技术是Java动态化模块化系统的一系列规范.OSGi一方面指维护OSGi规范的OSGI官方联盟,另一方面指的是该组织维护的基于 ...
- 《hello-world》第八次团队作业:Alpha冲刺
项目 内容 这个作业属于哪个课程 2016级计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 实验十二 团队作业8:软件测试与Alpha冲刺 团队名称 <hello--worl ...
- 《hello-world》第八次团队作业:Alpha冲刺-Scrum Meeting 1
项目 内容 这个作业属于哪个课程 2016级计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 实验十二 团队作业8:软件测试与Alpha冲刺 团队名称 <hello--worl ...
- 《hello-world》第八次团队作业:Alpha冲刺-Scrum Meeting 2
项目 内容 这个作业属于哪个课程 2016级计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 实验十二 团队作业8:软件测试与Alpha冲刺 团队名称 <hello--worl ...
- 《hello-world》第八次团队作业:Alpha冲刺-Scrum Meeting 3
项目 内容 这个作业属于哪个课程 2016级计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 实验十二 团队作业8:软件测试与Alpha冲刺 团队名称 <hello--worl ...
随机推荐
- PDO 对 mysql的基本操作
PDO扩展操作 <?php $dsn = 'mysql:dbname=yii2;host=localhost'; $user = 'root'; $password = '123456'; tr ...
- 寒假训练 A - A Knight's Journey 搜索
Background The knight is getting bored of seeing the same black and white squares again and again an ...
- centos7下安装docker(7docker base command 命令词典)
上一章中我总结了学习docker 镜像时所用过的命令,今天先来将docker base command 记录一下,参考:https://docs.docker.com/edge/engine/refe ...
- 基于Redis的INCR实现一个限流器
模式:计数器 计数器是 Redis 的原子性自增操作可实现的最直观的模式了,它的想法相当简单:每当某个操作发生时,向 Redis 发送一个 INCR 命令. 比如在一个 web 应用程序中,如果想知道 ...
- 单例模式和JDBC
配置文件: driver=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/blog user=root user=1234 properti ...
- Vue 改变数组中对象的属性不重新渲染View的解决方案
Vue 改变数组中对象的属性不重新渲染View的解决方案 在解决问题之前,我们先来了解下 vue响应性原理: Vue最显著的一个功能是响应系统-- 模型只是一个普通对象,修改对象则会更新视图.受到ja ...
- AI 随机梯度下降(SGD)
随机梯度下降(stochastic gradient descent) 梯度是期望 计算梯度耗时太长
- 【Luogu P1074】靶形数独
Luogu P1074 题意:给一个数独,问怎么填会使每个位置填的数乘以它的权值得到的和最大.其中每个位置的权值在题面中给出了. 思路:首先我们考虑搜索.由于我们不可能搜每个格子取太多的数,所以我们从 ...
- Luogu4249 WC2007 石头剪刀布 费用流
传送门 考虑竞赛图三元环计数,设第\(i\)个点的入度为\(d_i\),根据容斥,答案为\(C_n^3 - \sum C_{d_i}^2\) 所以我们需要最小化\(\sum C_{d_i}^2\) 考 ...
- React-使用combineReducers完成对数据对拆分管理
数据都放在reducer.js下不利于对数据进行管理,可以把一个大的reducer.js拆分成多个小的reducer.js. 小的reducer.js const defaultState={ foc ...