package xTestx;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JButton;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.Color;
import java.awt.Label;
import java.awt.Point;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.HeadlessException;
/**
* Simple JSlider.
*
* @author
*/
public class PropertiesWindow implements ChangeListener {
JFrame propertiesWindow;
JPanel windowPanel;
JButton button;
JSlider widthSlider;
JSlider heightSlider;
JSlider pointXSlider;
JSlider pointYSlider;
JSlider redSchemeSlider;
JSlider blueSchemeSlider;
JSlider greenSchemeSlider;
JLabel widthLabel;
JLabel heightLabel;
JLabel pointYLabel;
JLabel pointXLabel;
JLabel redSchemeLabel;
JLabel blueSchemeLabel;
JLabel greenSchemeLabel;
// the spot where the sliders color combination will be displayed
Label colorSpot;
// the color spot label name
Label spotLabel;
// center point for the shape
Point centerPoint;
// dimension of the shape
Dimension shapeDimension;
// minimum value for the width of the shape
private static final int WIDTH_MIN_VALUE = 100;
// maximum value for width of the shape
private static final int WIDTH_MAX_VALUE = 500;
// minimum value for the height of the shape
private static final int HEIGHT_MIN_VALUE = 100;
// maximum value for the height of the shape
private static final int HEIGHT_MAX_VALUE = 500;
// minimum value for the center point (point x) of the shape
private static final int MIN_POINT_X = 200;
// maximum value for the center point (point x) of the shape
private static final int MAX_POINT_X = 800;
// minimum value for the center point (point y) of the shape
private static final int MIN_POINT_Y = 100;
// maximum value for the center point (point y) of the shape
private static final int MAX_POINT_Y = 500;
// constant value for color scheme slider's minor tick
private static final int COLOR_SLIDER_MINOR_TICK = 5;
// constant value for color scheme slider's major tick
private static final int COLOR_SLIDER_MAJOR_TICK = 10;
// constant value of minor tick for the geometric pattern sliders
private static final int MINOR_TICK = 10;
// constant value of major tick for the geometric pattern sliders
private static final int MAJOR_TICK = 100;
public void showPropertyWindow() throws HeadlessException {
propertiesWindow = new JFrame("Properties Window");
windowPanel = new JPanel();
button = new JButton("My Button");
widthSlider = new JSlider(WIDTH_MIN_VALUE, WIDTH_MAX_VALUE);
heightSlider = new JSlider(HEIGHT_MIN_VALUE, HEIGHT_MAX_VALUE);
pointXSlider = new JSlider(MIN_POINT_X, MAX_POINT_X);
pointYSlider = new JSlider(MIN_POINT_Y, MAX_POINT_Y);
// sliders for the adjustment of the color
redSchemeSlider = new JSlider(SwingConstants.VERTICAL, 0 , 255, 0);
blueSchemeSlider = new JSlider(SwingConstants.VERTICAL, 0, 255, 0);
greenSchemeSlider = new JSlider(SwingConstants.VERTICAL, 0 ,255, 0);
widthLabel = new JLabel();
heightLabel = new JLabel();
pointXLabel = new JLabel();
pointYLabel = new JLabel();
// Label for each color
redSchemeLabel = new JLabel();
blueSchemeLabel = new JLabel();
greenSchemeLabel = new JLabel();
// spot where the color that will be generated by the color sliders is displayed
colorSpot = new Label();
// Label for the width value slider
widthLabel.setText("Width : ");
widthLabel.setBounds(20, 10, 50, 40);
// set the slider properties for the width
widthSlider.setBounds(20, 35, 250, 50);
widthSlider.setMinorTickSpacing(MINOR_TICK);
widthSlider.setMajorTickSpacing(MAJOR_TICK);
widthSlider.setPaintTicks(true);
widthSlider.setPaintLabels(true);
widthSlider.setToolTipText("Width");
widthSlider.setForeground(Color.GRAY);
widthSlider.addChangeListener(this);
// Label for the height value slider
heightLabel.setText("Height : ");
heightLabel.setBounds(20, 90, 60, 70);
// set the slider properties for the height
heightSlider.setBounds(20, 135, 250, 45);
heightSlider.setMinorTickSpacing(MINOR_TICK);
heightSlider.setMajorTickSpacing(MAJOR_TICK);
heightSlider.setPaintTicks(true);
heightSlider.setPaintLabels(true);
heightSlider.setToolTipText("Height");
heightSlider.setForeground(Color.GRAY);
// Label for the point x (center point)
pointXLabel.setText("Point x : ");
pointXLabel.setBounds(20, 175, 70, 100);
// set the properties of the point x(center point) slider
pointXSlider.setBounds(20, 230, 250, 50);
pointXSlider.setMinorTickSpacing(MINOR_TICK);
pointXSlider.setMajorTickSpacing(MAJOR_TICK);
pointXSlider.setPaintTicks(true);
pointXSlider.setPaintLabels(true);
pointXSlider.setToolTipText("Center Point (x)");
pointXSlider.setForeground(Color.GRAY);
// Label for the point y (center point)
pointYLabel.setText("Point y : ");
pointYLabel.setBounds(20, 240, 70, 155);
// set the properties of the point y(center point) slider
pointYSlider.setBounds(20, 330, 250, 45);
pointYSlider.setMinorTickSpacing(MINOR_TICK);
pointYSlider.setMajorTickSpacing(MAJOR_TICK);
pointYSlider.setPaintTicks(true);
pointYSlider.setPaintLabels(true);
pointYSlider.setToolTipText("Center Point (y)");
pointYSlider.setForeground(Color.GRAY);
// Label for each of the color scheme slider
redSchemeLabel.setText("Red : ");
redSchemeLabel.setBounds(300, 5, 50 , 50);
greenSchemeLabel.setText("Green : ");
greenSchemeLabel.setBounds(530, 5, 50, 50);
blueSchemeLabel.setText("Blue : ");
blueSchemeLabel.setBounds(420, 5, 50, 50);
// set the properties of the red color scheme slider
redSchemeSlider.setBounds(310, 40, 50, 280);
redSchemeSlider.setMinorTickSpacing(COLOR_SLIDER_MINOR_TICK);
redSchemeSlider.setMajorTickSpacing(COLOR_SLIDER_MAJOR_TICK);
redSchemeSlider.setPaintTicks(true);
redSchemeSlider.setPaintLabels(false);
redSchemeSlider.setToolTipText("Red");
redSchemeSlider.setForeground(Color.RED);
redSchemeSlider.addChangeListener(this);
// set the properties of the green color scheme slider
greenSchemeSlider.setBounds(550, 40, 50, 280);
greenSchemeSlider.setMinorTickSpacing(COLOR_SLIDER_MINOR_TICK);
greenSchemeSlider.setMajorTickSpacing(COLOR_SLIDER_MAJOR_TICK);
greenSchemeSlider.setPaintTicks(true);
greenSchemeSlider.setPaintLabels(false);
greenSchemeSlider.setToolTipText("Green");
greenSchemeSlider.setForeground(Color.GREEN);
greenSchemeSlider.addChangeListener(this);
// set the properties of the blue color shceme slider
blueSchemeSlider.setBounds(430, 40, 50, 280);
blueSchemeSlider.setMinorTickSpacing(COLOR_SLIDER_MINOR_TICK);
blueSchemeSlider.setMajorTickSpacing(COLOR_SLIDER_MAJOR_TICK);
blueSchemeSlider.setPaintTicks(true);
blueSchemeSlider.setPaintLabels(false);
blueSchemeSlider.setToolTipText("Blue");
blueSchemeSlider.setForeground(Color.blue);
blueSchemeSlider.addChangeListener(this);
// set the color spot in the panel
colorSpot.setText("Shape's Color.");
colorSpot.setFont(new Font("Monospaced",Font.CENTER_BASELINE ,20));
colorSpot.setBounds(320, 350, 260, 40);
colorSpot.setAlignment(Label.CENTER);
colorSpot.setForeground(new Color(255, 255, 255));
colorSpot.setBackground(new Color(0, 0, 0));
// show the labels
windowPanel.add(widthLabel);
windowPanel.add(heightLabel);
windowPanel.add(pointXLabel);
windowPanel.add(pointYLabel);
windowPanel.add(redSchemeLabel);
windowPanel.add(blueSchemeLabel);
windowPanel.add(greenSchemeLabel);
// show the sliders
windowPanel.add(widthSlider);
windowPanel.add(heightSlider);
windowPanel.add(pointXSlider);
windowPanel.add(pointYSlider);
windowPanel.add(redSchemeSlider);
windowPanel.add(blueSchemeSlider);
windowPanel.add(greenSchemeSlider);
windowPanel.add(colorSpot);
windowPanel.add(button);
windowPanel.setLayout(null);
windowPanel.setDoubleBuffered(false);
propertiesWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
propertiesWindow.setSize(700, 450);
propertiesWindow.setLocation(350, 200);
propertiesWindow.setVisible(true);
propertiesWindow.getContentPane().add(windowPanel);
}
public static void main(String[] args) {
PropertiesWindow enhc = new PropertiesWindow();
enhc.showPropertyWindow();
}
public void stateChanged(ChangeEvent event) {
int width = widthSlider.getValue();
int height = heightSlider.getValue();
int pointX = pointXSlider.getValue();
int pointY = pointYSlider.getValue();
int red = redSchemeSlider.getValue();
int green = greenSchemeSlider.getValue();
int blue = blueSchemeSlider.getValue();
if ((red >= 200) && (red <= 255)) {
if ((green >= 200) && (green <= 255)) {
if ((blue >= 200) && (green <= 255)) {
colorSpot.setForeground(Color.BLACK);
}
}
}
else if ((red <= 50) && (red >= 0)) {
if ((green <= 50) && (green >= 0)) {
if ((blue <= 50) && (blue >= 0)) {
colorSpot.setForeground(Color.WHITE);
}
}
}
// set the spot color according to the colors generated by sliders
colorSpot.setBackground(new Color(red, green, blue));
}
}