Unable to resize a button using java.awt

Posted by asm_debuger on Stack Overflow See other posts from Stack Overflow or by asm_debuger
Published on 2010-12-21T16:50:08Z Indexed on 2010/12/21 16:54 UTC
Read the original article Hit count: 239

Filed under:
|

this is my code:

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class Maapp extends Applet implements ActionListener
{
    private int flag=0;
    Panel p1=new Panel();
    Panel p2=new Panel();
    Button[] arr=new Button[12];

    TextField textf=new TextField("",25);
    public void init()
    {
        this.setLayout(new BorderLayout());
        this.p2.setBackground(Color.DARK_GRAY);
        this.p2.setLayout(new GridLayout(2,30));
        textf.setBackground(Color.BLACK);
        textf.setForeground(Color.YELLOW);
        this.p1.setLayout(new GridLayout(4,10));
        p2.add(textf);
        for(int i=0; i<10 ;i++)
        {

            arr[i]=new Button(""+i);
            arr[i].setForeground(Color.WHITE);
            arr[i].setBackground(Color.DARK_GRAY);
            p1.add(arr[i]);
            this.arr[i].addActionListener(this);
        }
            arr[10]=new Button("=");
            p1.add(arr[10]);
            arr[10].setPreferredSize(new Dimension(20,40));
            this.arr[10].addActionListener(this);


        this.add(p2,BorderLayout.NORTH);
        this.add(p1,BorderLayout.CENTER);
    }





    public void actionPerformed(ActionEvent arg0)
    {

        for(int i=0;i<10;i++)
        {
            if(arg0.getSource()==arr[i])
            {
                this.textf.setText(this.textf.getText()+i);
            }


        }
    }
}

i`m want to resize 1 of the buttons i tried to write: arr[10].setPreferredSize(new Dimension(20,40)); ist do not works i tried to write : arr[10].resize(10,20); ist do not works

so how can i resize button arr[10]?

© Stack Overflow or respective owner

Related posts about java

Related posts about awt