From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../hjp5/examples/Listing3713.java | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/hjp5/examples/Listing3713.java (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing3713.java') 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 -- cgit v1.2.3