File "gui.java"
Full Path: /home/analogde/www/Ebook/Informatique/JAVA/interface/src/gui.java
File size: 1.23 KB
MIME-type: text/x-c
Charset: utf-8
import java.awt.Container;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
class MainFrame extends JFrame
{
public MainFrame()
{
super("titre");
setSize(300,300);
Container content = getContentPane();
content.setLayout(new BorderLayout());
JPanel panel = new JPanel(new FlowLayout());
//panel.add(new JButton("Button 1"));
JButton button1 = new JButton("Button 1");
panel.add(button1);
button1.addActionListener( new MyButtonListener(this));
panel.add(new JButton("Button 2"));
panel.add(new JButton("Button 3"));
content.add(panel, BorderLayout.SOUTH);
content.add(new JTextArea(), BorderLayout.CENTER);
//setDefaultCloseOperation(EXIT_ON_CLOSE);
}
private class MyButtonListener implements ActionListener
{
private JFrame parentComponent;
MyButtonListener(JFrame parentComponent){
this.parentComponent=parentComponent; }
public void actionPerformed(ActionEvent e) {
System.out.println("Ici !");
JOptionPane.showMessageDialog(parentComponent, "BUTTON PRESSED!");}
}
}
public class gui {
public static void main(String[] args) {
// TODO Auto-generated method stub
MainFrame mf = new MainFrame();
mf.setVisible(true);
}
}