• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

minimise to systray

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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");
}
}
};







 
Sheriff
Posts: 28328
96
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 28328
96
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?





 
it's a teeny, tiny, wafer thin ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic