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. .NET 序列化成XML, 并且格式化

    现有Person类: [Serializable] public class Person { public string Name; public string Info; public Perso ...

  2. 关于plist文件的那些事

    今天遇到新生问一个问题,就是用自己定义了一个plist文件,然后可以往里面写东西,但是写过再次运行的时候里面的数据总是最后一次写入的数据.后来就专门研究了一下plist文件. 大家都知道当你创建一个项 ...

  3. 【Java123】Java基础知识点

    https://github.com/xbox1994/2018-Java-Interview 虽说不为面试做准备,仅仅就工作中遇到的很多Java问题,总是模棱两可的擦肩而过,真不是自己的风格. 还是 ...

  4. 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 ...

  5. PAT A1129 Recommendation System (25 分)——set,结构体重载小于号

    Recommendation system predicts the preference that a user would give to an item. Now you are asked t ...

  6. LOJ2538 PKUWC2018 Slay the Spire DP

    传送门 不想放题面了,咕咕咕咕咕 这个期望明明是用来吓人的,其实要算的就是所有方案的最多伤害的和. 首先可以知道的是,能出强化牌就出强化牌(当然最后要留一张攻击牌出出去),且数字尽量大 所以说在强化牌 ...

  7. Luogu3760 TJOI2017 异或和 树状数组

    传送门 题意:给出一个长度为$N$的非负整数序列,求其中所有连续区间的区间和的异或值.$N \leq 10^5$,所有元素之和$\leq 10^6$ 设序列的前缀和为$s_i$,特殊地,$s_0=0$ ...

  8. .NET和F#周报第35周-.NET 8月重大更新

    来看看8月份最后一个周F#和.NET最新相关信息. https://www.yuque.com/rock/fsharp-weekly/35 这次我们多聊聊.NET相关的东西, 看看.NET的健康生态. ...

  9. Intellij Idea 返回上次编辑快捷键设置

    由于默认的返回上次编辑快捷键和和笔记本冲突. 需要从新设置快捷键. 找了好久终于找到了.  分别选中Back和Forward后设置新的快捷键即可

  10. Ext.js Combobox 输入模糊匹配

    前台页面 aspx: 数据源: <ext:Store ID="storeJF" runat="server" AutoLoad="true&qu ...