Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2010
    Posts
    47
    Rep Power
    0

    Question 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();
                 
     					
    		}
    	}

  2. #2
    Join Date
    Sep 2010
    Posts
    47
    Rep Power
    0

    Default

    Bump, anyone? :/

  3. #3
    Join Date
    Sep 2010
    Posts
    47
    Rep Power
    0

    Default

    Cmon, someone must be able to help :/

  4. #4
    Join Date
    Sep 2010
    Posts
    47
    Rep Power
    0

    Default

    i'll bump one last time to see if anyone cares to respond.

  5. #5
    NRitH is offline Senior Member
    Join Date
    Feb 2011
    Posts
    118
    Rep Power
    0

    Default

    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,

    1. create an instance variable for the one and only instance of your window
    2. replace new win() in actionPerformed() with window.setVisible(true)
    3. 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 09:23 PM.

Similar Threads

  1. Java Popup Window & Url Query String Value
    By Rivelyn in forum New To Java
    Replies: 4
    Last Post: 01-20-2011, 06:03 AM
  2. How to create a Popup window
    By sarwar1234 in forum New To Java
    Replies: 2
    Last Post: 09-29-2010, 05:38 PM
  3. Replies: 1
    Last Post: 08-18-2010, 08:20 AM
  4. Javascript to generate popup window
    By vrk in forum Advanced Java
    Replies: 3
    Last Post: 03-20-2009, 09:20 AM
  5. how we get popup window in java
    By baserohit in forum Advanced Java
    Replies: 1
    Last Post: 03-22-2008, 05:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •