PDA

View Full Version : Why the button 9 is not displaying properly ?



joshuadavid2007
01-21-2008, 11:40 AM
import java.awt.*;
import java.awt.event.*;

public class Standard_Calculator
{
static Frame W;
static Button num;
Button operate;
Button memory;

public static void main(String args[])
{
int i = 1, x = 40, y = 50, x2 = 4;
W = new Frame("Calculator 1.0");
W.setSize(300, 300);
for (; i<=9; i++, x+=10)
{
num = new Button(Integer.toString(i));
num.setActionCommand(Integer.toString(i));
if (i==x2)
{
x=40;
x2+=3;
y+=10;
}
num.setLocation(x, y);
num.setSize(10, 10);
W.add(num);
}
W.show();
}
}


i want the numbers to display properly...why no 9 is so big...why is not attached next to 8 ? what do i do ?

icm9768
01-22-2008, 05:10 AM
Not sure why it's doing that, but there's a pretty easy fix. Just create a JPanel with a grid layout of 3 x 3 and add the buttons to that. Then after the loop, add that panel to the frame and your buttons will look like you want them to.