Ball Code

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package group3;

import com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComponent;
import javax.swing.Timer;


/**
 *
 * @author jgoudy
 */
public class ball extends JComponent {
    private int mradius;
    private int mxpos;
    private int mypos;
    private int mspeed = 1;
    private int mxdir = 1;
    private int mydir = 1;
    private Color mcolor;
    private int mcvwidth;
    private int mcvheight;
    private int mrise;
    private int mrun;

    private Timer bTimer;

    public ball(int radius, int xpos, int ypos,
            int speed, int rise, int run, int cvwidth, int cvheight, Color xColor) {

        this.mradius = radius;
        this.mxpos = xpos;
        this.mypos = ypos;
        this.mspeed = speed;
        this.mcolor = xColor;
        this.mcvwidth = cvwidth / 2;
        this.mcvheight = cvheight / 2;
        this.mrise = rise;
        this.mrun = run;
        //this.setSize(mcvwidth, mcvheight);

        btime();
        bTimer.start();

    }

    public void paintComponent(Graphics g) {

        //super.paintComponent(g); 
        g.setColor(mcolor);
        g.fillOval(mxpos, mypos, mradius, mradius);

    }

    private void btime() {
        bTimer = new Timer(mspeed,
                new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent ae) {

                        if (mxpos > mcvwidth) {
                            mxdir = mxdir * -1;
                            mxpos = mcvwidth - 1;
                        } else if (mxpos < -1) {
                            mxdir = mxdir * -1;
                            mxpos = 0;
                        }

                        if (mypos > mcvheight) {
                            mydir = mydir * -1;
                            mypos = mcvheight;

                        } else if (mypos < -1) {
                            mydir = mydir * -1;
                            mypos = 0;

                        }

                        mxpos = mxpos + (mxdir * mrun);
                        mypos = mypos + (mydir * mrise);
                        setLocation(mxpos, mypos);


                    }
                  
                }
        );

    }

}