Hey everyone, this program displays a ball in a screen moving a set speed, set by the Time object clock at 20. One of my jobs is to allow the user to go to the menu, click on set speed option and enter any speed. So far, I've gotten as far as getting the window up asking the user to enter their desired amount. My problem is how to get that amount to a time object allowing it to change from the default. I tried multiple things, none seemed to work. I was now thinking instead of 2 Timer's. I put a variable where the 20 is in Timer clock. But I dont know how to pass the numSpeed to it. Help would be greatly appreciated. Thanks!

(Ps I didn't include the other files of code, I didn't think it would be necessary)


Java Code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Random;

public class RollB extends JPanel implements ActionListener{
  String inputSpeed;
  String inputCount;
  int numBall;
  int numSpeed; 
  int s;

  Random random = new Random();
  int ranStart = random.nextInt(60) + 1;
  int width = 700; int height = 250; 
  Timer clock = new Timer(20,this); 
  Timer newClock = new Timer(numSpeed,this);
  int NWall = 0; int WWall = 0; int EWall = width; int SWall = height;
  int h = 3; int v = 2; 
  int x = 125; int y = 21;
  Ball ball = new Ball(x,y,50,h,v);
  JMenuBar b;
  JMenu menu = new JMenu("Game Controls");
  JMenuItem quit = new JMenuItem("Quit");
  JMenuItem stop = new JMenuItem("Stop");
  JMenuItem start = new JMenuItem("Start");
  JMenuItem speed = new JMenuItem("Speed");
  JMenuItem newStart = new JMenuItem("New Start");
  JMenuItem ballCount = new JMenuItem("Ball Count");
  
  public RollB(JMenuBar bar){
    
    clock.start();
    newClock.start();
    this.b=bar;
    b.add(menu);
    menu.add(quit);
    menu.add(stop);
    menu.add(start);
    menu.add(speed);
    menu.add(newStart);
    menu.add(ballCount);
    quit.addActionListener(this);
    stop.addActionListener(this);
    start.addActionListener(this);
    speed.addActionListener(this);
    newStart.addActionListener(this);
    ballCount.addActionListener(this);
    setPreferredSize(new Dimension(width,height));
    setBackground(Color.white);
    
  }
  
  
  public void paintComponent(Graphics g){
    super.paintComponent(g);
    g.drawRect(0,0,width,height);
    drawBalls(g);
  }
  
  public void drawBalls(Graphics g){
    g.fillOval(ball.getX(),ball.getY(),ball.getR(),ball.getR());
  }
  
   public void reflectBalls(){
     // when ball reaches (crosses) a wall, it flips (bounces)
    if (ball.getY() <= NWall) ball.flipVertical();
    else if (ball.getY() >= (SWall-50)) ball.flipVertical();
    else if (ball.getX() <= WWall) ball.flipHorizontal();
    else if (ball.getX() >= EWall-50) ball.flipHorizontal();
  }

   public void advanceBalls(){
     // ball moves ahead h,v units
     ball.advance();
   }
   
  public void actionPerformed(ActionEvent e){ 
  
    if(e.getSource()==quit) System.exit(0);
    else if(e.getSource()==stop) {clock.stop();}
    else if (e.getSource() == clock) {
      advanceBalls();
      reflectBalls();
    }
    
    else if(e.getSource()==start) clock.start();
    else if(e.getSource()==speed){
      inputSpeed=JOptionPane.showInputDialog("Enter delay (smaller=faster)");
      numSpeed=Integer.parseInt(inputSpeed);

    }
    repaint();
    
    }
}