hello everybody,
I am new to all of this
Java stuff and would like some help with an
applet that I am trying to minimize to the systray. If this is possible?
why I am using an applet? I need a small app to launch from my database system that has a php front end, basically I have a php mysql database program that records an employees work time. What I need is, after closing the parent system a small app that launchs and runs in the system tray. This app/applet is launched from the php page displays a message then is minimized to the system tray.
so far I have an applet with a JFrame and Jpanel I have a windowlistener that will display a joptionPane but will NOT invoke my TrayIcon class below is the code that I am using.
Any help would be much appreciated.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class WritsGui extends JApplet
{
public void init()
{
// create a frame with a JLabel
final JFrame frame = new JFrame();
frame.addWindowListener( new WindowAdapter() {
// This window listener responds when the user
// clicks the window's close box by giving the
// user a chance to change his mind.
public void windowClosing(WindowEvent evt) {
JOptionPane.showConfirmDialog(null, "or no",
"choose yes",JOptionPane.YES_NO_OPTION);
}
});
frame.setTitle("Writs");
frame.setSize(600, 400);
frame.add(new JLabels());
frame.setVisible(!frame.isVisible());
}
}
class JLabels extends JPanel
{
public JLabels() {
// create button
JButton btn1 = new JButton("Button1");
setLayout(new BorderLayout( ));
ImageIcon labelIcon = new ImageIcon( "Logo.png" );
JLabel centerLabel = new JLabel( labelIcon );
JLabel southLabel = new JLabel( labelIcon );
add( southLabel, BorderLayout.NORTH );
// add button to panel
add(btn1, BorderLayout.SOUTH);
// create button action
ActionListener listener = new trayTest();
btn1.addActionListener(listener);
add(new JLabel ("<html>The Applied Physics Laboratory is a division " +
"of the Johns Hopkins University." +
"<P>" +
"Major JHU divisions include:" +
"<UL>" +
" <LI>The Applied Physics Laboratory" +
" <LI>The Krieger School of Arts and Sciences" +
" <LI>The Whiting School of Engineering" +
" <LI>The School of Medicine" +
" <LI>The School of Public Health" +
" <LI>The School of Nursing" +
" <LI>The Peabody Institute" +
" <LI>The Nitze School of Advanced International Studies" +
"</UL>"),BorderLayout.CENTER);
}
}
class trayTest implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
if (SystemTray.isSupported()) {
SystemTray tray = SystemTray.getSystemTray();
Image image = Toolkit.getDefaultToolkit().getImage("today.jpg");
PopupMenu popup = new PopupMenu();
MenuItem item = new MenuItem("A MenuItem");
popup.add(item);
TrayIcon trayIcon = new TrayIcon(image, "The Tip Text", popup);
try {
tray.add(trayIcon);
} catch (AWTException e) {
System.err.println("Can't add to tray");
}
} else {
System.err.println("Tray unavailable");
}
}
};