📄 minitipui.java
字号:
package com.liming.remind.ui;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
* Function : Give MINI(not full screen) Tip to user
*
* @author Liming
* @time Dec 18, 2008 8:51:22 PM
* @version 1.0
*/
public class MiniTipUI extends JFrame {
/**
* Field : serialVersionUID
*/
private static final long serialVersionUID = 3116021730489343180L;
private JButton close;
// Judge the window whether dispose or not
private boolean isExit = false;
public MiniTipUI(String remindContent) {
close = new JButton("<html><font color='green' size='3'><b>"
+ remindContent + "</b></font></html>");
close.setActionCommand("close");
close.addActionListener(new MyButtonListener());
JPanel panel = (JPanel) this.getContentPane();
panel.setLayout(new GridBagLayout());
panel.add(close);
// Set size
this.setSize(250, 150);
// Hidden the border of window
this.setUndecorated(true);
this.setTitle("Time is up...");
// Set DefaultCloseOperation
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// Set Background
panel.setBackground(new Color(100, 200, 100));
// Get Axis x
int x = (int) (this.getScreenSize().getWidth() - this.getThisSize()
.getWidth());
// Get Axis y
int y = (int) (this.getScreenSize().getHeight() - this.getThisSize()
.getHeight()) - 30;
// Get Screen Height
int i = (int) this.getScreenSize().getHeight();
int screenHeight = i;
// Move window up
for (;i > y;i--) {
this.setLoca(x, i);
}
// Wait for 10 seconds
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (!isExit) {
// Move window down
for (;i < screenHeight;i++) {
this.setLoca(x, i);
}
// Close this window without exit Reminder
dispose();
}
}
/**
* Function : Where to place the window
*
* @param x
* @param y
*/
private void setLoca(int x, int y) {
this.setLocation(x, y);
this.setVisible(true);
try {
Thread.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
/**
* Function : Get window size
*
* @return
*/
private Dimension getThisSize() {
return this.getSize();
}
/**
* Function : Get screen size
*
* @return
*/
private Dimension getScreenSize() {
return Toolkit.getDefaultToolkit().getScreenSize();
}
/**
* Function : Close the remind window
*
* @author Liming
* @time Dec 23, 2008 7:47:51 PM
* @version 1.0
*/
private class MyButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("close")) {
isExit = true;
dispose();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -