One of the MulticastTest

 

    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
 
    public class MulticastTest{
      public static void main(String args[]){
     
        MulticastFrame frame = new MulticastFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.show();
      }
    }

    /**
 A frame with buttons to make and close secondary frames
    */
 
    class MulticastFrame extends JFrame{
   
      public MulticastFrame(){
     
        setTitle("Sketch");
        setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);

 //add panel to frame

        MulticastPanel panel = new MulticastPanel();
        Container contentPane = getContentPane();
        contentPane.add(panel);
      }
   
      public static  int DEFAULT_WIDTH = 300;
      public static  int DEFAULT_HEIGHT =200;

    }

    /**
 A panel with buttons to create and close sample frames.
    */
    class MulticastPanel extends JPanel{

        public MulticastPanel(){

    //add "New" button
 
    JButton newButton = new JButton("New");
    add(newButton);
    final JButton closeAllButton = new JButton("Close all");
    add(closeAllButton);

    ActionListener newListener = new
       ActionListener()
       {

   public void actionPerformed(ActionEvent event)
   {
       BlankFrame frame = new BlankFrame(closeAllButton);
       frame.show();
    }
       };
    
     newButton.addActionListener(newListener);
 }
    }

    /**
       A blank frame that can be closed by cliking a button.
    */
    class BlankFrame extends JFrame{

      /**
 Constructs a blank  frmae
 @param closeButton the button to close this frmae
      */
      public BlankFrame(final JButton closeButton){

  counter++;
  setTitle("Frmae"+ counter);
  setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
  setLocation(SPACING * counter, SPACING * counter);

  closeListener  = new
     ActionListener(){
      
        public void actionPerformed(ActionEvent event){

    closeButton.removeActionListener(closeListener);
    dispose();
        }
      };

   closeButton.addActionListener(closeListener);
      }

      private ActionListener closeListener;
      private static final int DEFAULT_WIDTH = 200;
      private static final int DEFAULT_HEIGHT = 300;
      private static final int SPACING = 40;
      private static int counter = 0;
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值