Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.AWTException;
- import java.awt.FlowLayout;
- import java.awt.Image;
- import java.awt.MenuItem;
- import java.awt.PopupMenu;
- import java.awt.SystemTray;
- import java.awt.Toolkit;
- import java.awt.TrayIcon;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.File;
- import javax.swing.*;
- public class main {
- public static void main(String s[]) {
- JFrame frame = new JFrame("JFrame");
- JPanel panel = new JPanel();
- setTray();
- panel.setLayout(new FlowLayout());
- JButton button1 = new JButton();
- JButton butto2 = new JButton();
- JButton butto3 = new JButton();
- JButton butto4 = new JButton();
- JButton butto5 = new JButton();
- button1.setText("Press me");
- panel.add(button1);
- button1.addActionListener( new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- AlertifyBuilder bldr = new AlertifyBuilder();
- bldr.type(AlertifyType.LOG);
- Alertify.show(
- bldr.text("Lololol").autoClose(5000L).callback(new AlertifyWindowClick() {
- @Override
- public void alertClicked(AlertifyWindow window) {
- }
- }).build());
- }
- });
- butto2.setText("Press me");
- panel.add(butto2);
- butto2.addActionListener( new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- AlertifyBuilder bldr = new AlertifyBuilder();
- bldr.type(AlertifyType.INFO);
- Alertify.show(
- bldr.text("Lololol").autoClose(5000L).callback(new AlertifyWindowClick() {
- @Override
- public void alertClicked(AlertifyWindow window) {
- }
- }).build());
- }
- });
- butto3.setText("Press me");
- panel.add(butto3);
- butto3.addActionListener( new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- AlertifyBuilder bldr = new AlertifyBuilder();
- bldr.type(AlertifyType.ERROR);
- Alertify.show(
- bldr.text("Lololol").autoClose(5000L).callback(new AlertifyWindowClick() {
- @Override
- public void alertClicked(AlertifyWindow window) {
- }
- }).build());
- }
- });
- butto4.setText("Press me");
- panel.add(butto4);
- butto4.addActionListener( new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- AlertifyBuilder bldr = new AlertifyBuilder();
- bldr.type(AlertifyType.SUCCESS);
- Alertify.show(
- bldr.text("Lololol").autoClose(5000L).callback(new AlertifyWindowClick() {
- @Override
- public void alertClicked(AlertifyWindow window) {
- }
- }).build());
- }
- });
- butto5.setText("Press me");
- panel.add(butto5);
- butto5.addActionListener( new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- AlertifyBuilder bldr = new AlertifyBuilder();
- bldr.type(AlertifyType.WARNING);
- Alertify.show(
- bldr.text("Lololol").autoClose(5000L).callback(new AlertifyWindowClick() {
- @Override
- public void alertClicked(AlertifyWindow window) {
- }
- }).build());
- }
- });
- frame.add(panel);
- frame.setSize(300, 300);
- frame.setLocationRelativeTo(null);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setVisible(true);
- }
- public static TrayIcon trayIcon;
- public static void setTray() {
- if (SystemTray.isSupported()) {
- Image icon = Toolkit.getDefaultToolkit().getImage("./Sprites/icon.png");
- trayIcon = new TrayIcon(icon, "Client is running.");
- trayIcon.setImageAutoSize(true);
- try {
- SystemTray tray = SystemTray.getSystemTray();
- tray.add(trayIcon);
- trayIcon.displayMessage("Client", "Initiated client.", TrayIcon.MessageType.INFO);
- PopupMenu menu = new PopupMenu();
- final MenuItem minimizeItem = new MenuItem("Minimize to Tray");
- MenuItem exitItem = new MenuItem("Exit");
- menu.add(minimizeItem);
- menu.add(exitItem);
- trayIcon.setPopupMenu(menu);
- ActionListener minimizeListener = new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- AlertifyBuilder bldr = new AlertifyBuilder();
- bldr.type(AlertifyType.WARNING);
- Alertify.show(
- bldr.text("Lololol").autoClose(5000L).callback(new AlertifyWindowClick() {
- @Override
- public void alertClicked(AlertifyWindow window) {
- }
- }).build());
- }
- };
- minimizeItem.addActionListener(minimizeListener);
- ActionListener exitListener = new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- };
- exitItem.addActionListener(exitListener);
- } catch (AWTException e) {
- System.err.println(e);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement