[Java/Java'scool][Swing] Ouvrir une JFrame avec un bouton
Bon avant tout je souhaite à tous un bonjour/bonsoir. Vous allez-bien ? Moi pas. En effet, j'ai rien foutue de mon année de terminale et il me reste une semaine pour faire un programme bref je vous demande pas de me le faire (quoi que ça serait sympatoch' hihi(2nd degrés bien sur) ) mais une petite aide assez urgente bon voilà avant tout je préviens mon j'ai codé sur Java'scool sous JavaProg car c'est comme ça que notre prof' nous as dit de codé (j'aurais préféré être habitué a codé en Java mais j'ai appris a m'adapter et de passer de Java à java'scool)
Voilà le code de mon programme
Code:
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
|
import java.awt.*;
import javax.swing.*;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
//Début Fenêtre Accueil
//Fen1
class Fenetre extends javax.swing.JFrame {
Fenetre(){
this.setTitle("Accueil");
this.setSize(400, 500);
this.setLocationRelativeTo(null);
this.setVisible(true);
this.setResizable(true);
this.setAlwaysOnTop(false);
this.setContentPane(Paneau1());
this.setVisible(true);
}
}
//Pan1
JPanel Paneau1(){
JPanel panel = new JPanel();
FlowLayout tropdeflow = new FlowLayout();
panel.setLayout(new FlowLayout());
panel.setBackground(Color.white);
JButton bouton1 = new JButton(new IciAction("Commencer"));
panel.add(bouton1);
JButton bouton2 = new JButton(new LaAction("Quitter"));
panel.add(bouton2);
return panel;
}
//Bouton1 action
public class IciAction extends AbstractAction {
public IciAction(String texte){
super(texte);
}
public void actionPerformed(ActionEvent e) {
}
}
//Bouton2 action
public class LaAction extends AbstractAction {
public LaAction(String texte){
super(texte);
}
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
//Fin de la fenêtre acceuille
//Début fenêtre jeu
//Fen2
class Fenetre2 extends javax.swing.JFrame {
Fenetre2(){
this.setTitle("Qui veut gagner des millions");
this.setSize(400, 500);
this.setLocationRelativeTo(null);
this.setVisible(true);
this.setResizable(true);
this.setAlwaysOnTop(false);
this.setContentPane(Paneau2());
this.setVisible(true);
}
}
//Pan2
JPanel Paneau2(){
JPanel panel = new JPanel();
FlowLayout tropdeflow = new FlowLayout();
panel.setLayout(new FlowLayout());
panel.setBackground(Color.white);
return panel;
}
void main(){
Fenetre fen = new Fenetre();
} |
Bon voilà mon problème je souhaiterai que lorsque je clique sur mon bouton n°1 ma Fenêtre n°2 s'ouvre