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
| import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ToolBarFrame3 extends JFrame{
public ToolBarFrame3() {
super("Title");
setSize(450, 250);
addWindowListener(new WindowAdapter( ) {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
ActionListener printListener = new ActionListener( ) {
public void actionPerformed(ActionEvent ae) {
System.out.println(ae.getActionCommand( ));
}
};
JPanel panneau = new JPanel();
panneau.setLayout(new FlowLayout(FlowLayout.CENTER));
JButton button = new JButton(new ImageIcon("image.jpg"));
button.addActionListener(printListener);
panneau.add(button);
add(panneau, BorderLayout.NORTH);
}
public static void main(String args[]) {
ToolBarFrame3 main = new ToolBarFrame3();
main.setVisible(true);
}
} |
Partager