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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
/**
*
*/
/**
* @author user
*
*/
public class iopjioh extends JFrame
{
private JPanel contentPane;
private JPanel panel;
private JPanel panel_1;
private JButton btnNewButton;
private JButton btnNewButton_1;
int idcpt = 0;
/**
* Launch the application.
*/
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
try
{
iopjioh frame = new iopjioh();
frame.setVisible(true);
} catch (Exception e)
{
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public iopjioh()
{
initialize();
}
private void initialize() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
contentPane.add(getPanel(), BorderLayout.CENTER);
contentPane.add(getPanel_1(), BorderLayout.SOUTH);
}
private JPanel getPanel() {
if (panel == null) {
panel = new JPanel();
}
return panel;
}
private JPanel getPanel_1() {
if (panel_1 == null) {
panel_1 = new JPanel();
panel_1.add(getBtnNewButton());
panel_1.add(getBtnNewButton_1());
}
return panel_1;
}
private JButton getBtnNewButton() {
if (btnNewButton == null) {
btnNewButton = new JButton("Add");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ajoute_panneau();
}
});
}
return btnNewButton;
}
private JButton getBtnNewButton_1() {
if (btnNewButton_1 == null) {
btnNewButton_1 = new JButton("Remove");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
remove_panneau();
}
});
}
return btnNewButton_1;
}
/**
*
*/
protected void ajoute_panneau()
{
// TODO Auto-generated method stub
JPanel neoPan = new JPanel();
neoPan.add(new JLabel("Pan_"+idcpt));
idcpt++;
this.panel.add(neoPan);
pack();
}
/**
*
*/
protected void remove_panneau()
{
this.panel.remove(this.panel.getComponentCount()-1);
pack();
}
} |
Partager