summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/hjp5/examples/Listing3713.java
diff options
context:
space:
mode:
authorSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
committerSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
commit33613a85afc4b1481367fbe92a17ee59c240250b (patch)
tree670b842326116b376b505ec2263878912fca97e2 /Master/Reference Architectures and Patterns/hjp5/examples/Listing3713.java
downloadStudium-master.tar.gz
Studium-master.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing3713.java')
-rw-r--r--Master/Reference Architectures and Patterns/hjp5/examples/Listing3713.java68
1 files changed, 68 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3713.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3713.java
new file mode 100644
index 0000000..193f244
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3713.java
@@ -0,0 +1,68 @@
+/* Listing3713.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import javax.swing.border.*;
+import javax.swing.event.*;
+
+public class Listing3713
+extends JFrame
+implements ChangeListener
+{
+ private JPanel coloredPanel;
+ private JSlider slEast;
+ private JSlider slSouth;
+ private int blue = 0;
+ private int red = 0;
+
+ public Listing3713()
+ {
+ super("JSlider");
+ addWindowListener(new WindowClosingAdapter(true));
+ Container cp = getContentPane();
+ //Vertikaler Schieberegler
+ slEast = new JSlider(JSlider.VERTICAL, 0, 255, 0);
+ slEast.setMajorTickSpacing(50);
+ slEast.setMinorTickSpacing(10);
+ slEast.setPaintTicks(true);
+ slEast.setPaintLabels(true);
+ slEast.addChangeListener(this);
+ cp.add(slEast, BorderLayout.EAST);
+ //Horizontaler Schieberegler
+ slSouth = new JSlider(JSlider.HORIZONTAL, 0, 255, 0);
+ slSouth.setMajorTickSpacing(100);
+ slSouth.setMinorTickSpacing(25);
+ slSouth.setPaintTicks(true);
+ slSouth.setPaintLabels(true);
+ slSouth.setSnapToTicks(true);
+ slSouth.addChangeListener(this);
+ cp.add(slSouth, BorderLayout.SOUTH);
+ //Farbiges Panel
+ coloredPanel = new JPanel();
+ coloredPanel.setBackground(new Color(red, 0, blue));
+ cp.add(coloredPanel, BorderLayout.CENTER);
+ }
+
+ public void stateChanged(ChangeEvent event)
+ {
+ JSlider sl = (JSlider)event.getSource();
+ if (sl == slEast) {
+ blue = sl.getValue();
+ } else {
+ red = sl.getValue();
+ }
+ coloredPanel.setBackground(new Color(red, 0, blue));
+ if (!sl.getValueIsAdjusting()) {
+ System.out.println("(" + red + ",0," + blue + ")");
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3713 frame = new Listing3713();
+ frame.setLocation(100, 100);
+ frame.setSize(300, 250);
+ frame.setVisible(true);
+ }
+} \ No newline at end of file