import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; public class ControlPanel extends JPanel { private JSlider redSlider, greenSlider, blueSlider; private Java3DWorld java3DWorld; public ControlPanel( Java3DWorld tempJ3DWorld ) { java3DWorld = tempJ3DWorld; JPanel instructionPanel = new JPanel(); JPanel topPanel = new JPanel ( new GridLayout( 1, 0, 0, 1) ); topPanel.add( instructionPanel ); JPanel colorPanel = new JPanel ( new FlowLayout( FlowLayout.LEFT, 15, 15 ) ); TitledBorder colorBorder = new TitledBorder ( "Применить цветовое освещение для прямоугольного параллелепипеда" ); colorBorder.setTitleJustification( TitledBorder.CENTER ); colorPanel.setBorder( colorBorder ); JLabel redLabel = new JLabel ( "К" ); JLabel greenLabel = new JLabel ( "З" ); JLabel blueLabel = new JLabel ( "С" ); redSlider = new JSlider( SwingConstants.HORIZONTAL, 0, 255, 1 ); redSlider.setMajorTickSpacing( 50 ); redSlider.setPaintTicks( true ); redSlider.setPaintTrack( true ); redSlider.setPaintLabels( true ); greenSlider = new JSlider( SwingConstants.HORIZONTAL, 0, 255, 25 ); greenSlider.setMajorTickSpacing( 50 ); greenSlider.setPaintTicks( true ); greenSlider.setPaintTrack( true ); greenSlider.setPaintLabels( true ); blueSlider = new JSlider( SwingConstants.HORIZONTAL, 0, 255, 25 ); blueSlider.setMajorTickSpacing( 50 ); blueSlider.setPaintTicks( true ); blueSlider.setPaintTrack( true ); blueSlider.setPaintLabels( true ); ChangeListener slideListener = new ChangeListener() { public void stateChanged( ChangeEvent event ) { Color color = new Color( redSlider.getValue(), greenSlider.getValue(), blueSlider.getValue() ); java3DWorld.changeColor( color ); } }; redSlider.addChangeListener( slideListener ); greenSlider.addChangeListener( slideListener ); blueSlider.addChangeListener( slideListener ); colorPanel.add( redLabel ); colorPanel.add( redSlider ); colorPanel.add( greenLabel ); colorPanel.add( greenSlider ); colorPanel.add( blueLabel ); colorPanel.add( blueSlider ); java3DWorld.changeColor( new Color( redSlider.getValue(), greenSlider.getValue(), blueSlider.getValue() ) ); setLayout( new GridLayout( 1, 0, 0, 1 ) ); add( colorPanel ); } public Dimension getPreferredSize() { return new Dimension ( 250, 100 ); } public Dimension getMinimumSize() { return getPreferredSize (); } }