Guest User

Untitled

a guest
Jun 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. package dk.hacklab.craptastic;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.FlowLayout;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.util.ArrayList;
  8.  
  9. import javax.swing.JButton;
  10. import javax.swing.JFrame;
  11. import javax.swing.JList;
  12. import javax.swing.JPanel;
  13. import javax.swing.JTextField;
  14.  
  15. public class ListStuff implements ActionListener {
  16. JFrame main;
  17. JList jl;
  18. JButton b1, b2;
  19. JTextField ny;
  20. MyListModel lm;
  21. ArrayList<String> stuff;
  22. JPanel bund;
  23.  
  24. public ListStuff()
  25. {
  26. stuff = new ArrayList<String>(10);
  27. stuff.add("Foo");
  28. stuff.add("Bar");
  29. stuff.add("Baz");
  30.  
  31. lm = new MyListModel(stuff);
  32. jl = new JList(lm);
  33.  
  34. b1 = new JButton("Indsæt og sortér");
  35. b1.setActionCommand("Foo");
  36. b1.addActionListener(this);
  37.  
  38. ny = new JTextField(10);
  39.  
  40. bund = new JPanel(new FlowLayout());
  41. bund.add(ny);
  42. bund.add(b1);
  43.  
  44. main = new JFrame();
  45. main.add(jl, BorderLayout.CENTER);
  46. main.add(bund, BorderLayout.SOUTH);
  47.  
  48. main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  49. main.setSize(320, 200);
  50. main.setTitle("Playing with lists!");
  51. main.setVisible(true);
  52.  
  53. }
  54.  
  55. /**
  56. * @param args
  57. */
  58. public static void main(String[] args) {
  59. new ListStuff();
  60. }
  61.  
  62. @Override
  63. public void actionPerformed(ActionEvent e) {
  64. String cmd = e.getActionCommand();
  65. if (cmd.equals("Foo")) {
  66. lm.add(ny.getText());
  67. ny.setText("");
  68. }
  69. }
  70.  
  71. }
Add Comment
Please, Sign In to add comment