Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- public class TrayFun {
- static class ShowMessageListener implements ActionListener {
- TrayIcon trayIcon;
- String title;
- String message;
- TrayIcon.MessageType messageType;
- ShowMessageListener(
- TrayIcon trayIcon,
- String title,
- String message,
- TrayIcon.MessageType messageType) {
- this.trayIcon = trayIcon;
- this.title = title;
- this.message = message;
- this.messageType = messageType;
- }
- public void actionPerformed(ActionEvent e) {
- trayIcon.displayMessage(title, message, messageType);
- }
- }
- public static void main(String args[]) {
- Runnable runner = new Runnable() {
- public void run() {
- if (SystemTray.isSupported()) {
- final SystemTray tray = SystemTray.getSystemTray();
- Image image = Toolkit.getDefaultToolkit().getImage("green_info.png");
- PopupMenu popup = new PopupMenu();
- final TrayIcon trayIcon = new TrayIcon(image, "The Tip Text", popup);
- trayIcon.setImageAutoSize(true);
- MenuItem item = new MenuItem("Close");
- item.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- tray.remove(trayIcon);
- }
- });
- popup.add(item);
- try {
- tray.add(trayIcon);
- } catch (AWTException e) {
- System.err.println("Can't add to tray");
- }
- } else {
- System.err.println("Tray unavailable");
- }
- }
- };
- EventQueue.invokeLater(runner);
- }
- }
- public void paint(Graphics g) {
- if (g != null && curW > 0 && curH > 0) {
- BufferedImage bufImage = new BufferedImage(curW, curH, BufferedImage.TYPE_INT_ARGB);
- Graphics2D gr = bufImage.createGraphics();
- if (gr != null) {
- try {
- gr.setColor(getBackground());
- gr.fillRect(0, 0, curW, curH);
- gr.drawImage(image, 0, 0, curW, curH, observer);
- gr.dispose();
- g.drawImage(bufImage, 0, 0, curW, curH, null);
- } finally {
- gr.dispose();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment