Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- public class AWT_Counter {
- Frame f;
- Label counter;
- TextField count_display;
- Button c_button;
- int count = 0;
- AWT_Counter() {
- f = new Frame("AWT Counter");
- f.setSize(300, 100);
- f.setLayout(null);
- f.setVisible(true);
- f.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent wEvent) {
- System.exit(0);
- }
- });
- counter = new Label("Counter");
- counter.setBounds(20, 40, 50, 30);
- f.add(counter);
- count_display = new TextField();
- count_display.setText(Integer.toString(count));
- count_display.setBounds(100, 40, 100, 30);
- f.add(count_display);
- count_display.setEditable(false);
- c_button = new Button("Count");
- c_button.setBounds(220, 40, 50, 30);
- c_button.addActionListener(new ButtonClickListener());
- f.add(c_button);
- }
- private class ButtonClickListener implements ActionListener {
- @Override
- public void actionPerformed(ActionEvent e) {
- count++;
- count_display.setText(Integer.toString(count));
- }
- }
- public static void main(String[] args) {
- AWT_Counter demo = new AWT_Counter();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement