Guest User

Untitled

a guest
Jun 23rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 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. lm = new MyListModel(stuff);
  28. jl = new JList(lm);
  29.  
  30. // MyListModel sorterer automatisk.
  31. lm.add("Foo");
  32. lm.add("Bar");
  33. lm.add("Baz");
  34.  
  35. b1 = new JButton("Indsรฆt og sortรฉr");
  36. b1.setActionCommand("Inds_sort");
  37. b1.addActionListener(this);
  38.  
  39. ny = new JTextField(10);
  40.  
  41. bund = new JPanel(new FlowLayout());
  42. bund.add(ny);
  43. bund.add(b1);
  44.  
  45. main = new JFrame();
  46. main.add(jl, BorderLayout.CENTER);
  47. main.add(bund, BorderLayout.SOUTH);
  48.  
  49. main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  50. main.setSize(320, 200);
  51. main.setTitle("Playing with lists!");
  52. main.setVisible(true);
  53.  
  54. }
  55.  
  56. /**
  57. * @param args
  58. */
  59. public static void main(String[] args) {
  60. new ListStuff();
  61. }
  62.  
  63. @Override
  64. public void actionPerformed(ActionEvent e) {
  65. String cmd = e.getActionCommand();
  66. if (cmd.equals("Inds_sort")) {
  67. lm.add(ny.getText());
  68. ny.setText("");
  69. }
  70. }
  71.  
  72. }
Add Comment
Please, Sign In to add comment