A newbie here so forgive me.
This is my code:
Parent/main/JFrame:
public class Home extends javax.swing.JFrame {
public Home() {
initComponents();
setIcon("icon"); // set the taskbar icon
}
public static void main(String args[]) {
// main code here, including tray initialization
new Home().setVisible(true);
}
public void start() {
// code here
}
}
Child class:
public class Tray extends Home {
static TrayIcon trayIcon;
private static void ShowTrayIcon(String status) {
if (!SystemTray.isSupported()) {
System.out.println("Tray not supported");
System.exit(0);
return;
}
final PopupMenu popup = new PopupMenu();
final SystemTray tray = SystemTray.getSystemTray();
trayIcon = new TrayIcon(CreateIcon("/Images/off.png", "desc"));
MenuItem StartItem = new MenuItem("Start");
popup.add(StartItem);
trayIcon.setPopupMenu(popup);
// open from tray
StartItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
start();
}
});
try {
tray.add(trayIcon);
} catch (AWTException e) {
}
}
protected static Image CreateIcon(String path, String desc) {
URL ImageURL = Tray.class.getResource(path);
if (ImageURL == null) {
System.err.println("Resource not found: " + path);
return null;
} else {
// System.err.println("Resource found: " + path);
return (new ImageIcon(ImageURL, desc)).getImage();
}
}
public void start() {
super.start();
}
}
the start() method in child class works, but when I try to call that from the actionlistener of the trayicon, it keeps saying 'non static method start() cannot be referenced from static context'.
Tried using super.start() in the actionlistener method but that doesn't work either.
What I'm trying to do; Home class is my JFrame and main class, I have another class set up that handles my tray icons, and got some buttons in the tray that will call some methods from the main class when invoked.
Any help would be appreciated.