Skip to content

Instantly share code, notes, and snippets.

@igorpopovio
Last active January 12, 2018 10:45
Show Gist options
  • Save igorpopovio/04070fcfcf4c13dad8ff to your computer and use it in GitHub Desktop.
Save igorpopovio/04070fcfcf4c13dad8ff to your computer and use it in GitHub Desktop.
An example of a very simple Java swing application.
package io.igorpopov;
import javax.swing.*;
import java.awt.event.*;
public class ClickCountingApp {
public static void main(String args[]) {
JButton button = new JButton("Button never pressed...");
button.addActionListener(new ButtonListener());
JFrame frame = new JFrame("Click Counting App");
frame.getContentPane().add(button);
frame.setSize(300, 80);
frame.setVisible(true);
}
static class ButtonListener implements ActionListener {
int timesPressed;
@Override
public void actionPerformed(ActionEvent event) {
timesPressed++;
JButton button = (JButton) event.getSource();
button.setText("Times pressed: " + timesPressed);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment