
how to set size of buttons on frame

Hi Friend,
Using the setPreferredSize(new Dimension(40,15)); method, you can set the button size in awt in java.
Here is your required code:
import java.awt.*;
import java.awt.event.*;
import java.util.regex.*;
class ButtonSize extends Frame{
Label l;
ButtonSize(){
Label lab=new Label("Enter number to find its factorial: ");
final TextField text=new TextField(20);
Button b=new Button("Find");
Panel p=new Panel();
l=new Label();
Panel pan=new Panel();
pan.add(l);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String input=text.getText();
Pattern p = Pattern.compile("[A-Z,a-z,&%$#@!()*^]");
Matcher m = p.matcher(input);
if(m.find()){
l.setText("*Enter only numeric value!");
l.setSize(250,20);
l.setForeground(Color.RED);
ltext.setText("");
}
else if(input.equals("")){
l.setText("*Enter value!");
l.setSize(250,20);
l.setForeground(Color.RED);
}
else{
int num=Integer.parseInt(input);
long fac=num;
for(int i=num;i>1;i--){
fac=fac*(i-1);
}
System.out.println(fac);
l.setText("Factorial Of Number "+input+" is: "+Long.toString(fac));
l.setSize(250,20);
l.setForeground(Color.BLUE);
}
}
});
p.add(lab);
p.add(text);
p.add(b);
b.setPreferredSize(new Dimension(40,15));
add(p,BorderLayout.NORTH);
add(pan,BorderLayout.SOUTH);
pack();
setVisible(true);
}
public static void main(String[] args){
new ButtonSize();
}
}
Thanks