Reputation: 1
I want to get long button like the '=' & '0' buttons on the windows calculator:
.
Please any one help me.
Also i need to modify this same code, is there way do that from GRIDLAYOUT?
import java.awt.*;
class Cal{
Cal(){
Frame f=new Frame();
f.setVisible(true);
f.setSize(350,500);
f.setTitle("Nano Cal");
Panel p1=new Panel();
p1.setBackground(Color.lightGray);
Panel p2=new Panel();
p2.setBackground(Color.gray);
BorderLayout br=new BorderLayout();
f.add(p1,br.NORTH);
f.add(p2,br.CENTER);
TextField t1=new TextField(57);
p1.add(t1);
Button b1=new Button("MC");
Button b2=new Button("MR");
Button b3=new Button("MS");
Button b4=new Button("M+");
Button b5=new Button("M-");
Button b6=new Button("<-");
Button b7=new Button("CE");
Button b8=new Button("C");
Button b9=new Button("±");
Button b10=new Button("√");
etc.
p2.add(b1);
p2.add(b2);
p2.add(b3);
p2.add(b4);
p2.add(b5);
p2.add(b6);
p2.add(b7);
p2.add(b8);
p2.add(b9);
p2.add(b10);
GridLayout gr=new GridLayout(6,5,5,5);
p2.setLayout(gr);
MenuBar mb=new MenuBar();
f.setMenuBar(mb);
Menu m1=new Menu("View");
Menu m2=new Menu("Edit");
Menu m3=new Menu("Help");
mb.add(m1);
mb.add(m2);
mb.add(m3);
MenuItem mview=new MenuItem("Copy");
MenuItem mview2=new MenuItem("Paste");
m1.add(mview);
m1.add(mview2);
}
}
class testCal{
public static void main(String sr[]){
Cal c = new Cal();
}
}
Upvotes: 0
Views: 1119
Reputation: 74
The entire point of GridLayout is to make things equal sizes. It sounds like you want to be using another layout manager such as GridBagLayout or MigLayout (not built into Java, see http://www.miglayout.com) instead.
Upvotes: 1