Results 1 to 5 of 5
Thread: Double window popup :/
- 03-01-2011, 03:38 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 47
- Rep Power
- 0
Double window popup :/
Hi.
I've made a game.
And when the game is over(the timer reaches 0) the game calls "new win();"
which is my end of game window.. the thing is that when the "win" window get's created. it comes up 2 windows. not one. Below is my win class and my timer class. the win class is inside the class "Move", but that dosen't matter. all the code related to the problem should be located below:
And please note that this code isn't completely finished, just trying to fix this double window prob before i move on.
PHP Code:public class clock implements Runnable, ActionListener{ private class win extends JFrame implements ActionListener{ private JButton again; private JLabel score1; private JLabel score2; public win(){ super("Game Over"); again = new JButton("Play again"); score1 = new JLabel("Player1(RED) score:" + p1score); score2 = new JLabel("Player2(GREEN) score:" + p2score); again.addActionListener(this); setLayout(new FlowLayout()); add(again); add(score1); add(score2); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(false); setLocation(900, 250); setSize(400, 200); setResizable(false); } public void actionPerformed(ActionEvent e) { if(e.getSource() == again){ new reseter(); }if(e.getSource() == timer){ left.setText("Time left: " + tic); tic--; left.setText("Time left: " + tic); } if(tic == 25){ delay.stop(); sc.stop(); enemytimer.stop(); tic = 30; t1.stop(); timer.stop(); setVisible(true); new win(); } } } Timer timer = new Timer(1000, new win()); win w = new win(); public void run(){ setVisible(true); timer.start(); left.setText("Time left: " + tic); } public void actionPerformed(ActionEvent e) { } public void keyPressed(KeyEvent e) { timer.stop(); } }
- 03-01-2011, 04:02 PM #2
Member
- Join Date
- Sep 2010
- Posts
- 47
- Rep Power
- 0
Bump, anyone? :/
- 03-01-2011, 04:59 PM #3
Member
- Join Date
- Sep 2010
- Posts
- 47
- Rep Power
- 0
Cmon, someone must be able to help :/
- 03-01-2011, 05:56 PM #4
Member
- Join Date
- Sep 2010
- Posts
- 47
- Rep Power
- 0
i'll bump one last time to see if anyone cares to respond.
- 03-01-2011, 08:19 PM #5
Senior Member
- Join Date
- Feb 2011
- Posts
- 118
- Rep Power
- 0
Kee-rist. Where to begin?
First, you're instantiating 3 windows: one in actionPerformed(), one as an instance variable, and once in the construction of Timer. WHY? You need only one, and can show and hide it when necessary. It looks to me that what's happening is that it's being shown once in actionPerformed(), and once when the Timer expires. That can't be right. To fix it,
- create an instance variable for the one and only instance of your window
- replace new win() in actionPerformed() with window.setVisible(true)
- pass the window instance, not a new one, to the Timer constructor
There's more to it, but I'll leave that up to you.Last edited by NRitH; 03-01-2011 at 08:23 PM.
Similar Threads
-
Java Popup Window & Url Query String Value
By Rivelyn in forum New To JavaReplies: 4Last Post: 01-20-2011, 05:03 AM -
How to create a Popup window
By sarwar1234 in forum New To JavaReplies: 2Last Post: 09-29-2010, 04:38 PM -
How to hide the titlebar of popup window in IE-7 in js(urgent )
By john_thomas03 in forum New To JavaReplies: 1Last Post: 08-18-2010, 07:20 AM -
Javascript to generate popup window
By vrk in forum Advanced JavaReplies: 3Last Post: 03-20-2009, 08:20 AM -
how we get popup window in java
By baserohit in forum Advanced JavaReplies: 1Last Post: 03-22-2008, 04:39 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks