Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Dimension;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.Box;
- import javax.swing.BoxLayout;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JTextField;
- import javax.swing.SwingUtilities;
- public class JCount extends JPanel{
- /**
- * Serial Version to remove warning
- */
- private static final long serialVersionUID = 7861071299105432602L;
- private JTextField text;
- private JLabel number;
- private JButton start, stop;
- private Thread thread;
- /**
- * Constructor initializes BoxLayout and adds textfield and buttons
- */
- public JCount() {
- setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
- text = new JTextField();
- number = new JLabel("0");
- start = new JButton("Start");
- start.addActionListener(new startListener());
- stop = new JButton("Stop");
- stop.addActionListener(new stopListener());
- text.setText(1000000 + "");
- thread = new workerThread();
- // System.out.println(thread.isAlive());
- add(text);
- add(number);
- add(start);
- add(stop);
- setVisible(true);
- }
- /**
- * Creates and shows visible gui with 4 JCounts
- */
- private static void createAndShowGUI() {
- JFrame frame = new JFrame();
- frame.setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));
- JCount[] count = new JCount[4];
- for (int i=0; i<4; i++) {
- count[i] = new JCount();
- frame.add(count[i]);
- frame.add(Box.createRigidArea(new Dimension(0, 40)));
- }
- frame.pack();
- frame.setVisible(true);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement