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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
| import java.awt.Color;
import static java.awt.Color.red;
import java.awt.Component;
import java.awt.Container;
import java.awt.Font;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.EventListener;
import java.util.EventObject;
import javafx.stage.WindowEvent;
import javax.swing.CellEditor;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.event.CellEditorListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;
import sun.misc.FormattedFloatingDecimal;
/**
*
* @author Mr Robot
*/
public class voir_dispo extends javax.swing.JFrame {
Connecter conn=new Connecter();
DefaultTableModel tab_cham=new DefaultTableModel();
Statement stm_ch;
ResultSet rs_ch;
DefaultTableCellRenderer df=new DefaultTableCellRenderer();
Object[]donnee={};
String[]entete={"num_ch","etat_ch"} ;
public voir_dispo() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
initComponents();
tab_cham.addColumn("num_ch");
tab_cham.addColumn("etat_ch");
try {
Statement stm_ch=conn.obtenircnx().createStatement();
rs_ch=stm_ch.executeQuery("SELECT * FROM `database`.`id_chambre`");
while(rs_ch.next()){
if ((rs_ch.getBoolean("etat_ch"))==true){
Object[] donnee={rs_ch.getString("num_ch"),"libre"};
tab_cham.addRow(donnee);
}
if ((rs_ch.getBoolean("etat_ch"))==false){
Object[]donnee={rs_ch.getString("num_ch"),"occupe"};
tab_cham.addRow(donnee);
}
jTable1.setModel(tab_cham); }
}catch(Exception e){e.printStackTrace();}
jTable1.setDefaultRenderer(Object.class,new tablecomposantstring());
//jTable1.setDefaultRenderer(Object.class,new editeurcellule());
celuleedition celule=new celuleedition();
JTable jTable1 = new JTable(new celledit());
}
public class celledit extends DefaultTableModel{
public boolean IsCellEditable(int row,int col){
return false;
}}
class celuleedition extends AbstractTableModel{
public Object[] donnee;
public String [] entete;
celuleedition(Object[] donnee,String [] entete){
this.donnee=donnee;
this.entete=entete;}
public int getRowCount() {
return this.donnee.length;}
public int getColumnCount() {
return this.entete.length; }
public String getColumnName(int col){
return this.entete[col];}
public Class getColumnClass (int col){
return this.donnee[4].getClass();}
public Object getValueAt(int row, int col) {
return this.donnee[row];}
public boolean isCellEditable (int row,int col){
if (getValueAt(row,col) instanceof Object)
return false;
return false;}
}
class tablecomposantstring extends DefaultTableCellRenderer{
public Component getTableCellRendererComponent(JTable tableau,Object value,boolean isSelected,
boolean hasFocused,int row,int col){
Component cell = super.getTableCellRendererComponent(jTable1, value,
isSelected, hasFocused, row, col);
// if (value=="libre"){
//cell.setBackground(Color.ORANGE
//);
//}
if (col==0){
cell.setBackground(Color.RED) ;
}else
cell.setBackground(Color.GREEN);
if (value=="libre"){
cell.setBackground(Color.LIGHT_GRAY) ;
}
Object o=jTable1.getValueAt(row, col);
if (o=="occupe"){cell.setBackground(Color.PINK);}
return this ;
}
}@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
setTitle("dispop");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});
jPanel1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
jPanel1.setName("disponibilite"); // NOI18N
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null},
{null, null},
{null, null}
},
new String [] {
"numero chambre", "etat chambre"
}
));
jScrollPane1.setViewportView(jTable1);
if (jTable1.getColumnModel().getColumnCount() > 0) {
jTable1.getColumnModel().getColumn(0).setHeaderValue("numero chambre");
jTable1.getColumnModel().getColumn(1).setHeaderValue("etat chambre");
}
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 332, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 68, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 42, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void formWindowOpened(java.awt.event.WindowEvent evt) {
}
public void disp (EventListener ev){
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(voir_dispo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(voir_dispo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(voir_dispo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(voir_dispo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new voir_dispo().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
public javax.swing.JTable jTable1;
// End of variables declaration
} |
Partager