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
a+b
jb12.0 threads.enums
This code is not what it seems...
exp 1
1.5
Fraction implementation using oops in java
2A
Java Variable
innerclssss
Item battle rolyal