當我鍵入t.schedule(umm.setVisible(false), 5);
時,我得到的錯誤和void類型是不允許的。有人可以幫我解決這個問題嗎?非靜態方法不能被引用,void類型不允許
public class menu extends JFrame{
JLabel bgmenu=new JLabel();
JLabel java=new JLabel();
JLabel umm=new JLabel();
JLayeredPane jLayeredPane1=new JLayeredPane();
public menu(){
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
//label
umm.setIcon(new javax.swing.ImageIcon("D:\\Job\\Kuliah\\4\\DAMG\\Game\\pic\\umm.jpg"));
umm.setBounds(0, 0, 1024, 709);
java.setIcon(new javax.swing.ImageIcon("D:\\Job\\Kuliah\\4\\DAMG\\Game\\pic\\java.jpg"));
java.setBounds(0, 0, 1024, 709);
bgmenu.setIcon(new javax.swing.ImageIcon("D:\\Job\\Kuliah\\4\\DAMG\\Game\\pic\\interfacemainmenu.jpg"));
bgmenu.setBounds(0, 0, 1024, 709);
//posisi
jLayeredPane1.add(umm, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLayeredPane1.add(java, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLayeredPane1.add(bgmenu, javax.swing.JLayeredPane.DEFAULT_LAYER);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1024, javax.swing.GroupLayout.PREFERRED_SIZE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 709, javax.swing.GroupLayout.PREFERRED_SIZE)
);
pack();
}
public static void main(String[] args) {
new menu().setVisible(true);
Timer t=new Timer();
//get error here under this comment
t.schedule(umm.setVisible(false), 5);
}
重新檢查'schedule'方法的簽名並查看'setVisible'返回類型。 – mishadoff 2012-03-23 00:23:24
另請考慮['javax.swing.Timer' v。'java.util.Timer'](http://java.sun.com/products/jfc/tsc/articles/timer/)。 – trashgod 2012-03-23 00:33:43
@ carl-manaster thx,現在明確:) – 2012-03-23 01:34:16