Total members 11893 |It is currently Sun Nov 03, 2024 2:47 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Window events-handling by WindowListener
java code
import java.applet.Applet;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

public class WindowEventExample extends Applet
implements WindowListener,
ActionListener {
String lineSep;
TextArea textAreaObj;
Frame frameObj;
Button btnOne, btnTwo;
static final String SHOW = "show";
static final String CLEAR = "clear";


public void init() {
btnOne = new Button("Click to bring up a window.");
btnOne.setActionCommand(SHOW);
btnOne.addActionListener(this);

btnTwo = new Button("Click to clear the display.");
btnTwo.setActionCommand(CLEAR);
btnTwo.addActionListener(this);

textAreaObj = new TextArea(5, 20);
textAreaObj.setEditable(false);

setLayout(new BorderLayout());
add("North", btnOne);
add("Center", textAreaObj);
add("South", btnTwo);


frameObj = new Frame("Frame with Window Event ");
frameObj.addWindowListener(this);
frameObj.add("Center",
new Label("The applet listens to this window for window events."));
frameObj.pack();

lineSep = System.getProperty("line.separator");
}

public void stop() {
frameObj.setVisible(false);
}

public void windowClosing(WindowEvent e) {
frameObj.setVisible(false);
printMessage("Window closing", e);
}

public void windowClosed(WindowEvent e) {
printMessage("Window closed", e);
}

public void windowOpened(WindowEvent e) {
printMessage("Window opened", e);
}

public void windowIconified(WindowEvent e) {
printMessage("Window iconified", e);
}

public void windowDeiconified(WindowEvent e) {
printMessage("Window deiconified", e);
}

public void windowActivated(WindowEvent e) {
printMessage("Window activated", e);
}

public void windowDeactivated(WindowEvent e) {
printMessage("Window deactivated", e);
}

void printMessage(String prefix, WindowEvent e) {
textAreaObj.append(prefix
+ ": "
+ e.getWindow()
+ lineSep);
}

public void actionPerformed(ActionEvent e) {
if (e.getActionCommand() == SHOW) {
frameObj.pack();
frameObj.setVisible(true);
} else {
textAreaObj.setText("");
}
}
}




_________________
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 : Window events-handling by WindowListener
 How can a GUI component handle its own events     -  
 check keyboard events using C++     -  
 Handle Focus events with FocusListener     -  
 Text Listener for events TextListener-on TextArea-TextField     -  
 What is Event Handling?     -  
 Exception handling     -  
 Material Handling Equipment     -  
 Exception Handling in a project     -  
 Event Handling Notes     -  
 try-with-resource automatic handling     -  



Topic Tags

Java AWT, Java Applet, Java Events






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