what code should be inside paint()

Discussion in 'Java' started by Madhur Ahuja, Aug 10, 2004.

  1. Madhur Ahuja

    Madhur Ahuja Guest

    Hello
    I have developed a Java Applet which contains swing buttons. The structure
    of code is
    as follows :

    public class game extends Applet implements ActionListener
    {
    JButton x[][]=new JButton[3][3];

    Button reset,start;
    ImageIcon not,cross;

    public void init()
    {

    for(int i=0;i<3;++i)
    {

    for(int j=0;j<3;++j)
    {
    x[j]=new JButton("");
    x[j].setEnabled(false);
    x[j].setVisible(true);
    add(x[j]);

    x[j].setLocation(50+j*100,20+i*100);
    x[j].setSize(40,40);

    x[j].addActionListener(this);
    }

    }
    doLayout();
    }
    }


    There are some problems with this applet :
    1) First the when the applet starts, the buttons are not displayed although
    I have set them explicitly
    to setvisible in init().

    2) Whenever a message box is displayed in the Applet, the buttons are not
    redrawn, i.e. they loose
    their visibility.

    I think, to solve these problems I have to put some code in paint() method,
    although I have no idea
    what to put.
    I am also confused about, which code should come in init() and what should
    come in the constructor
    of the applet. Is their any rule of thumb, like initialization code should
    come in init() etc.


    --
    Winners dont do different things, they do things differently.

    Madhur Ahuja
    India

    Homepage : http://madhur.netfirms.com
    Email : madhur<underscore>ahuja<at>yahoo<dot>com
    Madhur Ahuja, Aug 10, 2004
    #1
    1. Advertising

  2. On Tue, 10 Aug 2004 11:54:46 +0530, Madhur Ahuja wrote:

    > I have developed a Java Applet which contains swing button..


    There is no (obvious) good reason for your
    AWT Applet to contain Swing buttons, it is
    advisable to use one or the other.
    <http://www.physci.org/guifaq.jsp#2.4>

    GUI questions are usually discussed on c.l.j.gui
    <http://www.physci.org/codes/javafaq.jsp#cljg>

    But statements you have made, make me
    think the best group for the moment is..
    <http://www.physci.org/codes/javafaq.jsp#cljh>
    On c.l.j.h., people devote more time to
    explaining the basics of Java.

    See you over there?

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
    Andrew Thompson, Aug 10, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alberto

    Paint a rectangle

    Alberto, Jan 1, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    428
    Scott Mitchell [MVP]
    Jan 1, 2005
  2. ruca
    Replies:
    5
    Views:
    3,099
    S. Justin Gengo
    Sep 28, 2005
  3. Ian

    paint gui problem

    Ian, Jul 11, 2003, in forum: Java
    Replies:
    3
    Views:
    492
    Fred L. Kleinschmidt
    Jul 14, 2003
  4. Ian

    paint gui problem2

    Ian, Jul 12, 2003, in forum: Java
    Replies:
    0
    Views:
    367
  5. Replies:
    4
    Views:
    4,616
    Brendan Guild
    Oct 23, 2005
Loading...

Share This Page