Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Counter.java
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Counter extends JPanel implements ActionListener // wait for an action { private Button upButton = new Button("Add 1"); // create a Button private int counter = 0; public Counter() { add(upButton); upButton.addActionListener(this); // add ActionListener to Button } public void paint( Graphics g ) { super.paint(g); // needed to paint rest of container g.drawString("Count: "+counter, 70, 50 ); } public void actionPerformed(ActionEvent e) { if (e.getSource() == upButton) // only have one event possible counter = counter + 1; repaint(); } public static void main() {JFrame frame = new JFrame(); Counter c = new Counter(); // creates the JPanel frame.add(c); frame.setSize(400,300); frame.setVisible(true); frame.repaint(); // wait for events (we only have one event available here) } }
run
|
edit
|
history
|
help
0
predecrement
jb7.0 extends.override
fizzbuzz
calc exp
linked lists
Project Euler #2
jb11.0 threads
Simple imitation for show banners on priorities
Rextester.java
ex25