summaryrefslogtreecommitdiff
path: root/src/aufgaben/b20160413/Zusatz1.java
blob: 470a908c53a495f8fe76007ec17d49d26cd3cae9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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]);
		}
	}

}