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
| import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Fenetre extends JFrame {
JPanel container, contenu;
JComboBox jdept, jcommune, jnra;
JLabel ldept;
String[] bloc = {"","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","2A","2B","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","97","98"};
public static SQLExecuteQuery connexion;
public Fenetre(){
connexion = new SQLExecuteQuery("org.sqlite.JDBC","jdbc:sqlite:nra.db");
this.setTitle("FreeDegroupADSL");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(800,200);
this.setAlwaysOnTop(true);
this.setResizable(false);
container = new JPanel();
container.setBackground(Color.white);
container.setLayout(new BorderLayout());
ldept = new JLabel("Département");
jdept = new JComboBox(bloc);
jdept.setPreferredSize(new Dimension(50,20));
jcommune = new JComboBox();
jcommune.setPreferredSize(new Dimension(500,20));
jnra = new JComboBox();
jnra.setPreferredSize(new Dimension(100,20));
contenu = new JPanel();
contenu.add(ldept);
contenu.add(jdept);
contenu.add(jcommune);
contenu.add(jnra);
container.add(contenu, BorderLayout.NORTH);
this.setContentPane(container);
jdept.addActionListener(new Communes());
jcommune.addActionListener(new Nra());
this.setVisible(true);
}
public class Communes implements ActionListener {
public void actionPerformed (ActionEvent arg0){
jcommune.removeAllItems();
try {
SQLExecuteQuery.setString(1,(String) jdept.getSelectedItem());
while(SQLExecuteQuery.rs.next()) {
jcommune.addItem(SQLExecuteQuery.rs.getString("COMMUNE"));
}
}
catch(Exception e1) {
System.out.println("Select Error:"+e1);
}
}
}
public class Nra implements ActionListener {
public void actionPerformed (ActionEvent arg0){
jnra.removeAllItems();
try {
SQLExecuteQuery.setString(1,(String) jcommune.getSelectedItem());
while(SQLExecuteQuery.rs2.next()) {
jnra.addItem(SQLExecuteQuery.rs2.getString("NRA"));
}
}
catch(Exception e1) {
System.out.println("Select Error:"+e1);
}
}
}
} |
Partager