CONNEXION
  • RetourJeux
    • Sorties
    • Hit Parade
    • Les + populaires
    • Les + attendus
    • Soluces
    • Tous les Jeux
    • Gaming
  • RetourActu Gaming
    • News
    • Astuces
    • Tests
    • Previews
    • Toute l'actu gaming
  • RetourBons plans
    • Bons plans
    • Bons plans Smartphone
    • Bons plans Hardware
    • Bons plans Image et Son
    • Bons plans Amazon
    • Bons plans Cdiscount
    • Bons plans Decathlon
    • Bons plans Fnac
    • Tous les Bons plans
  • RetourJVTech
    • Actus High-Tech
    • Intelligence Artificielle
    • Smartphones
    • Mobilité urbaine
    • Hardware
    • Image et son
    • Tutoriels
    • Tests produits High-Tech
    • Guides d'achat High-Tech
    • JVTech
  • RetourCulture
    • Actus Culture
    • Culture
  • RetourVidéos
    • A la une
    • Gaming Live
    • Vidéos Tests
    • Vidéos Previews
    • Gameplay
    • Trailers
    • Chroniques
    • Replay Web TV
    • Toutes les vidéos
  • RetourForums
    • Hardware PC
    • PS5
    • Switch 2
    • Xbox Series
    • Switch
    • Pokemon pocket
    • FC 25 Ultimate Team
    • League of Legends
    • Tous les Forums
  • PC
  • PS5
  • Xbox Series
  • Switch 2
  • PS4
  • One
  • Switch
  • iOS
  • Android
  • MMO
  • RPG
  • FPS
En ce moment Genshin Impact Valhalla Breath of the wild Animal Crossing GTA 5 Red dead 2
Liste des sujets

java imprimer un txt

PSG_77
PSG_77
Niveau 10
30 mars 2004 à 23:18:15

saluttt

je voudrais avoir un peu d´aide en java

je vous explique mon ptit probleme :) :

j´ai une interface et une personne rempli des case ( jtextfield), je vais chercher le contenu de ces cases et apres je les fais affiché dans un fichier . txt

mais je voudrais imprimer comment faire ? ?

je sais qu´il existe Jprintjob mais je vois pas comment lui indiqué d´aller chercher le nom du fichier et d´imprimer :-(

voila merci bcp pour ceux qui pourront m´aidé :)

jarose
jarose
Niveau 10
31 mars 2004 à 04:40:30

Bon j´ai pas écrit un truc qui t´imprime le contenu d´un fichier, pour la simple raison qu´il faut que tu travailles un peu :)

PSG_77
PSG_77
Niveau 10
31 mars 2004 à 09:37:58

salut merci pour ta reponse :)

le probleme c´est que sur ma fenetre le bouton imprimer ne s´affiche pas :(

je te mets tous le code( c un peu long ) :

package interfac;

import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import com.borland.dx.sql.dataset.*;

/ /importation des librairies pour imprimer
import java.awt.print.*;
import java.util.Properties;
/ /import java.io.DataOutputStream;
/ /import java.io.FileOutputStream;

import java.util.Locale;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

class requete_bilan
{
public static void connect(String nb_badge) throws Exception
{

Class.forName("com.mysql.jdbc.Driver").newInstance
();

Connection conn =
DriverManager.getConnection("jdbc:mysql://lgbciris
/badgeuse","connectbadge","connect");

conn.setAutoCommit(false);
Statement st = conn.createStatement();

ResultSet rs = st.executeQuery("select * from employe, stokage where employe.badge=´"+nb_badge+"´ AND stokage.badge=´"+nb_badge+"´ " );
conn.commit();
conn.setAutoCommit(true);

fen fenetre = new fen();
fenetre.setBounds(100, 100, 600, 500); / / position et dimension de la fenetre
fenetre.show(); / / Afficher la fenetre
fenetre.setTitle("Bilan du salarié");

SimpleDateFormat formatter = new SimpleDateFormat ( "yyyy.MM.dd"); / /recupere l´heure
Date currentTime_1 = new Date();// recupere la date et l´heure
String dateString = formatter.format(currentTime_1); / / recupere la date

String temps_mois9="";
String mois = dateString.substring(5,7); / / découpage de la chaine de caractere pour ne selectionner que le mois
int mois1 = Integer.parseInt(mois); / / transformer la chaine de caractere mois en entier mois1

switch ( mois1)
{
case 1:
temps_mois9 = " temp_mois_janvier";
break;
case 2:
temps_mois9 = " temp_mois_fevrier";
break;
case 3:
temps_mois9 = " temp_mois_mars";
break;
case 4:
temps_mois9 = " temp_mois_avril";
break;
case 5:
temps_mois9 = " temp_mois_mai";
break;
case 6:
temps_mois9 = " temp_mois_juin";
break;
case 7:
temps_mois9 = " temp_mois_juillet";
break;
case 8:
temps_mois9 = " temp_mois_aout";
break;
case 9:
temps_mois9 = " temp_mois_septembre";
break;
case 10:
temps_mois9 = " temp_mois_octobre";
break;
case 11:
temps_mois9 = " temp_mois_novembre";
break;
case 12:
temps_mois9 = " temp_mois_decembre";
break;
}

while( rs.next())
{

fenetre.ChampHeure_Effectue1.setText((String)rs.ge
tString(temps_mois9));

fenetre.ChampSemaine.setText((String)rs.getString(
"temp_semaine"));

fenetre.ChampNom.setText((String)rs.getString("nom
"));

fenetre.ChampPrenom.setText((String)rs.getString("
prenom"));

fenetre.ChampBadge.setText((String)rs.getString("b
adge"));

fenetre.ChampAdress.setText((String)rs.getString("
adresse_1"));

fenetre.ChampAdress2.setText((String)rs.getString(
"adresse_2"));

fenetre.ChampCp.setText((String)rs.getString("cp")
);

fenetre.ChampVille.setText((String)rs.getString("v
ille"));
}
rs.close();
}
}

public class fen extends JFrame
{
XYLayout xYLayout2 = new XYLayout();
JTextArea nom = new JTextArea();
JTextArea prenom = new JTextArea();
JTextArea cp = new JTextArea();
JTextArea adresse1 = new JTextArea();
JTextArea adresse2 = new JTextArea();
JTextArea badge = new JTextArea();
JTextArea ville = new JTextArea();
JTextArea semaine = new JTextArea();
JTextArea Heure_Effectue = new JTextArea();
JTextField ChampNom = new JTextField();
JTextField ChampPrenom = new JTextField();
JTextField ChampCp = new JTextField();
JTextField ChampAdress = new JTextField();
JTextField ChampAdress2 = new JTextField();
JTextField ChampVille = new JTextField();
JTextField ChampBadge = new JTextField();
JTextField ChampHeure_Effectue1 = new JTextField();
JTextField ChampSemaine = new JTextField();
public fen()
{
try {
jbInit();
}
catch ( Exception e) {
e.printStackTrace();
}

}

private void jbInit() throws Exception
{
ChampPrenom.setEditable(false);
ChampPrenom.setText("");
ChampNom.setFont(new java.awt.Font("Dialog", 1, 16));
ChampNom.setEditable(false);
ChampNom.setText("");
nom.setBackground(Color.lightGray);
nom.setEditable(false);
nom.setText(" Nom :");
xYLayout2.setWidth(507);
xYLayout2.setHeight(483);

this.getContentPane().setBackground(Color.lightGra
y);
this.setLocale(java.util.Locale.getDefault());
this.setState(Frame.NORMAL);
this.getContentPane().setLayout(xYLayout2);
prenom.setBackground(Color.lightGray);
prenom.setEditable(false);
prenom.setText(" Prenom :");
cp.setBackground(Color.lightGray);
cp.setEditable(false);
cp.setText(" Code postal :");
adresse1.setBackground(Color.lightGray);
adresse1.setEditable(false);
adresse1.setText(" Adresse :");
adresse2.setBackground(Color.lightGray);
adresse2.setEditable(false);
adresse2.setText(" Adresse 2 :");
badge.setBackground(Color.lightGray);
badge.setEditable(false);
badge.setText("Badge :");
ville.setBackground(Color.lightGray);
ville.setEditable(false);
ville.setText(" Ville :");
ChampCp.setRequestFocusEnabled(true);
ChampCp.setEditable(false);
ChampCp.setText("");
ChampVille.setEditable(false);
ChampVille.setText("");
ChampAdress2.setEditable(false);
ChampAdress2.setText("");
ChampAdress.setEditable(false);
ChampAdress.setText("");
ChampBadge.setFont(new java.awt.Font("Dialog", 1, 16));
ChampBadge.setEditable(false);
ChampBadge.setText("");
Heure_Effectue.setBackground(Color.lightGray);
Heure_Effectue.setText(" Heure effectué par mois :");
ChampHeure_Effectue1.setEditable(false);
ChampHeure_Effectue1.setSelectionStart(11);
ChampHeure_Effectue1.setText("");
ChampSemaine.setToolTipText("");
ChampSemaine.setEditable(false);
ChampSemaine.setText("");
semaine.setBackground(Color.lightGray);
semaine.setToolTipText("");
semaine.setVerifyInputWhenFocusTarget(true);
semaine.setText(" Heure effectué par semaine :");
this.getContentPane().add(badge, new XYConstraints(355, 37, 55, 20));
this.getContentPane().add(prenom, new XYConstraints(34, 84, 68, 20));
this.getContentPane().add(adresse1, new XYConstraints(34, 124, 77, 20));
this.getContentPane().add(adresse2, new XYConstraints(34, 164, 90, 20));
this.getContentPane().add(ville, new XYConstraints(34, 204, 61, 20));
this.getContentPane().add(cp, new XYConstraints(34, 244, 103, 20));
this.getContentPane().add(ChampBadge, new XYConstraints(424, 24, 70, 35));
this.getContentPane().add(nom, new XYConstraints(35, 37, 47, 20));
this.getContentPane().add(Heure_Effectue, new XYConstraints(34, 284, 186, 20));
this.getContentPane().add(ChampPrenom, new XYConstraints(172, 84, 100, 20));
this.getContentPane().add(ChampAdress2, new XYConstraints(172, 164, 165, 20));
this.getContentPane().add(ChampCp, new XYConstraints(172, 244, 50, 20));
this.getContentPane().add(ChampVille, new XYConstraints(172, 204, 165, 20));
this.getContentPane().add(ChampAdress, new XYConstraints(172, 123, 165, 20));
this.getContentPane().add(ChampNom, new XYConstraints(172, 27, 100, 35));
this.getContentPane().add(semaine, new XYConstraints(34, 324, 205, 20));

this.getContentPane().add(ChampHeure_Effectue1,new
XYConstraints(255, 284, 110, 20));
this.getContentPane().add(ChampSemaine, new XYConstraints(255, 324, 110, 20));
}

class Contxt extends Canvas
{
public void paint(Graphics g)
{
g.setColor(new Color(0,0,0));
g.fillRect(100, 100, 40, 40);
}

public Dimension preferredSize() {
return new Dimension(50, 50);
}
}

class Jprint extends fen implements ActionListener
{

Contxt _contxt = new Contxt ( ) ;
Button _goprint = new Button ( " print ! " );

Jprint()
{
add("Center", _contxt);
add("South", _goprint);
_goprint.addActionListener ( this);
}

public void actionPerformed(ActionEvent e)
{
Properties ppt = new Properties();

PrintJob pJob = getToolkit().getPrintJob(this, " Nom_Dialog", ppt);

if ( pJob ! = null)
{
Graphics prtg = pJob.getGraphics();

/ / Imprime toute la frame
/ /printAll ( prtg);

/ / Imprime seulement le canvas " _contxt"
_contxt.printAll ( prtg);

prtg.dispose ( ) ;
pJob.end ( ) ;
}
}

}
}

==> autre petite question Canvas c´est quoi ? ?

PSG_77
PSG_77
Niveau 10
31 mars 2004 à 10:54:21

en faite mon probleme est un peu plus compliqué si tu as msn et que tu veux bien m´aider contact moi a juju_PSG_@hotmail.com je t´expliquerais plus en detail le probleme . .. :)

jarose
jarose
Niveau 10
31 mars 2004 à 12:31:32

Oulala, je te conseille de réviser ton Java :)
Déja ne cherches pas à mélanger swing et awt !

`Canvas` est une classe qui dérive de Component, et qui permet d´écrire ses propres composants.

jarose
jarose
Niveau 10
31 mars 2004 à 12:33:46

Et c´est mort pour msn ou autre. Je t´ai fourni là, de quoi résoudre ton problème.

PSG_77
PSG_77
Niveau 10
31 mars 2004 à 18:21:30

je vois pas ou je melange le awt et le swing . .. ?

jarose
jarose
Niveau 10
31 mars 2004 à 19:33:40

Tu as écrit ton truc avec des methodes swing alors que moi j´ai utilisé awt.
Et, en plus de ça tu veux afficher des composants dans un container inexistant.
Cherches un peu : (

PSG_77
PSG_77
Niveau 10
31 mars 2004 à 19:50:48

ouep mais moi je cherche en faite a imprimer une partie de la fenetre graphique ( sans le bouton imprimer ) ....

j´ai deja fait le test avec un bouton classique mais ca m´imprime tout . . meme le haut des fenetres windows :-(

tu as pas un exemple avec swing ? ??

PSG_77
PSG_77
Niveau 10
01 avril 2004 à 10:53:28

sinon personne ne sait comment on fait pour imprimer un fichier txt qui se trouve sur le disque toujours en java . ..

PSG_77
PSG_77
Niveau 10
05 avril 2004 à 10:07:25

Salutt :)

voila j´ai reussi à trouver un code sur un forum qui permet d´imprimer un fichier . TXT , mais j´ai un probleme avec job . .. comment le declare t´on ? ?

et j´ai aussi un probleme de printerExecption qu´il ne veut pas traité . .

voila le code :

try {
/ / Set up destination attribute
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(new Destination(new java.net.URI("file:c:/fichier.txt")));

/ / Print it
job.print(doc, aset);
} catch ( PrintException ev) {
} catch ( java.net.URISyntaxException eu) {
}

PSG_77
PSG_77
Niveau 10
06 avril 2004 à 10:39:57

en faite un pote de classe m´a aidé et on a crer un jpanel ou j´ai mis tt mes cases dedans et j´imprime ma jpanel et ca marche impec :) . ..

Sous forums
  • Aide à l'achat Mac
  • Macintosh
  • Création de sites web
  • Création de Jeux
  • Linux
  • Programmation
  • Internet
  • Steam Deck
  • Hardware
La vidéo du moment