Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

about applets

Posted on 2001-06-09
6
Medium Priority
?
208 Views
Last Modified: 2013-11-23
in an applet if constructor, init() method, start() method and paint() method are called, what will be the execution flow of these methods
0
Comment
Question by:farooqnasim
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
superschlonz earned 45 total points
ID: 6171826
After the applet has been constructed init() is called. Here you can do some initialisations
like creating the gui components and adding them to the applet.
then start() is called. Here you could start a thread that does some work.
when stop() is called you should stop that thread.
in the destroy() method you should release all resources.
paint() is called whe the component must be painted the first time or when it must be repainted.
If you use buttons, textfields and other awt or swing components you dont need to override
the paint method.
0
 

Author Comment

by:farooqnasim
ID: 6173589
i knew all these things, there is nothing new, i repeat the question again,
      see the code below

import java.applet.Applet;
import java.awt.*;
class MyApplet extends Applet{
          Button b1,b2;
          MyApplet(){
          b1=new Button("one");
           add(b1);
           setBackground(Color.blue);
       }            
          public void init(){
          b2=new Button("Two");
          add(b2);

          setBackground(Color.red);
       }
}
now whether init() or constructor will be called first
or both at the same time and if a new thread is created in constructor, then what will happen
0
 
LVL 3

Expert Comment

by:superschlonz
ID: 6173720
There must be an instance of MyApplet to call init.
So first the constructor must be called. After that init will be called.

I compiled your code and the applet displays 2 buttons and the background is red.

But I had to change 2 lines for getting it running: The class must be public and the
constructor also.

Now it looks like this:

...
public class MyApplet extends Applet {
  ...
  public MyApplet() {
  ...
}
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:superschlonz
ID: 6173730
Oh I forgot the Thread.

If you create a thread in constructor and start it, it will run and do its work. But you
should start threads in init() if they initialize something or in start() if they show an
animation for example.
I don't know what will happen if you start it in the constructor and the user presses
reload, perhaps only stop(), destroy(), init() and start() are called.
0
 

Author Comment

by:farooqnasim
ID: 6196555
the answer is again incomplete, if a thread is created inside the constructor of an applet then what will happen, what method will be executed first, init() or start()
0
 
LVL 3

Expert Comment

by:superschlonz
ID: 6198093
They are still called in the same order:
Constructor, init, start
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question