我有一个主机和一个带有计时器的strartscreen从3,2,1倒计时。 我已经设置了主机main.setVisible(false)但是当计时器达到0时我希望它是main.setVisible(true)。我做了这个,但它似乎没有工作,我不知道我做错了什么。这是我到目前为止: *大型机:
public class MainPanel extends JPanel {
public JLabel welkom, vraag, vraagnr, minimize, close;
public JButton btnVolgende, btnExit, btnVraag;
public ImageIcon icon;
public MainPanel() {
setLayout(null);
setVisible(false); // visibility false
Timerframe:
MainPanel main = new MainPanel();
Vraag1 vraag1 = new Vraag1();
ActionListener listener = new ActionListener()
{
int seconden = 3;
public void actionPerformed(ActionEvent e) {
seconden--;
if(seconden > 0)
{
countdown.setText("" + seconden);
}
else if(seconden == 0)
{
main.setVisible(true); //setframe visible
vraag1.setVisible(true);
setVisible(false);
}
}
};
afteller = new Timer(1000, listener);
afteller.start();
}
这是我的JFrame:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseListener;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import com.sun.glass.events.MouseEvent;
public class Frame {
static JFrame frame;
static MainPanel paneel;
static Vraag1 vraag1;
static StartScherm start;
public static void main(String[] args) {
// TODO Auto-generated method stub
frame = new JFrame();
frame.setLayout(null);
frame.setTitle("Voetbal quiz - Edward Kerckhof");
frame.setSize(1191,677);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon icon = new ImageIcon("src/images/voetbal.PNG");
frame.setIconImage(icon.getImage());
vraag1 = new Vraag1();
vraag1.setBounds(0,0,1191,677);
frame.add(vraag1);
paneel = new MainPanel();
paneel.setBounds(0,0,1191,677);
frame.add(paneel);
start = new StartScherm();
start.setBounds(0,0,1191,677);
frame.add(start);
frame.setVisible(true);
}
}