Advertisement
Guest User

Untitled

a guest
May 3rd, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1.  
  2. import java.awt.Dimension;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5.  
  6. import javax.swing.Box;
  7. import javax.swing.BoxLayout;
  8. import javax.swing.JButton;
  9. import javax.swing.JFrame;
  10. import javax.swing.JLabel;
  11. import javax.swing.JPanel;
  12. import javax.swing.JTextField;
  13. import javax.swing.SwingUtilities;
  14.  
  15. public class JCount extends JPanel{
  16.  
  17. /**
  18. * Serial Version to remove warning
  19. */
  20. private static final long serialVersionUID = 7861071299105432602L;
  21. private JTextField text;
  22. private JLabel number;
  23. private JButton start, stop;
  24. private Thread thread;
  25.  
  26. /**
  27. * Constructor initializes BoxLayout and adds textfield and buttons
  28. */
  29. public JCount() {
  30. setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
  31. text = new JTextField();
  32. number = new JLabel("0");
  33. start = new JButton("Start");
  34. start.addActionListener(new startListener());
  35. stop = new JButton("Stop");
  36. stop.addActionListener(new stopListener());
  37. text.setText(1000000 + "");
  38. thread = new workerThread();
  39. // System.out.println(thread.isAlive());
  40. add(text);
  41. add(number);
  42. add(start);
  43. add(stop);
  44. setVisible(true);
  45. }
  46.  
  47. /**
  48. * Creates and shows visible gui with 4 JCounts
  49. */
  50. private static void createAndShowGUI() {
  51. JFrame frame = new JFrame();
  52. frame.setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));
  53. JCount[] count = new JCount[4];
  54. for (int i=0; i<4; i++) {
  55. count[i] = new JCount();
  56. frame.add(count[i]);
  57. frame.add(Box.createRigidArea(new Dimension(0, 40)));
  58. }
  59. frame.pack();
  60. frame.setVisible(true);
  61. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement