Bonsoir à tous,
Je souhaite pour exemple d'apprentissage créer une fenetre principale ayant un bouton et un label. Ce bouton devrai ouvrir une autre fenetre qui contient 3 JSlider.
Pour celà j'ai une class ( public class Applic1 extends JFrame ) qui sert de fenetre principale et la classe qui contient les JSlider (public class SL_ReglageCouleurs extends JFrame).
public class SL_ReglageCouleurs extends JFrame{
JSlider JS_Red = new JSlider();
JSlider JS_Green = new JSlider();
JSlider JS_Blue = new JSlider();
public SL_ReglageCouleurs() {
initGUI();
}
public static void main(String args[]) {
new SL_ReglageCouleurs();
}
public void initGUI() {
this.setTitle("Color mixer");
this.setSize(250,200);
this.getContentPane().setLayout(null);
this.getContentPane().setBackground(Color.white);
this.getContentPane().setVisible(true);
JS_Red.setOrientation(JSlider.VERTICAL);
JS_Red.setMaximum(255);
JS_Red.setValue(255);
JS_Red.setMajorTickSpacing(50);
JS_Red.setMinorTickSpacing(10);
JS_Red.setPaintLabels(true);
JS_Red.setPaintTicks(true);
JS_Red.setPaintTrack(true);
JS_Red.setSnapToTicks(true);
//JS_Red.setPreferredSize(new Dimension(70,180));
JS_Red.setBackground(Color.white);
JS_Red.addChangeListener(new SliderListener(this));
// Idem que ci dessus pour le JSGreen et le JS_Blue
JS_Red.setBounds(10,10,70,180);
JS_Green.setBounds(90,10,70,180);
JS_Blue.setBounds(170,10,70,180);
this.getContentPane().add(JS_Red);
this.getContentPane().add(JS_Green);
this.getContentPane().add(JS_Blue);
}
public void ChangedColor() {
int Val_Red = JS_Red.getValue();
int Val_Green = JS_Green.getValue();
int Val_Blue = JS_Blue.getValue();
this.getContentPane().setBackground(new Color(Val_Red,Val_Green,Val_Blue));
}
}
class SliderListener implements ChangeListener {
SL_ReglageCouleurs obj;
public SliderListener(SL_ReglageCouleurs obj) {
this.obj=obj;
}
public void stateChanged(ChangeEvent e) {
obj.ChangedColor();
}
}
Dans la premiere class , j'ai une méthode qui traite les evenements et est sensée lancer l'ouverture de la deuxième classe.
public void TraitementEcouteur(ActionEvent e) {
if (BT_Lance.equals(e.getSource()))
// ? LANCER LA DEUXIEME CLASSE
}
Comment s'y prend t'on pour lancer la deuxième classe ?
Merci de votre aide
Partager