ここで初心者は私を許します。トレイアイコンを使用して子クラスから親クラスのメソッドを呼び出すことはできません
これは私のコードです:
親/メイン/ 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
}
}
子クラス:子クラスの作品に
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();
}
}
start()メソッドが、私がしようとすると、トレーチコンのactionlistenerから呼び出すために、 '非静的メソッドstart()は静的コンテキストから参照できません'ということを続けます。
actionlistenerメソッドでsuper.start()を使用しようとしましたが、動作しません。
私が何をしようとしているのですか。ホームクラスは私のJFrameとメインクラスです。トレイアイコンを扱う別のクラスを用意しています。呼び出されるとメインクラスからいくつかのメソッドを呼び出すトレイのボタンがいくつかあります。
ご協力いただければ幸いです。私が正しい場合