Results 1 to 4 of 4
  1. #1
    xalebo is offline Member
    Join Date
    Nov 2011
    Posts
    5
    Rep Power
    0

    Post Repeating or Looping a Whole Frame

    I have got a frame which i did which has got methods and stuff and works perfectly but i want that this frame continues or loops for only 10 times (don't tell me why idk -.-'). It continues literally forever when i run it. And another thing my professor told me that i must do a frame with methods etc and then a normal class to show that frame and that i cant use swing :s. But the prob is the loop. Any help? I kept swearing all the night ... I guess that is a programmer's life :P

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,412
    Rep Power
    25

    Default Re: Repeating or Looping a Whole Frame

    Please post the code with the loop if you want help fixing it. Be sure to wrap the code in code tags.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    xalebo is offline Member
    Join Date
    Nov 2011
    Posts
    5
    Rep Power
    0

    Default Re: Repeating or Looping a Whole Frame

    Java Code:
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Scanner;
    import javax.swing.*;
    
    public class PenaltyFrame extends Frame implements ActionListener{
    
    	Button btnBL, btnTL, btnBC, btnTC, btnBR, btnTR;
    	Image image;
    
    	public PenaltyFrame(){
    
    		setLayout(null);
    
    		btnBL = new Button("BOTTOM LEFT 1");
    		btnBL.addActionListener(this);
    		btnTL = new Button("TOP LEFT 4");
    		btnTL.addActionListener(this);
    		btnBC = new Button("BOTTOM CENTRE 2");
    		btnBC.addActionListener(this);
    		btnTC = new Button("TOP CENTRE 5");
    		btnTC.addActionListener(this);
    		btnBR = new Button("BOTTOM RIGHT 3");
    		btnBR.addActionListener(this);
    		btnTR = new Button("TOP RIGHT 6");
    		btnTR.addActionListener(this);
    
    		btnBL.setBounds(100,450,100,50);
    		btnTL.setBounds(250,450,100,50);
    		btnBC.setBounds(350,450,100,50);
    		btnTC.setBounds(450,450,100,50);
    		btnBR.setBounds(550,450,100,50);
    		btnTR.setBounds(650,450,100,50);
    
    		add(btnBL);
    		add(btnTL);
    		add(btnBC);
    		add(btnTC);
    		add(btnBR);
    		add(btnTR);
    
    	}
    	float score =0;
    	int count=0;
    
    	public void actionPerformed(ActionEvent ae){
    
    			if(ae.getSource()==btnBL){
    				bottomLeft();
    				count++;
    			}else if(ae.getSource()==btnBC){
    				bottomCentre();
    				count++;
    			}else if(ae.getSource()==btnBR){
    				bottomRight();
    				count++;
    			}else if(ae.getSource()==btnTL){
    				topLeft();
    				count++;
    			}else if(ae.getSource()==btnTC){
    				topCentre();
    				count++;
    			}else if(ae.getSource()==btnTR){
    				topRight();
    				count++;
    			}
    
    
    	}
    
    	public void bottomLeft(){
    		int choice = (int)(Math.random()*6);
    			if(choice != 1){
    				score=score+5;
    				JOptionPane.showMessageDialog(this, "Penalty Scored", "SUCCESS", JOptionPane.PLAIN_MESSAGE);
    				JOptionPane.showMessageDialog(this, "Points (+5)", "SUCCESS", JOptionPane.PLAIN_MESSAGE);
    			}else if(choice == 1){
    				JOptionPane.showMessageDialog(this, "Penalty Failed", "FAILURE", JOptionPane.PLAIN_MESSAGE);
    			}
    	}
    
    	public void bottomCentre(){
    		int choice = (int)(Math.random()*6);
    			if(choice != 2){
    				score=score+5;
    				JOptionPane.showMessageDialog(this, "Penalty Scored", "SUCCESS", JOptionPane.PLAIN_MESSAGE);
    				JOptionPane.showMessageDialog(this, "Points (+5)", "SUCCESS", JOptionPane.PLAIN_MESSAGE);
    			}else if(choice == 2){
    				JOptionPane.showMessageDialog(this, "Penalty Failed", "FAILURE", JOptionPane.PLAIN_MESSAGE);
    			}
    	}
    
    	public void bottomRight(){
    		int choice = (int)(Math.random()*6);
    			if(choice != 3){
    				score=score+5;
    				JOptionPane.showMessageDialog(this, "Penalty Scored", "SUCCESS", JOptionPane.PLAIN_MESSAGE);
    				JOptionPane.showMessageDialog(this, "Points (+5)", "SUCCESS", JOptionPane.PLAIN_MESSAGE);
    			}else if(choice == 3){
    				JOptionPane.showMessageDialog(this, "Penalty Failed", "FAILURE", JOptionPane.PLAIN_MESSAGE);
    			}
    	}
    
    	public void topLeft(){
    		int choice = (int)(Math.random()*6);
    			if(choice != 4){
    				score=score+5;
    				JOptionPane.showMessageDialog(this, "Penalty Scored", "SUCCESS", JOptionPane.PLAIN_MESSAGE);
    				JOptionPane.showMessageDialog(this, "Points (+5)", "SUCCESS", JOptionPane.PLAIN_MESSAGE);
    			}else if(choice == 4){
    				JOptionPane.showMessageDialog(this, "Penalty Failed", "FAILURE", JOptionPane.PLAIN_MESSAGE);
    			}
    	}
    
    	public void topCentre(){
    		int choice = (int)(Math.random()*6);
    			if(choice != 5){
    				score=score+5;
    				JOptionPane.showMessageDialog(this, "Penalty Scored", "SUCCESS", JOptionPane.PLAIN_MESSAGE);
    				JOptionPane.showMessageDialog(this, "Points (+5)", "SUCCESS", JOptionPane.PLAIN_MESSAGE);
    			}else if(choice == 5){
    				JOptionPane.showMessageDialog(this, "Penalty Failed", "FAILURE", JOptionPane.PLAIN_MESSAGE);
    			}
    	}
    
    	public void topRight(){
    		int choice = (int)(Math.random()*6);
    			if(choice != 6){
    				score=score+5;
    				JOptionPane.showMessageDialog(this, "Penalty Scored", "SUCCESS", JOptionPane.PLAIN_MESSAGE);
    				JOptionPane.showMessageDialog(this, "Points (+5)", "SUCCESS", JOptionPane.PLAIN_MESSAGE);
    			}else if(choice == 6){
    				JOptionPane.showMessageDialog(this, "Penalty Failed", "FAILURE", JOptionPane.PLAIN_MESSAGE);
    			}
    	}
    
    	public void paint(Graphics g){
    
    		image = Toolkit.getDefaultToolkit().getImage("PenaltyShot.jpg");
    		g.drawImage(image, 300, 50, this);
    	}
    
    }
    That is all the program that i need to be repeated or looped. Thx :)

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,412
    Rep Power
    25

    Default Re: Repeating or Looping a Whole Frame

    What actions in the program do you want to be inside of the loop?

    . It continues literally forever when i run it.
    Where does the code loop? I don't see any loops in the posted code.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Repeating too many times.
    By trishtren in forum New To Java
    Replies: 4
    Last Post: 11-11-2011, 12:20 AM
  2. Repeating a letter
    By passingTime in forum New To Java
    Replies: 3
    Last Post: 03-13-2011, 09:43 PM
  3. Replies: 4
    Last Post: 01-18-2011, 08:22 AM
  4. Java slave Frame access to its owner main frame problem
    By cagdaseckin in forum New To Java
    Replies: 0
    Last Post: 12-10-2010, 10:40 AM
  5. Repeating
    By AbdulAziz Bader in forum New To Java
    Replies: 3
    Last Post: 05-05-2010, 11:35 PM

Tags for this Thread

Posting Permissions

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