我想特別注意到在我的Java應用程序中發生什麼事情時,我試圖使窗口閃爍(在Mac和Windows上)。但是,我是新來的Java和鬱悶的靜態/非靜態方法爵士樂。調用非靜態類java
但是我的挫折一邊,我怎麼稱呼我的toggleVisible類?
我已經刪除了不必要的代碼:
public static void main(String args[]) {
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
checkAlerts();
}
}, 30000, 30000);
}
public static Boolean checkAlerts(){
if(count == 0){
JOptionPane.showMessageDialog(null, "No results");
} else {
toggleVisible();
JOptionPane.showMessageDialog(null, "Some results back");
}
}
public void toggleVisible() {
setVisible(!isVisible());
if (isVisible()) {
toFront();
requestFocus();
setAlwaysOnTop(true);
try {
//remember the last location of mouse
final Point oldMouseLocation = MouseInfo.getPointerInfo().getLocation();
//simulate a mouse click on title bar of window
Robot robot = new Robot();
robot.mouseMove(mainFrame.getX() + 100, mainFrame.getY() + 5);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
//move mouse to old location
robot.mouseMove((int) oldMouseLocation.getX(), (int) oldMouseLocation.getY());
} catch (Exception ex) {
//just ignore exception, or you can handle it as you want
} finally {
setAlwaysOnTop(false);
}
}
}
toggleVisible給我的錯誤:非靜態方法toggleVisible()不能從靜態上下文引用。
請提供完整的類。 –
對不起,能否詳細說明一下?你需要所有的課程? – TMB87
當我將其聲明爲靜態時,會出現很多錯誤 – TMB87