writing_classes_practice
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
writing_classes_practice [2022/10/01 13:33] – frchris | writing_classes_practice [2022/10/01 14:45] (current) – [Writing Classes Practice] frchris | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Writing Classes Practice ====== | ====== Writing Classes Practice ====== | ||
+ | |||
+ | These are designed to be done with an actual computer. | ||
===== Clock ===== | ===== Clock ===== | ||
Line 20: | Line 22: | ||
import javax.swing.Timer; | import javax.swing.Timer; | ||
- | public class ClockTester extends JPanel implements | + | public class ClockTester extends JPanel implements |
{ | { | ||
public static int WIDTH=800; | public static int WIDTH=800; | ||
Line 51: | Line 53: | ||
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
window.getContentPane().add(app); | window.getContentPane().add(app); | ||
- | window.addKeyListener(app); | ||
- | // | ||
window.setVisible(true); | window.setVisible(true); | ||
Line 73: | Line 73: | ||
} | } | ||
- | // update is a workaround to cure Windows screen flicker problem | + | |
- | public void update(Graphics g){ | + | |
- | paint(g); | + | |
- | } | + | |
- | + | ||
- | // These 3 methods need to be declares to implement the KeyListener Interface | + | |
- | @Override | + | |
- | public void keyTyped(KeyEvent e) {} | + | |
- | + | ||
- | @Override | + | |
- | public void keyPressed(KeyEvent e) {} | + | |
- | + | ||
- | @Override | + | |
- | public void keyReleased(KeyEvent e) {} | + | |
- | @Override | + | |
public void actionPerformed(ActionEvent e) { | public void actionPerformed(ActionEvent e) { | ||
writing_classes_practice.1664645596.txt.gz · Last modified: 2022/10/01 13:33 by frchris