Advertisement
Guest User

Untitled

a guest
Feb 5th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. import java.awt.AWTException;
  2. import java.awt.FlowLayout;
  3. import java.awt.Image;
  4. import java.awt.MenuItem;
  5. import java.awt.PopupMenu;
  6. import java.awt.SystemTray;
  7. import java.awt.Toolkit;
  8. import java.awt.TrayIcon;
  9. import java.awt.event.ActionEvent;
  10. import java.awt.event.ActionListener;
  11. import java.io.File;
  12.  
  13. import javax.swing.*;
  14.  
  15. public class main {
  16.  
  17. public static void main(String s[]) {
  18. JFrame frame = new JFrame("JFrame");
  19. JPanel panel = new JPanel();
  20. setTray();
  21. panel.setLayout(new FlowLayout());
  22. JButton button1 = new JButton();
  23. JButton butto2 = new JButton();
  24. JButton butto3 = new JButton();
  25. JButton butto4 = new JButton();
  26. JButton butto5 = new JButton();
  27. button1.setText("Press me");
  28. panel.add(button1);
  29. button1.addActionListener( new ActionListener() {
  30. public void actionPerformed(ActionEvent e) {
  31. AlertifyBuilder bldr = new AlertifyBuilder();
  32. bldr.type(AlertifyType.LOG);
  33. Alertify.show(
  34. bldr.text("Lololol").autoClose(5000L).callback(new AlertifyWindowClick() {
  35. @Override
  36. public void alertClicked(AlertifyWindow window) {
  37.  
  38. }
  39. }).build());
  40. }
  41. });
  42. butto2.setText("Press me");
  43. panel.add(butto2);
  44. butto2.addActionListener( new ActionListener() {
  45. public void actionPerformed(ActionEvent e) {
  46. AlertifyBuilder bldr = new AlertifyBuilder();
  47. bldr.type(AlertifyType.INFO);
  48. Alertify.show(
  49. bldr.text("Lololol").autoClose(5000L).callback(new AlertifyWindowClick() {
  50. @Override
  51. public void alertClicked(AlertifyWindow window) {
  52.  
  53. }
  54. }).build());
  55. }
  56. });
  57. butto3.setText("Press me");
  58. panel.add(butto3);
  59. butto3.addActionListener( new ActionListener() {
  60. public void actionPerformed(ActionEvent e) {
  61. AlertifyBuilder bldr = new AlertifyBuilder();
  62. bldr.type(AlertifyType.ERROR);
  63. Alertify.show(
  64. bldr.text("Lololol").autoClose(5000L).callback(new AlertifyWindowClick() {
  65. @Override
  66. public void alertClicked(AlertifyWindow window) {
  67.  
  68. }
  69. }).build());
  70. }
  71. });
  72. butto4.setText("Press me");
  73. panel.add(butto4);
  74. butto4.addActionListener( new ActionListener() {
  75. public void actionPerformed(ActionEvent e) {
  76. AlertifyBuilder bldr = new AlertifyBuilder();
  77. bldr.type(AlertifyType.SUCCESS);
  78. Alertify.show(
  79. bldr.text("Lololol").autoClose(5000L).callback(new AlertifyWindowClick() {
  80. @Override
  81. public void alertClicked(AlertifyWindow window) {
  82.  
  83. }
  84. }).build());
  85. }
  86. });
  87. butto5.setText("Press me");
  88. panel.add(butto5);
  89. butto5.addActionListener( new ActionListener() {
  90. public void actionPerformed(ActionEvent e) {
  91. AlertifyBuilder bldr = new AlertifyBuilder();
  92. bldr.type(AlertifyType.WARNING);
  93. Alertify.show(
  94. bldr.text("Lololol").autoClose(5000L).callback(new AlertifyWindowClick() {
  95. @Override
  96. public void alertClicked(AlertifyWindow window) {
  97.  
  98. }
  99. }).build());
  100. }
  101. });
  102. frame.add(panel);
  103. frame.setSize(300, 300);
  104. frame.setLocationRelativeTo(null);
  105. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  106. frame.setVisible(true);
  107.  
  108. }
  109.  
  110.  
  111. public static TrayIcon trayIcon;
  112.  
  113. public static void setTray() {
  114. if (SystemTray.isSupported()) {
  115. Image icon = Toolkit.getDefaultToolkit().getImage("./Sprites/icon.png");
  116. trayIcon = new TrayIcon(icon, "Client is running.");
  117. trayIcon.setImageAutoSize(true);
  118. try {
  119. SystemTray tray = SystemTray.getSystemTray();
  120. tray.add(trayIcon);
  121. trayIcon.displayMessage("Client", "Initiated client.", TrayIcon.MessageType.INFO);
  122. PopupMenu menu = new PopupMenu();
  123. final MenuItem minimizeItem = new MenuItem("Minimize to Tray");
  124. MenuItem exitItem = new MenuItem("Exit");
  125. menu.add(minimizeItem);
  126. menu.add(exitItem);
  127. trayIcon.setPopupMenu(menu);
  128. ActionListener minimizeListener = new ActionListener() {
  129. public void actionPerformed(ActionEvent e) {
  130. AlertifyBuilder bldr = new AlertifyBuilder();
  131. bldr.type(AlertifyType.WARNING);
  132. Alertify.show(
  133. bldr.text("Lololol").autoClose(5000L).callback(new AlertifyWindowClick() {
  134. @Override
  135. public void alertClicked(AlertifyWindow window) {
  136.  
  137. }
  138. }).build());
  139. }
  140. };
  141. minimizeItem.addActionListener(minimizeListener);
  142. ActionListener exitListener = new ActionListener() {
  143. public void actionPerformed(ActionEvent e) {
  144. System.exit(0);
  145. }
  146. };
  147. exitItem.addActionListener(exitListener);
  148. } catch (AWTException e) {
  149. System.err.println(e);
  150. }
  151. }
  152. }
  153.  
  154.  
  155.  
  156.  
  157.  
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement