je suis nouveau sur java, et je voudrais faire un bouton quand je clique dessus il me lance une application.
Voilà mon code.
et Merci pour votre aide.
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Jfenetre extends JFrame {
private static final long serialVersionUID = 1L;
public Jfenetre(){
build();//On initialise notre fenêtre
}
private void build(){
setTitle("Menu D'installation Des Mise à Jour"); //On donne un titre à l'application
setSize(400,200); //On donne une taille à notre fenêtre
setLocationRelativeTo(null); //On centre la fenêtre sur l'écran
setResizable(false); //On interdit la redimensionnement de la fenêtre
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //On dit à l'application de se fermer lors du clic sur la croix
setContentPane(buildContentPane());
}
private JPanel buildContentPane(){
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
panel.setBackground(Color.gray);
JButton bouton = new JButton("UPDATE 1 ");
panel.add(bouton);
bouton.addActionListener(new UpdateButton());
return panel;
}
class UpdateButton implements ActionListener
{
String nomDuFichier= "C:\\ConfigMgrAdminUISetup.log";
File fichier1 = new File(nomDuFichier);
public void actionPerformed (ActionEvent a)
{
Scanner in = null;
try {
in = new Scanner(fichier1);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
in.close();
}
}
}
mport javax.swing.SwingUtilities;
public class Button {
public static void main (String[] args) {
SwingUtilities.invokeLater(new Runnable(){
public void run(){
Jfenetre fenetre = new Jfenetre();
fenetre.setVisible(true);
}
});
}
}
PXL Le retro gaming facile Thread sur le forum: https://openclassrooms.com/forum/sujet/retro-pxl