diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Master/Reference Architectures and Patterns/hjp5/examples/Listing3410.java | |
| download | Studium-master.tar.gz Studium-master.tar.bz2 | |
Diffstat (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing3410.java')
| -rw-r--r-- | Master/Reference Architectures and Patterns/hjp5/examples/Listing3410.java | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3410.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3410.java new file mode 100644 index 0000000..c65b520 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3410.java @@ -0,0 +1,69 @@ +/* Listing3410.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class Listing3410
+extends Frame
+implements Runnable
+{
+ //Konstanten
+ private static final int NUMLEDS = 20;
+ private static final int SLEEP = 60;
+ private static final int LEDSIZE = 10;
+ private static final Color ONCOLOR = new Color(255,0,0);
+ private static final Color OFFCOLOR = new Color(100,0,0);
+
+ //Instanzvariablen
+ private Thread th;
+ private int switched;
+ private int dx;
+
+ public static void main(String[] args)
+ {
+ Listing3410 frame = new Listing3410();
+ frame.setSize(270,150);
+ frame.setVisible(true);
+ frame.startAnimation();
+ }
+
+ public Listing3410()
+ {
+ super("Leuchtdiodenkette");
+ setBackground(Color.lightGray);
+ addWindowListener(new WindowClosingAdapter(true));
+ }
+
+ public void startAnimation()
+ {
+ th = new Thread(this);
+ th.start();
+ }
+
+ public void run()
+ {
+ switched = -1;
+ dx = 1;
+ while (true) {
+ repaint();
+ try {
+ Thread.sleep(SLEEP);
+ } catch (InterruptedException e){
+ //nichts
+ }
+ switched += dx;
+ if (switched < 0 || switched > NUMLEDS - 1) {
+ dx = -dx;
+ switched += 2*dx;
+ }
+ }
+ }
+
+ public void paint(Graphics g)
+ {
+ for (int i = 0; i < NUMLEDS; ++i) {
+ g.setColor(i == switched ? ONCOLOR : OFFCOLOR);
+ g.fillOval(10+i*(LEDSIZE+2),80,LEDSIZE,LEDSIZE);
+ }
+ }
+}
\ No newline at end of file |
