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
|
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ContainerAdapter;
import javax.swing.AbstractListModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
/*
* Frame.java
*
* Created on 28 juillet 2006, 10:31
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author Blaise
*/
public class Frame extends JFrame {
private ListePaysModel model;
/** Creates a new instance of Frame */
public Frame() {
setSize(500,600);
setLocationByPlatform(true);
setVisible(true);
Container cont = getContentPane();
cont.setLayout(new BorderLayout());
cont.add(getListe1(),BorderLayout.NORTH);
cont.add(getListe2(),BorderLayout.SOUTH);
setVisible(true);
}
public JComboBox getListe1() {
JComboBox liste1 = new JComboBox();
liste1.setModel(getModel());
return liste1;
}
public JComboBox getListe2() {
JComboBox liste2 = new JComboBox();
liste2.setModel(getModel());
return liste2;
}
public ListePaysModel getModel() {
if ( model == null ){
model = new ListePaysModel();
}
return model;
}
/* --------------------------- */
public class ListePaysModel extends DefaultComboBoxModel {
String[] pays = {
"Belgique",
"France",
"Hongrie",
"Australie"
};
public Object getElementAt(int index) {
return pays[index];
}
public int getSize() {
return pays.length;
}
protected void fireContentsChanged(Object source, int index0, int index1) {
super.fireContentsChanged(source, index0, index1);
System.out.println("Changed");
}
}
public static void main(String[] args) {
new Frame();
}
} |
Partager