How I would change your class is like so (note this is pseudo code you'll need to actually implement an action listener for handling button presses)-
public class UI extends JFrame implements ActionListener
{
ArrayList buttonList = new ArrayList();
int x = 0;
int y = 0;
int width = 50;
int height = 50;
public UI()
{
super("Example Frame");
setSize(800,600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new GridLayout(1,3));
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(12,1));
for(int i=1; i<13; i++)
{ String s = Integer.toString(i);
buttonPanel.add(new JButton(s));
}
add(mainPanel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainPanel.add(buttonPanel, BorderLayout.CENTER);
}
public void paint(Graphics g){
super.paint(g);
g.drawRect(x,y,width,height);
}
onButtonPress(int buttonNumber){
y = buttonNumber * 10;
repaint();
}