含動畫的java氣泡提示效果,右下角訊息提示窗
訊息提示框類,包含動畫的設定,以及取工作列高度
TipWindow類由網上找來經過本人修改,現將修改後的小程式發給大家試用,你們可以改的更漂亮更豐富
package test;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
/**
*
* @author lgh
*/
public class TipWindow extends JDialog implements Runnable {
private static Dimension dim;
private int x, y;
private int width, height;
private static Insets screenInsets;
public TipWindow(int width,int height){
dim = Toolkit.getDefaultToolkit().getScreenSize();
screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(this.getGraphicsConfiguration());
this.width=width;
this.height=height;
x = (int) (dim.getWidth() - width-3);
y = (int) (dim.getHeight()-screenInsets.bottom-3);
initComponents();
}
/*
* 開啟漸入效果
* 開啟後3秒,視窗自動漸出
* 若不需要漸出,註釋掉,sleep(3000)和close()方法
*/
public void run() {
for (int i = 0; i <= height; i += 10) {
try {
this.setLocation(x, y - i);
Thread.sleep(5);
} catch (InterruptedException ex) {
Logger.getLogger(TipWindow.class.getName()).log(Level.SEVERE, null, ex);
}
}
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
close();
}
private void initComponents() {
this.setSize(width, height);
this.setLocation(x, y);
this.setBackground(Color.black);
this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
close();
}
});
}
public void close(){
for (int i = 0; i <= height; i += 10) {
try {
setLocation(x, y-height+i);
Thread.sleep(5);
} catch (InterruptedException ex) {
Logger.getLogger(TipWindow.class.getName()).log(Level.SEVERE, null, ex);
}
}
dispose();
}
}
測試類 TipTest
package test;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.HashMap;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
/*
* java氣泡提示效果
* @author noobjava
* @version 1.0
* @since JDK1.6(建議)
*
*/
public class TipTest extends Thread{
private Map<String,String> feaMap=null;
public TipTest(){
feaMap=new HashMap<String,String>();
feaMap.put("name", "noobjava氣泡提醒");
feaMap.put("release", "2010-08-20 11:33:00");
feaMap.put("feature", "1.含動畫漸入與漸出效果\n2.3秒後啟動動畫漸出效果");
super.start();
}
public void run(){
final TipWindow tw=new TipWindow(300,220);
tw.setTitle("noobjava動畫氣泡提示");
JPanel headPan=new JPanel();
JPanel feaPan=new JPanel(new FlowLayout(FlowLayout.RIGHT));
JPanel btnPan=new JPanel();
JButton update=new JButton("確定");
// feaPan.setBorder(BorderFactory.createMatteBorder(1, 2, 3, 0, Color.gray));
JLabel head=new JLabel(feaMap.get("name")+",含以下功能");
head.setPreferredSize(new Dimension(250,30));
head.setForeground(Color.black);
JTextArea feature=new JTextArea(feaMap.get("feature"));
feature.setEditable(false);
feature.setForeground(Color.red);
feature.setFont(new Font("宋體",Font.PLAIN,13));
// feature.setBackground(Color.ORANGE);
feature.setPreferredSize(new Dimension(280,60));
JScrollPane jfeaPan=new JScrollPane(feature);
jfeaPan.setPreferredSize(new Dimension(283,80));
// jfeaPan.setBorder(null);
jfeaPan.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.gray));
JLabel releaseLabel=new JLabel("釋出日期"+feaMap.get("release").substring(0,19));
releaseLabel.setForeground(Color.gray);
feaPan.add(jfeaPan);
feaPan.add(releaseLabel);
headPan.add(head);
btnPan.add(update);
tw.add(headPan,BorderLayout.NORTH);
tw.add(feaPan,BorderLayout.CENTER);
tw.add(btnPan,BorderLayout.SOUTH);
update.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
JOptionPane.showMessageDialog(tw, "點這裡幹嗎?點那個XX關掉嘛");
}
});
tw.setAlwaysOnTop(true);
tw.setResizable(false);
tw.setVisible(true);
tw.run();
}
public static void main(String args[]){
new TipTest();
}
}
相關文章
- 【java web】--Beetl+html滑鼠懸停提示氣泡JavaWebHTML
- vue提示訊息Vue
- reactnative實現qq聊天訊息氣泡拖拽消失效果React
- js氣泡排序動畫JS排序動畫
- jQuery 訊息提示框jQuery
- iOS 微信聊天訊息的圖片氣泡實現iOS
- 基於 Vue.js 的訊息氣泡外掛Vue.js
- e/易語言 按鈕介面彈出氣泡提示
- css實現的氣泡型提示框程式碼例項CSS
- css氣泡聊天框效果CSS
- 微信小程式之『仿QQ訊息氣泡拖拽消失』微信小程式
- asp.net 即時訊息提示ASP.NET
- 訊息提示彈層滾動JQUERRY
- Android輕鬆搞定Dialog提示動畫效果Android動畫
- java氣泡排序Java排序
- 氣泡排序 java排序Java
- Java 氣泡排序Java排序
- 氣泡排序(Java)排序Java
- hp惠普插入耳機右下角提示"檢測到音訊裝置" 取消提醒彈窗音訊
- css實現氣泡框效果CSS
- 榮耀手機鎖屏訊息提示怎麼設定?榮耀手機鎖屏訊息提示的設定方法教程
- java程式的氣泡排序操作Java排序
- javascript網頁右下角彈窗效果JavaScript網頁
- 搭建直播平臺,iYiuMessage 訊息提示元件元件
- mysql 下的提示和含義MySql
- 純CSS製作帶三角的邊框(氣泡框或者提示框)CSS
- Java實現氣泡排序Java排序
- 氣泡排序java實現排序Java
- JAVA基礎--氣泡排序Java排序
- css3氣泡動態上升效果CSSS3
- 【原始碼解讀】js原生訊息提示外掛原始碼JS
- H5說話氣泡點選動畫H5動畫
- JavaScript氣泡排序+Vue視覺化冒泡動畫JavaScript排序Vue視覺化動畫
- 巧用 CSS 動畫實現動態氣泡背景CSS動畫
- 動畫-CAShapeLayer實現QQ訊息紅點拖拽效果動畫
- Text Messages for Mac(簡訊社交聊天彈窗對話氣泡fcpx外掛)Mac
- 線上直播原始碼,自定義氣泡效果(BubbleView)原始碼View
- 直播平臺搭建,自定義氣泡效果(BubbleView)View