Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Manju Tcs   on Jan 12 In Java Category.

  
Question Answered By: Percy Morgan   on Jan 12

I generally use an inner class  when working with listeners. Otherwise
the new event  model didn't do very much to improve on the old AWT
method.
Modified:
import java.awt.*;
import java.applet.*;
import java.util.*;
import java.awt.event.*;
/*
<applet code = "MessageWindow" width=400 height = 200>
</applet>
*/

public class MessageWindow extends Applet
{
Button Send;
TextArea A1, A2;

public void  init ()
{
setBackground (Color.cyan);
setLayout (new BorderLayout ());
add (new TextArea (" ", 10, 30), BorderLayout.NORTH);
add (new TextArea (" ", 5, 30), BorderLayout.SOUTH);

// I put this
Send = new Button ("Send");
//I change dis:)
add (Send, BorderLayout.WEST);

Send.addActionListener (new Listen ());
}


class Listen implements ActionListener
{

public void actionPerformed (ActionEvent ae)
{
repaint ();
}
}
}

Share: 

 

This Question has 1 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Null Pointer exception Or get search suggestion and latest updates.


Tagged: