Total members 11895 |It is currently Tue Dec 03, 2024 7:23 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Two Listeners- Mutli- Action Listeners on Text Area
java code
import java.applet.Applet;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class TwoListeners extends Applet
implements ActionListener {

TextArea textAreaObj1;
TextArea textAreaObj2;
Button btnObj1, btnObj2;

public void init() {
Label labelObj = null;
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints gridBagConstrain = new GridBagConstraints();
setLayout(gridbag);

gridBagConstrain.fill = GridBagConstraints.BOTH;
gridBagConstrain.gridwidth = GridBagConstraints.REMAINDER;
labelObj = new Label("Listener one:");
gridbag.setConstraints(labelObj, gridBagConstrain);
add(labelObj);

gridBagConstrain.weighty = 1.0;
textAreaObj1 = new TextArea(5, 20);
textAreaObj1.setEditable(false);
gridbag.setConstraints(textAreaObj1, gridBagConstrain);
add(textAreaObj1);

gridBagConstrain.weightx = 0.0;
gridBagConstrain.weighty = 0.0;
labelObj = new Label("Listener two:");
gridbag.setConstraints(labelObj, gridBagConstrain);
add(labelObj);

gridBagConstrain.weighty = 1.0;
textAreaObj2 = new TextArea(5, 20);
textAreaObj2.setEditable(false);
gridbag.setConstraints(textAreaObj2, gridBagConstrain);
add(textAreaObj2);

gridBagConstrain.weightx = 1.0;
gridBagConstrain.weighty = 0.0;
gridBagConstrain.gridwidth = 1;
gridBagConstrain.insets = new Insets(10, 10, 0, 10);
btnObj1 = new Button(" Button Obj1");
gridbag.setConstraints(btnObj1, gridBagConstrain);
add(btnObj1);

gridBagConstrain.gridwidth = GridBagConstraints.REMAINDER;
btnObj2 = new Button("Button Obj2");
gridbag.setConstraints(btnObj2, gridBagConstrain);
add(btnObj2);

btnObj1.addActionListener(this);
btnObj2.addActionListener(this);

btnObj2.addActionListener(new Listener2(textAreaObj2));
}

public void actionPerformed(ActionEvent e) {
textAreaObj1.append(e.getActionCommand() + "\n");
}
}

class Listener2 implements ActionListener {
TextArea myTextArea;
public Listener2(TextArea ta) {
myTextArea = ta;
}

public void actionPerformed(ActionEvent e) {
myTextArea.append(e.getActionCommand() + "\n");
}
}




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Two Listeners- Mutli- Action Listeners on Text Area
 Need help with generic listeners     -  
 Java- Copy text area into disabled text area     -  
 php extends in action     -  
 is_numeric in action     -  
 php SAX parser in action     -  
 Area clipping     -  
 compute area of the circle.     -  
 JButtons implementing an Action     -  
 Calculate the area of a circle of given radius     -  
 Button action listener should implement abstract method     -  



Topic Tags

Java Applet, Java AWT
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com