Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Test;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.util.List;
- import java.util.*;
- public class Test extends JFrame{
- public static void main(String[] args) {
- new Test();
- }
- TextField name=new TextField(30);
- Box window=new Box(BoxLayout.Y_AXIS);
- List<Button> list=new ArrayList<Button>();
- ActionListener vvod=new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- Button jb=new Button(name.getText());
- list.add(jb);
- window.add(jb);
- jb.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- window.remove(list.indexOf(e.getSource()));
- list.remove(e.getSource());
- }
- });
- }
- };
- Button south=new Button("Добавить");
- Test(){
- super("Test");
- setLayout(new BorderLayout());
- add(name, BorderLayout.NORTH);
- add(window);
- add(south,BorderLayout.SOUTH);
- name.addActionListener(vvod);
- south.addActionListener(vvod);
- setSize(400,400);
- setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement