Last active
January 12, 2018 10:45
-
-
Save igorpopovio/04070fcfcf4c13dad8ff to your computer and use it in GitHub Desktop.
An example of a very simple Java swing application.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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