Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class SwingCounter extends JFrame implements ActionListener{
- private JButton btnOK = new JButton("Count");
- private int cout;
- private JTextField text = new JTextField(10);
- public SwingCounter(String title){
- setTitle(title);
- setLayout(new FlowLayout(FlowLayout.LEFT,10,20));
- add(new JLabel("Counter"));
- add(text);
- text.setHorizontalAlignment(SwingConstants.RIGHT);
- add(btnOK);
- btnOK.addActionListener(this);
- }
- public void actionPerformed(ActionEvent e) {
- ++cout;
- text.setText(""+cout);
- //System.out.println(++cout);
- }
- public static void main(String s[]) {
- SwingCounter frame = new SwingCounter("Swing Counter");
- frame.setSize(300, 100);
- frame.setLocationRelativeTo(null);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment