Advertisement
Guest User

Test

a guest
May 27th, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. package Test;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.*;
  6. import java.util.List;
  7. import java.util.*;
  8.  
  9. public class Test extends JFrame{
  10.     public static void main(String[] args) {
  11.         new Test();
  12.     }
  13.     TextField name=new TextField(30);
  14.     Box window=new Box(BoxLayout.Y_AXIS);
  15.     List<Button> list=new ArrayList<Button>();
  16.     ActionListener vvod=new ActionListener() {
  17.         @Override
  18.         public void actionPerformed(ActionEvent e) {
  19.             Button jb=new Button(name.getText());
  20.             list.add(jb);
  21.             window.add(jb);
  22.             jb.addActionListener(new ActionListener() {
  23.                 @Override
  24.                 public void actionPerformed(ActionEvent e) {
  25.                     window.remove(list.indexOf(e.getSource()));
  26.                     list.remove(e.getSource());
  27.                 }
  28.             });
  29.  
  30.         }
  31.     };
  32.     Button south=new Button("Добавить");
  33.  
  34.     Test(){
  35.         super("Test");
  36.         setLayout(new BorderLayout());
  37.         add(name, BorderLayout.NORTH);
  38.         add(window);
  39.         add(south,BorderLayout.SOUTH);
  40.         name.addActionListener(vvod);
  41.         south.addActionListener(vvod);
  42.         setSize(400,400);
  43.         setVisible(true);
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement