[clos] je cherche à ajouter un bouton imprimer a mon JFrame pour imprimer les ch
Fermé
gharsih
Messages postés2Date d'inscriptionmercredi 30 novembre 2011StatutMembreDernière intervention 3 juin 2012
-
3 juin 2012 à 15:25
cs_Julien39
Messages postés6414Date d'inscriptionmardi 8 mars 2005StatutModérateurDernière intervention29 juillet 2020
-
4 juin 2012 à 08:20
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* planning.java
*
* Created on 25 mai 2012, 17:46:06
*/
/** Creates new form planning */
public planning()throws IOException {
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension tailleEcran = tk.getScreenSize();
int largeurEcran = tailleEcran.width;
int hauteurEcran = tailleEcran.height;
Image fond = tk.getImage("c:/steg-tunisie.jpg");
this.setLocation(largeurEcran * 2 / 8, hauteurEcran * 2 / 8);
FenetreFond fenFond = new FenetreFond(fond);
this.setContentPane(fenFond);
this.pack();
this.setBounds(100, 80, 900, 700);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jSeparator1 = new javax.swing.JSeparator();
jLabel4 = new javax.swing.JLabel();
jTextField2 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jSeparator3 = new javax.swing.JSeparator();
jScrollPane1 = new javax.swing.JScrollPane();
// jTable1 = new javax.swing.JTable();
jLabel2 = new javax.swing.JLabel();
jComboBox1 = new javax.swing.JComboBox();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
J=new javax.swing.JTable();
DefaultTableModel md = new DefaultTableModel();
md.setColumnIdentifiers(new String []{"nom de l'acteur","fonction","date de réalisation"});
/*----------------- c juste pr Determiner le nom de la colonne ------------------------- */
Class.forName("com.mysql.jdbc.Driver");
Connection connect=DriverManager.getConnection("jdbc:mysql://localhost:3306/g_inventaire","root","");
System.out.println("Connexion avec la base gestion inventaire établie");
// création d'un objet Statement
Statement S=connect.createStatement();
ResultSet rs = S.executeQuery("SELECT * FROM acteur");
int i=0;
while(rs.next())
{
Tab[i]=rs.getString(2);
i++;
}
/*ResultSet rs2=S.executeQuery("SELECT * FROM matériel");
int j=0;
while(rs2.next())
{
Tab2[j]=rs2.getString(2);
j++;
}*/
private void formWindowActivated(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
}
private void formWindowOpened(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
}
//afficher
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
DefaultTableModel md = new DefaultTableModel();
md.setColumnIdentifiers(new String []{"nom de l'acteur","fonction","date de réalisation"});
/*----------------- c juste pr Determiner le nom de la colonne ------------------------- */
Class.forName("com.mysql.jdbc.Driver");
Connection connect=DriverManager.getConnection("jdbc:mysql://localhost:3306/g_inventaire","root","");
System.out.println("Connexion avec la base gestion inventaire établie");
// création d'un objet Statement
Statement S=connect.createStatement();
ResultSet rs = S.executeQuery("SELECT * FROM planning,acteur WHERE planning.num_act=acteur.num_acteur");
System.out.println("bonjour");
md.addRow(new Object[]{"nom de l'acteur","fonction","date de réalisation"});
while (rs.next()){
/*---------------------- AJOUT DES LIGNES AU JTABLE --------------------*/
md.addRow(new Object[]{rs.getObject("nom_acteur"),rs.getObject("fonction"),rs.getObject("date")});
}
/*---------------------------------- AFFECTER LE MODEL AU JTABLE avec la methode setmodel ------------*/
//ajout
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String nom = (String)jComboBox1.getSelectedItem();
String date =jTextField2.getText();
String num_act="";
Connection connect=null; // connexion avec la base
Statement S=null; // objet d'émission des requêtes
int RS; // table résultat d'une requête
try{
// connexion à la base
Class.forName("com.mysql.jdbc.Driver");
connect=DriverManager.getConnection("jdbc:mysql://localhost:3306/g_inventaire","root","");
System.out.println("Connexion avec la base gestion inventaire établie");
// création d'un objet Statement
S=connect.createStatement();
ResultSet rs1=S.executeQuery("SELECT DISTINCT num_acteur FROM acteur WHERE nom_acteur='"+nom+"'");
while(rs1.next())
{
num_act=rs1.getString(1);
}
RS=S.executeUpdate("insert into planning values (null,'" + date + "','"+num_act+"')");
if (RS==1)
{
JOptionPane.showMessageDialog(this,"ajout avec succés","Menus",JOptionPane.INFORMATION_MESSAGE);
}
else JOptionPane.showMessageDialog(this,"problème de connexion","Menus",JOptionPane.INFORMATION_MESSAGE);
String nom = (String)jComboBox1.getSelectedItem();
String date=jTextField2.getText();
String num_act="";
Connection connect=null; // connexion avec la base
Statement S=null; // objet d'émission des requêtes
int RS; // table résultat d'une requête
try{
// connexion à la base
Class.forName("com.mysql.jdbc.Driver");
connect=DriverManager.getConnection("jdbc:mysql://localhost:3306/g_inventaire","root","");
System.out.println("Connexion avec la base gestion inventaire établie");
// création d'un objet Statement
S=connect.createStatement();
ResultSet rs1=S.executeQuery("SELECT DISTINCT num_planning FROM planning");
while(rs1.next())
{
num_act=rs1.getString(1);
}
RS=S.executeUpdate("UPDATE planning SET date='"+date+"' WHERE num_planning='"+num_act+"'");
if (RS==1)
{
JOptionPane.showMessageDialog(this,"modification effectuée avec succés","Menus",JOptionPane.INFORMATION_MESSAGE);
}
else JOptionPane.showMessageDialog(this,"problème de connexion","Menus",JOptionPane.INFORMATION_MESSAGE);
Connection connect=null; // connexion avec la base
Statement S=null; // objet d'émission des requêtes
int RS; // table résultat d'une requête
try{
// connexion à la base
Class.forName("com.mysql.jdbc.Driver");
connect=DriverManager.getConnection("jdbc:mysql://localhost:3306/g_inventaire","root","");
System.out.println("Connexion avec la base gestion inventaire établie");
// création d'un objet Statement
S=connect.createStatement();
ResultSet rs1=S.executeQuery("SELECT DISTINCT num_planning FROM planning");
while(rs1.next())
{
num_pl=rs1.getString(1);
}
RS=S.executeUpdate("DELETE FROM planning WHERE num_planning='"+num_pl+"'");
if (RS==1)
{
JOptionPane.showMessageDialog(this,"suppression effectué ","Menus",JOptionPane.INFORMATION_MESSAGE);
}
else JOptionPane.showMessageDialog(this,"problème de connexion","Menus",JOptionPane.INFORMATION_MESSAGE);
}
class DatePicker {
int month = java.util.Calendar.getInstance().get(java.util.Calendar.MONTH);
int year = java.util.Calendar.getInstance().get(java.util.Calendar.YEAR);;
JLabel l = new JLabel("", JLabel.CENTER);
String day = "";
JDialog d;
JButton[] button = new JButton[49];
public DatePicker(JFrame parent) {
d = new JDialog();
d.setModal(true);
String[] header = { "Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat" };
JPanel p1 = new JPanel(new GridLayout(7, 7));
p1.setPreferredSize(new Dimension(430, 120));
for (int x = 0; x < button.length; x++) {
final int selection = x;
button[x] = new JButton();
button[x].setFocusPainted(false);
button[x].setBackground(Color.white);
if (x > 6)
button[x].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
day = button[selection].getActionCommand();
d.dispose();
}
});
if (x < 7) {
button[x].setText(header[x]);
button[x].setForeground(Color.red);
}
p1.add(button[x]);
}
JPanel p2 = new JPanel(new GridLayout(1, 3));
JButton previous = new JButton("<< Previous");
previous.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
month--;
displayDate();
}
});
p2.add(previous);
p2.add(l);
JButton next = new JButton("Next >>");
next.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
month++;
displayDate();
}
});
p2.add(next);
d.add(p1, BorderLayout.CENTER);
d.add(p2, BorderLayout.SOUTH);
d.pack();
d.setLocationRelativeTo(parent);
d.setLocation(40,210);
displayDate();
d.setVisible(true);
}
public void displayDate() {
for (int x = 7; x < button.length; x++)
button[x].setText("");
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
"MMMM yyyy");
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.set(year, month, 1);
int dayOfWeek = cal.get(java.util.Calendar.DAY_OF_WEEK);
int daysInMonth = cal.getActualMaximum(java.util.Calendar.DAY_OF_MONTH);
for (int x 6 + dayOfWeek, day 1; day <= daysInMonth; x++, day++)
button[x].setText("" + day);
l.setText(sdf.format(cal.getTime()));
d.setTitle("Date Picker");
}
public String setPickedDate() {
if (day.equals(""))
return day;
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
"dd-MM-yyyy");
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.set(year, month, Integer.parseInt(day));
return sdf.format(cal.getTime());
}
}
A voir également:
[clos] je cherche à ajouter un bouton imprimer a mon JFrame pour imprimer les ch