• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet

 
Arun Maalik
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actualy sir what's wrong with following code , i would like to see working of ActionPerformed function but it is not working. Mean ActionPerformed function is not calling by ActionListner why why why?pls help.


import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class first extends Applet implements ActionListener{
Button btn=new Button("Maalik");
Button btn1=new Button("Arun");
public void init(){

add(btn);

btn.addActionListener(this);
}

public void actionPerformed(ActionEvent ae){

add(btn1);


}


}
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Arun,

this is your second post with the subject "Applet" - how are we going to tell which one is which in the forum overview? In fact this isn't even an Applet question, but a generic Swing question. Please take some time to compose a meaningful subject line when posting a question, that will safe all those people who'd like to help you a lot of time, and therefore simply would be an act of respect. See http://faq.javaranch.com/view?UseAMeaningfulSubjectLine

You can change the subject line by clicking the edit icon on your very first post of the thread.

Moving this and your other post to the Swing forum.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you add a component to a container that's already visible on the screen, you must call validate() on the container afterwards. Until you do, the new component won't appear. Since here the applet itself is the container, just add the line

validate();

at the end of the event handler.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic