Multicast event : General Event « Event « Java






Multicast event

Multicast event
   

import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class MulticastEvent extends JPanel implements ActionListener {

  private int counter = 0;

  private JButton closeAllButton;

  public MulticastEvent() {
    JButton newButton = new JButton("New");
    add(newButton);
    newButton.addActionListener(this);

    closeAllButton = new JButton("Close all");
    add(closeAllButton);
  }

  public void actionPerformed(ActionEvent evt) {
    CloseFrame f = new CloseFrame();
    counter++;
    f.setTitle("Window " + counter);
    f.setSize(200, 150);
    f.setLocation(30 * counter, 30 * counter);
    f.show();
    closeAllButton.addActionListener(f);
  }

  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setTitle("MulticastTest");
    frame.setSize(300, 200);
    frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    });

    Container contentPane = frame.getContentPane();
    contentPane.add(new MulticastEvent());

    frame.show();
  }

  class CloseFrame extends JFrame implements ActionListener {
    public void actionPerformed(ActionEvent evt) { // handles Close all
                            // button
      setVisible(false);
    }
  }
}
           
         
    
    
  








Related examples in the same category

1.Swing Event MultiListener Swing Event MultiListener
2.EventTest PaneEventTest Pane
3.KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner()
4.Event Listener List
5.Monitors the AWT event dispatch thread for events that take longer than a certain time to be dispatched