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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
| import java.awt.EventQueue;
public class RVB {
private JFrame frmSynth;
DecimalFormat df= new DecimalFormat("#.##");
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
RVB window = new RVB();
window.frmSynth.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public RVB() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmSynth = new JFrame();
frmSynth.setIconImage(Toolkit.getDefaultToolkit().getImage(RVB.class.getResource("/com/sun/java/swing/plaf/windows/icons/Inform.gif")));
frmSynth.setBackground(UIManager.getColor("Button.background"));
frmSynth.setResizable(false); // taille de fenêtre non redimensionnable
frmSynth.setTitle("Synth\u00E8se additive R V B"); // Titre de la fenêtre
frmSynth.setBounds(100, 100, 491, 300);
frmSynth.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmSynth.getContentPane().setLayout(null);
//Bouton "couleur résultante"
JButton btn = new JButton("");
btn.setToolTipText("Couleur r\u00E9sultante");
btn.setBounds(294, 36, 177, 192);
frmSynth.getContentPane().add(btn);
// Bouton rouge
final JButton btnR = new JButton("128");
btnR.addMouseListener(new MouseAdapter() {
private JSlider sliderR;
@Override
public void mouseClicked(MouseEvent arg0) {
String inputValue = JOptionPane.showInputDialog("Composante Rouge"); //Boite de dialogue
btnR.setText(String.valueOf(df.format(sliderR.getValue())));
}
});
btnR.setFont(new Font("Arial", Font.BOLD, 12));
btnR.setToolTipText("Cliquer pour entrer la valeur de la composante rouge"); //Info-bulle
btnR.setForeground(Color.WHITE);
btnR.setBackground(Color.RED);
btnR.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
});
btnR.setBounds(10, 49, 62, 39);
frmSynth.getContentPane().add(btnR);
//Bouton Vert
final JButton btnV = new JButton("128");
btnV.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
String inputValue = JOptionPane.showInputDialog("Composante Verte"); //Boite de dialogue
btnV.setText(String.valueOf(inputValue));
}
});
btnV.setFont(new Font("Arial", Font.BOLD, 12));
btnV.setToolTipText("Cliquer pour entrer la valeur de la composante verte"); //Info-bulle
btnV.setBackground(Color.GREEN);
btnV.setForeground(Color.WHITE);
btnV.setBounds(10, 117, 62, 39);
frmSynth.getContentPane().add(btnV);
// Bouton Bleu
final JButton btnB = new JButton("128");
btnB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
});
btnB.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
String inputValue = JOptionPane.showInputDialog("Composante Bleu"); //Boite de dialogue
btnB.setText(String.valueOf(inputValue));
}
});
btnB.setFont(new Font("Arial", Font.BOLD, 12));
btnB.setToolTipText("Cliquer pour entrer la valeur de la composante bleu"); //Info-bulle
btnB.setBackground(Color.BLUE);
btnB.setForeground(Color.WHITE);
btnB.setBounds(10, 177, 62, 39);
frmSynth.getContentPane().add(btnB);
// Slider Rouge
final JSlider sliderR = new JSlider();
sliderR.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent arg0) {
}
});
sliderR.setValue(128); // valeur par défaut
sliderR.setPaintTicks(true);
sliderR.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseMoved(MouseEvent arg0) {
btnR.setText(String.valueOf(df.format(sliderR.getValue()))); //Indique la valeur du slider dans le bouton
}
});
sliderR.setFont(new Font("Arial", Font.BOLD, 12));
sliderR.setMajorTickSpacing(50); // Espacement des grandes divisions
sliderR.setPaintLabels(true); // affichage des valeurs du slider
sliderR.setMinorTickSpacing(10); // Espacement des petites divisions
sliderR.setMaximum(255); // valeur ax
sliderR.setToolTipText("Selectionner la valeur de la composante rouge"); //Info-bulle
sliderR.setBounds(84, 49, 200, 39);
frmSynth.getContentPane().add(sliderR);
// Slider Vert
final JSlider sliderV = new JSlider();
sliderV.setPaintLabels(true);
sliderV.setPaintTicks(true);
sliderV.setSnapToTicks(true);
sliderV.setValue(128);
sliderV.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent arg0) {
btnV.setText((String.valueOf(df.format(sliderV.getValue())))); //Indique la valeur du slider dans le bouton
}
});
sliderV.setFont(new Font("Arial", Font.BOLD, 12));
sliderV.setMajorTickSpacing(50);
sliderV.setMinorTickSpacing(10);
sliderV.setToolTipText("Selectionner la valeur de la composante verte");
sliderV.setMaximum(255);
sliderV.setBounds(84, 117, 200, 39);
frmSynth.getContentPane().add(sliderV);
// Slider Bleu
final JSlider sliderB = new JSlider();
sliderB.setValue(128);
sliderB.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent arg0) {
btnB.setText((String.valueOf(df.format(sliderB.getValue())))); //Indique la valeur du slider dans le bouton
}
});
sliderB.setFont(new Font("Arial", Font.BOLD, 12));
sliderB.setPaintLabels(true);
sliderB.setMajorTickSpacing(50);
sliderB.setMinorTickSpacing(10);
sliderB.setToolTipText("Selectionner la valeur de la composante bleu"); //Info-bulle
sliderB.setSnapToTicks(true);
sliderB.setMaximum(255);
sliderB.setPaintTicks(true);
sliderB.setBounds(82, 177, 200, 39);
frmSynth.getContentPane().add(sliderB);
}
} |
Partager