The aim was to arrange components so as to resemble a standard calculator setup. I put a border layout with two panels, so that one panel consists of a long text box and the another one contains buttons in the grid form. Yet the output is a simple grid layout with the textbox followed by all the buttons composing of grid. Is it due to odd no. of buttons? or is it about insufficient parameters?
public class Calc extends Applet {
Button add, sub, mul, div, sin, cos, tan, eq, cl;
Button bt[] = new Button[10];
TextField t1;
String s, s1, num1, num2, s3, s4;
int a, b, c;
double d;
public void init() {
Panel p = new Panel();
Panel e = new Panel();
setLayout(new BorderLayout());
t1 = new TextField(10);
e.add(t1);
e.setLayout(new GridLayout(1, 1));
add("North", e);
for (int i = 0; i < 10; i++) {
bt[i] = new Button(String.valueOf(i));
p.add(bt[i]);
bt[i].addActionListener(this);
}
add = new Button("ADD");
sub = new Button("SUB");
mul = new Button("MUL");
div = new Button("DIV");
sin = new Button("SIN");
cos = new Button("COS");
tan = new Button("TAN");
eq = new Button("EQU");
cl = new Button("CLR");
p.add(add);
p.add(sub);
p.add(mul);
p.add(div);
p.add(sin);
p.add(cos);
p.add(tan);
p.add(eq);
p.add(cl);
p.add(t1);
p.setLayout(new GridLayout(4, 5));
add("South", p);
}
}
I am unable to figure out where is it going wrong. Please suggest.