what code should be inside paint()

M

Madhur Ahuja

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
 
A

Andrew Thompson

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top