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
|
package aa;
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.lang.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
public class SimpleFenetre extends JFrame implements ActionListener {
private JButton Ok = new JButton("OK");
private GridBagLayout gbl = new GridBagLayout();
private JTextPane b = new JTextPane();
private JScrollPane n = new JScrollPane();
public SimpleFenetre() {
this.getContentPane().setLayout(gbl);
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.NONE;
gbc.gridx = 0;
gbc.gridy = 0;
b.setText("affichage");
n.setPreferredSize(new Dimension(300, 225));
n.setViewportView(b);
gbl.setConstraints(this.n, gbc);
this.getContentPane().add(this.n);
gbc.gridy = 2;
gbc.anchor = GridBagConstraints.FIRST_LINE_END;
gbl.setConstraints(this.Ok, gbc);
Ok.addActionListener(this);
this.getContentPane().add(this.Ok);
this.setResizable(false);
this.setSize(520, 620);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
SimpleFenetre gui = new SimpleFenetre();
}
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(Ok)) {
ArrayList s = new ArrayList();
s.add("B");
s.add("C");
s.add("D");
s.add("A");
n.setText(s);
}
}
} |
Partager