File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes minimise to systray Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "minimise to systray" Watch "minimise to systray" New topic
Author

minimise to systray

Stephen O'Connor
Greenhorn

Joined: Oct 19, 2010
Posts: 11
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");
}
}
};







Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18113
    
    8

stephen oconnor wrote: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?

I very much doubt it. On most operating systems the "systray" can only contain applications which are running as a process. An applet isn't such a thing.
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.

Then why aren't you using Java Web Start? That's the standard way to launch a Java application from a web site.
Stephen O'Connor
Greenhorn

Joined: Oct 19, 2010
Posts: 11
hello Paul,

thanks for yr response and yr advice. so an applet is not a process but a JFrame is? I got some code that runs a JFrame from command prompt, the code is a basic JFrame that minimizes to "systray".

Can I display a frame or dialog using an applet and the frame contains a button that when the user clicks the button the frame is minimised to the "sysTray"? its just I have been tring to learn about applets and now I have to learn java web atart. I hope it wasn't a total waste of time..

will take a look at javaws its always fun to learn something new.






Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18113
    
    8

stephen oconnor wrote:Can I display a frame or dialog using an applet and the frame contains a button that when the user clicks the button the frame is minimised to the "sysTray"? its just I have been tring to learn about applets and now I have to learn java web atart. I hope it wasn't a total waste of time..

No, a JFrame popped up from an applet is still part of the applet, which is still part of the browser. It's all one process.
will take a look at javaws its always fun to learn something new.

The programming for applets and applications is basically the same, especially if the application is going to be distributed by JWS. The main problem with applets (and with Web Start) is getting the configuration right. However in neither case is it horrendously difficult to do that.
Stephen O'Connor
Greenhorn

Joined: Oct 19, 2010
Posts: 11
Paul,

Thanks a million for taking the time to answer my questions. No wonder I was having so much trouble trying to get that applet to work. I see what you mean by the same process, makes sense alright.

Maybe not horrendously difficult, just difficult for me anyway... what do you mean by getting the configuration right?

Have you any suggestions on where to start? so far I took a look at wiki and the sun tutorials do you know of any good site to learn about JWS with good examples?





 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: minimise to systray
 
Similar Threads
Error loading image jar
menu with hotkeys in applet using AWT only
How to Add a Systemtray Icon on several machines ?
System Tray - double click icon to set visible
questions regarding system tray and tray icon