import java.util.observable;
public class model extends observable
{
public final int ball_size=20;
private int xposition;
private int yposition;
private int xlimit, ylimit;
private int xdelta=6;
private int ydelta=4;

public void setlimit(int xlimit, int ylimit)
{
this.xlimit=xlimit-ball_size;
this.ylimit=ylimit-ball_size;
}

public int getx()
{
return xposition;
}

public int gety()
{
return yposition;
}

public void makeonestep()
{
xposition+=xdelta;
if(xposition<0||xposition>=xlimit)
{
xdelta=-xdelta;
xposition+=xdelta;
}
yposition+=ydelta;
if(yposition<0||yposition>=ylimit)
{
ydelta=-ydelta;
yposition+=ydelta;
}
setchanged();
notifyobservers();
}

}
-------------------------------------------------------------------
import javax.swing.jcombobox;
import javax.swing.jpanel;
import java.awt.*;
import java.awt.event.itemevent;
import java.awt.event.itemlistener;
import java.util.*;
class view extends jpanel implements observer
{
model model;
view(model model)
{
this.model=model;
}
@override
public void paint(graphics g)
{

g.setcolor(color.white);
g.fillrect(0, 0, getwidth(), getheight());
g.setcolor(color.red);
g.filloval(model.getx(), model.gety(), model.ball_size, model.ball_size);

}
public void update(observable obs, object agr)
{
repaint();
}
}
-------------------------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import java.util.observable;
import java.util.timer;
import java.util.timertask;
import javax.swing.*;
public class controller extends jframe
{
jpanel p = new jpanel();
jbutton btnrun = new jbutton("run");
jbutton btnstop = new jbutton("stop");
timer timer;
model model = new model();
view view = new view(model);

string[] mau ={"red","green", "blue","magenta","yello"};
jcombobox jcb = new jcombobox(mau);
jbutton btnsubmit = new jbutton("submit");

public void init()
{
layoutcomponent();
attachlistenertocomponent();
model.addobserver(view);

}
private void layoutcomponent()
{
setlayout(new borderlayout());
this.add(borderlayout.south,p);
p.add(btnrun);
p.add(btnstop);
p.add(jcb);
p.add(btnsubmit);
//btnsubmit.setenabled(false);
btnstop.setenabled(false);
this.add(borderlayout.center,view);
}

private void attachlistenertocomponent()
{
btnrun.addactionlistener(new actionlistener()
{
@override
public void actionperformed(actionevent arg0)
{
btnrun.setenabled(false);
btnstop.setenabled(true);
timer = new timer(true);
timer.schedule(new strobe(), 0,20);
}
});
btnstop.addactionlistener(new actionlistener()
{

@override
public void actionperformed(actionevent arg0)
{
btnrun.setenabled(true);
btnstop.setenabled(false);
timer.cancel();

}
});
btnsubmit.addactionlistener(new actionlistener()
{

@override
public void actionperformed(actionevent e)
{

string mau = jcb.getselecteditem().tostring();
}
});
}
//@override
private class strobe extends timertask
{
public void run()
{
model.setlimit(view.getwidth(), view.getheight());
model.makeonestep();

}
}

public static void main(string[] args)
{
controller controllerapp = new controller();
controllerapp.init();
controllerapp.setsize(600,600);
controllerapp.setvisible(true);
controllerapp.setdefaultcloseoperation(jframe.exit _on_close);
}
}
--------------------------------------------------------------------------------