import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class HoorayWithTimer extends javax.swing.JFrame {
int counter;
public HoorayWithTimer() {
initComponents();
}
/*
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
timerLabel = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(timerLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 334, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 271, Short.MAX_VALUE)
.addComponent(timerLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
);
timerLabel.getAccessibleContext().setAccessibleName("timerLabel");
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(HoorayWithTimer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(HoorayWithTimer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(HoorayWithTimer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(HoorayWithTimer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
Timer timer = new Timer(10000, new ActionListener() {
public void actionPerformed(ActionEvent e) {
HoorayWithTimer.setVisible(false);
HoorayWithTimer.dispose();
}
});
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new HoorayWithTimer().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel timerLabel;
// End of variables declaration
}
所以是的,我从菜单中有一个菜单,您可以在 somone 获胜时启动 3 种不同的游戏 关闭万岁屏幕并返回仍然打开的游戏。菜单始终在后台保持打开状态,因为我也无法关闭或 dispose()。
总是出错:不能从静态上下文中引用非静态方法 setVisible(boolean)
我对java有点陌生,所以请耐心等待......哈哈