maygapixel

Untitled

Apr 20th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. class SwingCounter extends JFrame implements ActionListener{
  5.     private JLabel jlCounter;
  6.     private JTextField jtfCount;
  7.     private JButton jbCount;
  8.     private int count = 0;
  9.     public SwingCounter(){
  10.         jlCounter = new JLabel("Counter");
  11.         jtfCount  = new JTextField("0",10);
  12.         jbCount   = new JButton("Count");
  13.         Container c = getContentPane();
  14.         FlowLayout fl = new FlowLayout();
  15.         c.setLayout(fl);
  16.         c.add(jlCounter);
  17.         c.add(jtfCount);
  18.         c.add(jbCount);
  19.         jbCount.addActionListener(this);
  20.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  21.         setSize(300,100);
  22.         setTitle("Swing Counter");
  23.         setVisible(true);
  24.     }
  25.     public void actionPerformed(ActionEvent e) {
  26.       count++;
  27.       jtfCount.setText(count + "");
  28.    }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment