/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package MIVGC; /** * * @author pc */ import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; import MIVGC.toutclasse.Connexion; import com.hp.hpl.jena.vocabulary.ResultSet; import com.mysql.jdbc.PreparedStatement; import java.awt.Color; import java.awt.Event; import java.awt.GridLayout; import java.sql.SQLException; import javax.swing.JButton; import javax.swing.JScrollPane; import java.awt.BorderLayout; import java.awt.Font; import java.awt.GraphicsEnvironment; import java.awt.GridLayout; import java.awt.Rectangle; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.KeyEvent; import java.sql.Statement; import java.util.HashMap; import javax.swing.BorderFactory; import javax.swing.ImageIcon; import javax.swing.JCheckBox; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; //mport java.util.*; import javax.swing.*; import javax.swing.table.*; public class Testcheckbox {public static String S=""; // public static Mot tablesp[] = new Mot[200]; public static int j=0; public static int testt; public static JFrame frame = new JFrame(); public static JButton B = new JButton("SAVE"); //public static JTable table = new JTable(new DefaultTableModel(0, 1)); //public static DefaultTableModel model2 = (DefaultTableModel) table.getModel(); public static GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); public static Rectangle bounds = env.getMaximumWindowBounds(); public static Connexion cons1 = new Connexion() { }; java.sql.Connection con1 = cons1.connecter("SYSTEM", "ameni"); ResultSet rs1=null; public static void main(String...args) { int x = 1; int CheckBoxNumber = 75; // int CheckBoxNumber = MIVGC.Accueil.ntnf; javax.swing.JCheckBox[] jCheckboxArray; javax.swing.JCheckBox[] box; Connexion cons = new Connexion() { }; java.sql.Connection con = cons.connecter("SYSTEM", "ameni"); // ResultSet rs =null; for (int k= 0; k < Accueil_Analyse.tablesp.length; k++) { Accueil_Analyse.tablesp[k] = new Mot(k + 1, ""); } box = new javax.swing.JCheckBox[CheckBoxNumber]; try{ java.sql.Statement state1 = con.createStatement(); java.sql.ResultSet rs1 = state1.executeQuery("SELECT NOM_TERME_NON_FREQ FROM TERMES_NON_FREQUENTS"); System.out.println("/n selection"); while(rs1.next()){ x =1; //Create the check boxes. box[x] = new javax.swing.JCheckBox(rs1.getString("NOM_TERME_NON_FREQ")); System.out.println("terme x" +box[x].getText()); x++; } }catch(SQLException e){}; final JTable table = new JTable(new DefaultTableModel(0, 1)); final DefaultTableModel model2 = (DefaultTableModel) table.getModel(); String[] s=new String[1]; s[0]="Nom_terme_spécifique"; model2.setColumnIdentifiers(s); for(int i = 1; i < CheckBoxNumber -1 ; i++) { box[i].addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JCheckBox src = (JCheckBox) e.getSource(); model2.addRow(new String[] {src.getText()}); Accueil_Analyse.tablesp[j]= new Mot(j+1, (src.getText())); j++; table.repaint(); } }); } table.repaint(); frame.setSize(1380,700); int p=0;int cc=0;int ccc=0; int xx=10; int yy=0; for ( int k=0;k< box.length;k++) { yy+=22; if( cc< ccc+26) { box[k].setBounds(xx, yy,220 ,15); frame.add(box[k]); cc++; } else {xx=xx+230; yy=22; ccc = ccc + 26; box[k].setBounds(xx,yy,220 ,15); frame.add(box[k]); cc++; } } JScrollPane jScrollPane10 = new javax.swing.JScrollPane(); frame.add(jScrollPane10); JScrollPane jScrollPane11 = new javax.swing.JScrollPane(); // jScrollPane11.setSize(50, 400); jScrollPane11.setViewportView(table); final JInternalFrame f = new JInternalFrame(); // f.setSize(100, 100); JPanel jPanel1 = new javax.swing.JPanel(); jPanel1.setBackground(new java.awt.Color(185, 209, 234)); JScrollPane jScrollPane12 = new javax.swing.JScrollPane(); jPanel1.add(jScrollPane12); jScrollPane12.setViewportView(table); f.add(jPanel1); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setBackground(new java.awt.Color(185, 209, 234)); f.setForeground(new java.awt.Color(185, 209, 234)); f.setTitle("termes spécifiques"); f.setVisible(true); frame.add(f,BorderLayout.EAST); frame.setTitle("Veuillez cocher les temes spécifiques qui apparaissent dans la liste suivante"); B.setSize(50, 50); // B.setBounds(690, 350,100 ,100); B.setBackground(new java.awt.Color(32,127,217)); B.setForeground(Color.WHITE); B.setFont(new java.awt.Font("Times New Roman", 1, 20)); B.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255),4)); frame.add(B,BorderLayout.SOUTH); B.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { frame.setVisible(false); testt = Accueil_Analyse.remplissagetermesspécifiques(); System.out.println("termessssssssssssssssssssssssssssssssssssssssssssssssssssssssssss spécifiques insérés f classe"+ testt); retourn_valeur(); } }); // frame.setMaximumSize(null); frame.setBounds(bounds); frame.setVisible(true); // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static int retourn_valeur() { return testt; // MIVGC.Accueil.jMenuItem1. } }