TrayIcon
Aus Programmers Guide
Roy (Diskussion | Beiträge) |
Roy (Diskussion | Beiträge) |
||
Zeile 1: | Zeile 1: | ||
- | import java.awt.AWTException; | + | <source lang="java> |
+ | import java.awt.AWTException; | ||
+ | import java.awt.Frame; | ||
+ | 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.awt.event.MouseEvent; | ||
+ | import java.awt.event.MouseListener; | ||
- | |||
- | private static TrayIcon trayIcon; | + | public class Icon { |
+ | private static TrayIcon trayIcon; | ||
+ | private SystemTray tray; | ||
+ | private Image image; | ||
+ | private MouseListener mouseListener; | ||
+ | private String info = null; | ||
+ | private String titelhover = "Titel"; | ||
+ | private String latestinfo = ""; | ||
+ | private PopupMenu popup; | ||
+ | private MenuItem openItem; | ||
+ | private String logoString = ""; | ||
- | + | //Konstruktor | |
+ | public Icon() { | ||
+ | if (SystemTray.isSupported()) { | ||
+ | tray = SystemTray.getSystemTray(); | ||
+ | image = Toolkit.getDefaultToolkit().getImage(Icon.class.getResource(logoString)); | ||
+ | popup = new PopupMenu(); | ||
+ | popup.setName("Menue"); | ||
+ | popup.setFont(schrift); | ||
- | + | openItem = new MenuItem("TitelAnzeige öffnen"); | |
+ | popup.add(openItem); | ||
- | + | trayIcon = new TrayIcon(image, titelhover, popup); | |
- | |||
- | + | ActionListener actionListener = new ActionListener() { | |
+ | public void actionPerformed(ActionEvent e) { | ||
+ | if (Window.getF().getState() == 1) { | ||
+ | Window.getF().setState(Frame.NORMAL); | ||
+ | Window.getF().setVisible(true); | ||
+ | }else if (Window.getF().getState() == 0) { | ||
+ | Window.getF().setState(Frame.ICONIFIED); | ||
+ | Window.getF().setVisible(false); | ||
+ | } | ||
+ | } | ||
+ | }; | ||
+ | trayIcon.setImageAutoSize(true); | ||
+ | trayIcon.addActionListener(actionListener); | ||
+ | trayIcon.addMouseListener(mouseListener); | ||
- | + | try{ | |
+ | tray.add(trayIcon); | ||
+ | } catch (AWTException e) { | ||
+ | System.err.println("TrayIcon kann nicht hinzugefuegt werden..."); | ||
+ | } | ||
+ | }else{ | ||
+ | // System Tray is not supported | ||
+ | System.err.println("Leider unterstützt Ihre Java-Version das Systemtray nicht, bitte updaten sie diese."); | ||
+ | } | ||
- | + | public static TrayIcon getTrayIcon() { | |
+ | return trayIcon; | ||
+ | } | ||
- | public void | + | public void setTip(String tip) { |
+ | trayIcon.setToolTip(tip); | ||
+ | } | ||
- | public void | + | public void setInfoString(String info){ |
+ | trayIcon.displayMessage("Information",info,TrayIcon.MessageType.INFO); | ||
+ | } | ||
- | + | public static void message(String msg){ | |
- | + | trayIcon.displayMessage("Information",msg,TrayIcon.MessageType.INFO); | |
- | + | } | |
- | + | } | |
- | + | </source> | |
- | + | [[Category:Java]][[Category:Klassen]] | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | [[Category:Java]] | + |
Version vom 10:09, 30. Mär. 2010
Ungültige Sprache.
Die gewünschte Sprache muss wie folgt definiert werden: <source lang="html4strict">...</source>
Unterstützte Sprachen für die Syntax-Hervorhebung:
4cs, abap, actionscript, actionscript3, ada, apache, applescript, apt_sources, asm, asp, autohotkey, autoit, avisynth, awk, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, c_mac, caddcl, cadlisp, cfdg, cfm, cil, clojure, cmake, cobol, cpp, cpp-qt, csharp, css, cuesheet, d, dcs, delphi, diff, div, dos, dot, eiffel, email, erlang, fo, fortran, freebasic, fsharp, gambas, gdb, genero, gettext, glsl, gml, gnuplot, groovy, haskell, hq9plus, html4strict, idl, ini, inno, intercal, io, java, java5, javascript, jquery, kixtart, klonec, klonecpp, latex, lisp, locobasic, logtalk, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, make, mapbasic, matlab, mirc, mmix, modula3, mpasm, mxml, mysql, newlisp, nsis, oberon2, objc, ocaml, ocaml-brief, oobas, oracle11, oracle8, pascal, per, perl, perl6, php, php-brief, pic16, pike, pixelbender, plsql, povray, powerbuilder, powershell, progress, prolog, properties, providex, purebasic, python, qbasic, rails, rebol, reg, robots, rsplus, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, systemverilog, tcl, teraterm, text, thinbasic, tsql, typoscript, vb, vbnet, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xml, xorg_conf, xpp, z80