diff options
author | Leonard Kugis <leonard@kug.is> | 2022-04-25 18:36:30 +0200 |
---|---|---|
committer | Leonard Kugis <leonard@kug.is> | 2022-04-25 18:36:30 +0200 |
commit | 84e220b332bfffb0f2dcc39b9697a6fd6691d265 (patch) | |
tree | 0b861a9a099017ffd9bf00bae12e33ed6a309bbe /src/aufgaben/b20160413/Zusatz1.java |
Diffstat (limited to 'src/aufgaben/b20160413/Zusatz1.java')
-rwxr-xr-x | src/aufgaben/b20160413/Zusatz1.java | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/aufgaben/b20160413/Zusatz1.java b/src/aufgaben/b20160413/Zusatz1.java new file mode 100755 index 0000000..470a908 --- /dev/null +++ b/src/aufgaben/b20160413/Zusatz1.java @@ -0,0 +1,84 @@ +package aufgaben.b20160413;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+import javax.swing.JSpinner;
+import javax.swing.SpinnerNumberModel;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Zusatz1 extends Aufgabe {
+
+ private final int width = 110, height = 200;
+ private boolean done = false;
+ private String name;
+ private JSpinner[] spinners;
+
+ public Zusatz1() {
+ name = "RGB Int Umwandlung";
+ this.setSize(width, height);
+ this.setTitle(name);
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ this.setLayout(null);
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ spinners = new JSpinner[4];
+ spinners[0] = new JSpinner(new SpinnerNumberModel(0, 0, 16777215, 1));
+ spinners[0].setBounds(10, 50, 100, 20);
+ spinners[1] = new JSpinner(new SpinnerNumberModel(0, 0, 255, 1));
+ spinners[1].setBounds(10, 80, 100, 20);
+ spinners[2] = new JSpinner(new SpinnerNumberModel(0, 0, 255, 1));
+ spinners[2].setBounds(10, 110, 100, 20);
+ spinners[3] = new JSpinner(new SpinnerNumberModel(0, 0, 255, 1));
+ spinners[3].setBounds(10, 140, 100, 20);
+ for(int i = 0; i<spinners.length; i++) {
+ spinners[i].addChangeListener(new ChangeListener() {
+ public void stateChanged(ChangeEvent e) {
+ if(e.getSource().equals(spinners[0])) {
+ spinners[1].setValue((int)((int)spinners[0].getValue() & 0xFF));
+ spinners[2].setValue((int)(((int)spinners[0].getValue() >> 8) & 0xFF));
+ spinners[3].setValue((int)(((int)spinners[0].getValue() >> 16) & 0xFF));
+ } else if(e.getSource().equals(spinners[1])) {
+ spinners[0].setValue((int)spinners[1].getValue() & 0xFF | ((int)spinners[2].getValue() & 0xFF) << 8 | ((int)spinners[3].getValue() & 0xFF) << 16);
+ } else if(e.getSource().equals(spinners[2])) {
+ spinners[0].setValue((int)spinners[1].getValue() & 0xFF | ((int)spinners[2].getValue() & 0xFF) << 8 | ((int)spinners[3].getValue() & 0xFF) << 16);
+ } else if(e.getSource().equals(spinners[3])) {
+ spinners[0].setValue((int)spinners[1].getValue() & 0xFF | ((int)spinners[2].getValue() & 0xFF) << 8 | ((int)spinners[3].getValue() & 0xFF) << 16);
+ }
+ }
+ });
+ this.add(spinners[i]);
+ }
+ }
+
+}
|