Hé les gars J'écris un programme Java pour la pratique. Il implique un JFrame, JButton et un écouteur d'action. Lorsque j'essaie de lancer le programme (via eclipse), la console indique "Window (5) [Java Application]" [...]Le programme se termine, et JFrame n'apparaît pas
Est-ce que quelqu'un connaît un correctif? Voici mon code:
Window.java
package com.github.dtroll.Carzett.main;
import java.awt.Color;
import javax.swing.JFrame;
public class Window {
public static void startGame() {
JFrame f = new JFrame("Journey To Carzett");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setResizable(true);
f.setBackground(Color.GRAY);
f.setVisible(true);
f.setSize(750, 500);
//JPanel p = new JPanel(new BorderLayout());
}
public static void main(String args[]) {
new Window();
new StartPanel();
}
}
StartPanel.java (ceci est utilisé pour ajouter un panneau au programme lorsque le bouton est pressé.)
package com.github.dtroll.Carzett.main;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
public class StartPanel extends JPanel implements ActionListener{
/**
*
*/
private static final long serialVersionUID = 1L;
private JButton start;
public StartPanel(){
Icon startButton = new ImageIcon("/images/buttons/start.png");
this.start = new JButton(startButton);
this.start.addActionListener(this);
this.add(start);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == start){
//insert methods here
}
}
}
quel est le message d'erreur? –
Note de côté 'if (e.getSource() == start) {' devrait être 'if (e.getSource(). Est égal à (début)) {' – Smit
non ne fonctionne pas. –