p51d | Bonsoir a tous,
je tente de lier pour une appli java ma menubar a mon imprimante
en implementant la methode printm
et la je coince car je manque de connaissance sur sont implementation
et en regardant dans different bouquin ( biblio de classe, le programmeur java2 ) je n'est rien trouvé
si quelqu'un aurait des infos sur un livre ou un lien ou je puisse trouver ces renseignement cela serait genial
je joint mon code avec le debut de l'implementation menubar/inprimante
D'avance merci a tous
Code :
- import java.awt.event.ActionListener;
- import java.awt.*;
- import javax.swing.*;
- import javax.swing.table.*;
- import javax.swing.border.*;
- import java.awt.Dimension;
- import java.awt.event.WindowAdapter;
- import java.awt.event.WindowEvent;
- import java.awt.Color;
- public class CoupeGeologique extends JFrame {
-
-
-
-
-
-
-
- public CoupeGeologique(){
- super("Coupe Geologique" );
- setSize(800,600);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- Container Pane=getContentPane();
- FlowLayout flow=new FlowLayout(FlowLayout.CENTER);
- setVisible(true);
-
-
-
- //Panneau global de fond
- JPanel fond = new JPanel(new BorderLayout());
- fond.setBackground(Color.blue);
- getContentPane().add(fond);
- setVisible(true);
-
-
- //les menus :
- MenuBar mbar = new MenuBar( );
- Menu meprinc1 = new Menu("Fichier" );
- Menu meprinc2 = new Menu("Edition" );
- Menu meprinc3 = new Menu("Affichage" );
- Menu meprinc4 = new Menu("Insertion" );
- Menu meprinc5 = new Menu("Format" );
- Menu meprinc6 = new Menu("Aide" );
- MenuItem item1 = new MenuItem("Enregistrer" );
- MenuItem item2 = new MenuItem("Enregistrer sous" );
- MenuItem item3 = new MenuItem("Imprimer" );
- MenuItem item4 = new MenuItem("Apercu avant impression" );
- MenuItem item5 = new MenuItem("Mise en page" );
- MenuItem item6 = new MenuItem("Envoyer" );
- MenuItem item7 = new MenuItem("Quitter" );
- setMenuBar(mbar);
- meprinc1.add(item1);
- meprinc1.add(item2);
- meprinc1.add(item3);
- meprinc1.add(item4);
- meprinc1.add(item5);
- meprinc1.add(item6);
- meprinc1.add(item7);
- mbar.add(meprinc1);
- mbar.add(meprinc2);
- mbar.add(meprinc3);
- mbar.add(meprinc4);
- mbar.add(meprinc5);
- mbar.add(meprinc6);
-
- meprinc1.add(item3);
- item3.setActionCommand("Imprimer" );
- item3.addActionListener(new ActionListener(){
- public void actionPerformed (ActionEvent m) {
- printme();
- }});
- JPanel row1= new JPanel();
- GridLayout grid=new GridLayout(5,5);
- row1.setBackground(Color.blue);
- fond.add(row1, BorderLayout.CENTER);
- row1.setLayout(grid);
- setContentPane(row1);
- setVisible(true);
-
- //definition de la premiere ligne
- JPanel row2=new JPanel();
- JLabel NumberFromFileLabel =new JLabel("Numeros de Dossier:",JLabel.CENTER);
- row2.add(NumberFromFileLabel);
- JTextField NumerosdeDossier=new JTextField(10);
- FlowLayout layout1 = new FlowLayout(FlowLayout.CENTER,10,10);
- Container Pane1 = getContentPane();
- Pane1.setLayout(layout1);
- row2.setLayout(layout1);
- row2.add(NumerosdeDossier);
- Pane1.add (NumberFromFileLabel);
- Pane1.add(NumerosdeDossier);
- setContentPane(Pane1);
-
-
-
- JPanel row3=new JPanel();
- JLabel SiteLabel=new JLabel("Chantier:",JLabel.CENTER);
- row3.add(SiteLabel);
- JTextField Chantier=new JTextField(17);
- FlowLayout layout2=new FlowLayout(FlowLayout.CENTER,10,10);
- Container pane2= getContentPane();
- pane2.setLayout(layout2);
- row3.add(Chantier);
- row3.setLayout(layout2);
- pane2.add(SiteLabel);
- pane2.add(Chantier);
- setContentPane(pane2);
- //definition de la troisieme ligne
- JPanel row4=new JPanel();
- JLabel ResponsibleFromBusinessLabel=new JLabel("Responsable de l Affaire:" );
- row4.add(ResponsibleFromBusinessLabel);
- JTextField ResponsabledelAffaire=new JTextField(12);
- FlowLayout flow2=new FlowLayout(FlowLayout.LEFT);
- Container pane3= getContentPane();
- pane3.setLayout(flow2);
- row4.add(ResponsabledelAffaire);
- pane3.add(ResponsibleFromBusinessLabel);
- pane3.add(ResponsabledelAffaire);
- setContentPane(pane3);
- //definition de la deuxieme ligne
- JPanel row5=new JPanel();
- JLabel TypesFromDrillingLabel =new JLabel("Types de Forage:" );
- row5.add(TypesFromDrillingLabel);
- JTextField TypesdeForage=new JTextField();
- FlowLayout flow3 = new FlowLayout(FlowLayout.LEFT);
- Container pane4 = getContentPane();
- pane4.setLayout(flow3);
- row5.add(TypesdeForage);
- pane4.add (TypesFromDrillingLabel);
- pane4.add(TypesdeForage);
- setContentPane(pane4);
-
-
- JComboBox SiteAndTypeFromDrilling =new JComboBox();
- FlowLayout flow4= new FlowLayout(FlowLayout.LEFT);
- Container pane5=getContentPane();
- SiteAndTypeFromDrilling.addItem("Sondage destructif" );
- SiteAndTypeFromDrilling.addItem("Sondage carotte" );
- SiteAndTypeFromDrilling.addItem("Sondage pressio" );
- SiteAndTypeFromDrilling.addItem("Forage d eau" );
- SiteAndTypeFromDrilling.addItem("Forage geothermique" );
- pane5.setLayout(flow4);
- pane5.add(SiteAndTypeFromDrilling);
- setContentPane(pane5);
- SiteAndTypeFromDrilling.setEditable(true);
- //definition de la sixieme ligne
- JPanel row6=new JPanel();
- JLabel MannerAndTypeAnyDrillingLabel=new JLabel("Moyens mis en Oeuvre:" );
- row6.add(MannerAndTypeAnyDrillingLabel);
- JTextField MoyensMisEnOeuvre=new JTextField();
- FlowLayout flow5=new FlowLayout(FlowLayout.LEFT);
- Container pane6= getContentPane();
- pane6.setLayout(flow5);
- row6.add(MoyensMisEnOeuvre);
- pane6.add(MannerAndTypeAnyDrillingLabel);
- pane6.add(MoyensMisEnOeuvre);
- setContentPane(pane6);
- //definition de la septieme ligne
- JComboBox MannerAnyDrilling =new JComboBox();
- FlowLayout flow6= new FlowLayout(FlowLayout.CENTER);
- Container pane7=getContentPane();
- MannerAnyDrilling.addItem("Forage hydraulique" );
- MannerAnyDrilling.addItem("Forage pneumatique" );
- MannerAnyDrilling.addItem("Forage rotary" );
- pane7.setLayout(flow6);
- pane7.add(MannerAnyDrilling);
- setContentPane(pane7);
- MannerAnyDrilling.setEditable(true);
- JPanel row7=new JPanel();
- JLabel TypesFromCompressorLabel=new JLabel("Compresseur:" );
- row7.add(TypesFromCompressorLabel);
- JTextField Compresseur=new JTextField(12);
- FlowLayout flow7=new FlowLayout(FlowLayout.RIGHT);
- Container pane8= getContentPane();
- pane8.setLayout(flow7);
- row7.add(Compresseur);
- pane8.add(TypesFromCompressorLabel);
- pane8.add(Compresseur);
- setContentPane(pane8);
- //definition de la sixieme ligne
- JPanel row8=new JPanel();
- JLabel TypesFromToolsLabel=new JLabel("Types d' Outils :" );
- row8.add(TypesFromToolsLabel);
- JTextField TypedOutils=new JTextField();
- FlowLayout flow8=new FlowLayout(FlowLayout.LEFT);
- Container pane9= getContentPane();
- pane9.setLayout(flow8);
- row8.add(TypedOutils);
- pane9.add(TypesFromToolsLabel);
- pane9.add(TypedOutils);
- setContentPane(pane9);
- //definition de la septieme ligne
- JComboBox Tools =new JComboBox();
- FlowLayout flow9= new FlowLayout(FlowLayout.LEFT);
- Container pane10=getContentPane();
- Tools.addItem("Tariere" );
- Tools.addItem("Taillant" );
- Tools.addItem("Fichtail" );
- Tools.addItem("Marteau fond de trou" );
- Tools.addItem("Odex" );
- Tools.addItem("Couronne diams" );
- Tools.addItem("Couronne carbure" );
- Tools.addItem("Couronne mixte" );
- Tools.addItem("Trepans" );
- pane10.setLayout(flow9);
- pane10.add(Tools);
- setContentPane(pane10);
- Tools.setEditable(true);
- //definition de la sixieme ligne
- JPanel row9=new JPanel();
- JLabel FromLabel=new JLabel("Diametre De A :" );
- row9.add(FromLabel);
- JTextField DA=new JTextField(12);
- FlowLayout flow10=new FlowLayout(FlowLayout.LEFT);
- Container pane11= getContentPane();
- pane11.setLayout(flow10);
- row9.add(DA);
- pane11.add(FromLabel);
- pane11.add(DA);
- setContentPane(pane11);
- //definition de la quatrieme ligne ligne
- JPanel row10=new JPanel();
- JLabel TypeanycarottageLabel=new JLabel("Types des Carottages :" );
- row10.add(TypeanycarottageLabel);
- JTextField CAROTTAGE=new JTextField();
- FlowLayout flow11=new FlowLayout(FlowLayout.LEFT);
- Container pane12= getContentPane();
- pane12.setLayout(flow11);
- row10.add(CAROTTAGE);
- pane12.add(TypeanycarottageLabel);
- pane12.add(CAROTTAGE);
- setContentPane(pane12);
- //definition de la cinqieme ligne
- JComboBox Carottage =new JComboBox();
- FlowLayout flow12=new FlowLayout(FlowLayout.LEFT);
- Container pane13=getContentPane();
- Carottage.addItem("Rotation carottier" );
- Carottage.addItem("Carottier Battu" );
- Carottage.addItem("Tubage" );
- Carottage.addItem("Carottier Cable" );
- pane13.setLayout(flow12);
- pane13.add(Carottage);
- setContentPane(pane13);
- Carottage.setEditable(true);
- //definition de la sixieme ligne
- JPanel row11=new JPanel();
- JLabel FromToLabel=new JLabel("Diametre De a:" );
- row11.add(FromToLabel);
- JTextField Dea=new JTextField(12);
- FlowLayout flow13=new FlowLayout(FlowLayout.LEFT);
- Container pane14= getContentPane();
- pane14.setLayout(flow13);
- row11.add(Dea);
- pane14.add(FromToLabel);
- pane14.add(Dea);
- setContentPane(pane14);
- //definition de la quatrieme ligne ligne
- JPanel row12=new JPanel();
- JLabel TypeanyTubageLabel=new JLabel("Types de Tubages :" );
- row12.add(TypeanyTubageLabel);
- JTextField TypesdeTubages=new JTextField();
- FlowLayout flow14=new FlowLayout(FlowLayout.LEFT);
- Container pane15= getContentPane();
- pane15.setLayout(flow14);
- row12.add(TypesdeTubages);
- pane15.add(TypeanyTubageLabel);
- pane15.add(TypesdeTubages);
- setContentPane(pane15);
- //definition de la cinqieme ligne
- JComboBox Tubage =new JComboBox();
- FlowLayout flow15=new FlowLayout(FlowLayout.LEFT);
- Container pane16=getContentPane();
- Tubage.addItem("120/140 mm" );
- Tubage.addItem("98/114 mm" );
- Tubage.addItem("70/90 mm" );
- Tubage.addItem("ODEX ET AUTRES" );
- pane16.setLayout(flow15);
- pane16.add(Tubage);
- setContentPane(pane16);
- Tubage.setEditable(true);
-
- JPanel row13=new JPanel();
- JLabel RefusalToLabel=new JLabel("Refus A:" );
- row13.add(RefusalToLabel);
- JTextField RefusA=new JTextField(10);
- FlowLayout flow16=new FlowLayout(FlowLayout.RIGHT);
- Container pane17= getContentPane();
- pane17.setLayout(flow14);
- row13.add(RefusA);
- pane17.add(RefusalToLabel);
- pane17.add(RefusA);
- setContentPane(pane17);
-
- JPanel row14=new JPanel();
- JLabel PzLabel=new JLabel("Piezo:" );
- row14.add(PzLabel);
- JTextField Piezo=new JTextField(10);
- FlowLayout flow17=new FlowLayout(FlowLayout.CENTER);
- Container pane18= getContentPane();
- pane18.setLayout(flow15);
- row14.add(Piezo);
- pane18.add(PzLabel);
- pane18.add(Piezo);
- setContentPane(pane18);
-
-
- // Take the dummy data from SwingSet.
- final String[] names = {"Nature des Terrains", "Vitesse P ms","Vitesse S ms", "Habituel Color",
- "De A","Nature de Sol","Couleur","Masse Volumique", "Present oui non"};
- final Object[][] data = {
- {"Eboulis Terre vegetale", "300-700","100-300", "Maroon","","","", new Integer(1), new Boolean(true)},
- {"Sable sec", "400-1200","100-500", "Blanc","","","", new Integer(1), new Boolean(false)},
- {"Sable humide", "1500-4000","400-1200", "yellow","","","", new Integer(1), new Boolean(false)},
- {"Argile", "1100-2500","200-800", "Turquois","","","", new Integer(1), new Boolean(true)},
- {"Marnes", "2000-3000","750-1500", "Blue","","","", new Integer(1), new Boolean(false)},
- {"Gres", "3000-4500","1500-2800", "Blanc","","","", new Integer(1), new Boolean(false)},
- {"Calcaires", "3500-6000","2000-3300", "blanc","","","", new Integer(1), new Boolean(false)},
- {"Craies", "2300-2600","1100-1300", "Blanc","","","", new Integer(1), new Boolean(false)},
- {"Sel", "4500-5500","2500-3100", "Blanc","","","", new Integer(1), new Boolean(false)},
- {"Anhydrite", "4000-5500","2500-3100", "Purple","","","", new Integer(1), new Boolean(false)},
- {"Dolomie", "3500-6500","1900-3600", "Purple","","","", new Integer(1), new Boolean(false)},
- {"Granites", "4500-6000","2500-3300", "Gris","","","", new Integer(1), new Boolean(false)},
- {"Basalte", "5000-6000","2800-3400", "Maroon","","","", new Integer(1), new Boolean(false)},
- {"Charbon", "2200-2700","1000-1400", "Black","","","", new Integer(1), new Boolean(false)},
- {"Eau", "1450-1500","1000-1400", "Blue","","","", new Integer(1), new Boolean(false)},
- {"Glace", "3400-3800","1700-1900", "Blanc","","","", new Integer(1), new Boolean(false)},
- {"Huile", "1200-1250","1700-1900", "Green","","","", new Integer(1), new Boolean(false)},
- {"Quartz", "","", "Red","","","", new Integer(1), new Boolean(false)},
- {"or", "","", "Yellow","","","", new Integer(1), new Boolean(false)},
- {"Diamant", "","", "Blue","","","", new Integer(1), new Boolean(false)},
- {"Petrole", "", "","Black","","","", new Integer(1), new Boolean(false)}
- };
- // Create a model of the data.
- TableModel dataModel = new AbstractTableModel() {
- // These methods always need to be implemented.
- public int getColumnCount() { return names.length; }
- public int getRowCount() { return data.length;}
- public Object getValueAt(int row, int col) {return data[row][col];}
- // The default implementations of these methods in
- // AbstractTableModel would work, but we can refine them.
- public String getColumnName(int column) {return names[column];}
- public Class getColumnClass(int c) {return getValueAt(0, c).getClass();}
- public boolean isCellEditable(int row, int col) {return true;}
- public void setValueAt(Object aValue, int row, int column) {
- System.out.println("Setting value to: " + aValue);
- data[row][column] = aValue;
- }
- };
- // Create the table
- JTable tableView = new JTable(dataModel);
- // Turn off auto-resizing so that we can set column sizes programmatically.
- // In this mode, all columns will get their preferred widths, as set blow.
- tableView.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
- // Create a combo box to show that you can use one in a table.
- JComboBox comboBox = new JComboBox();
- comboBox.addItem("Maronn" );
- comboBox.addItem("Orange" );
- comboBox.addItem("Yellow" );
- comboBox.addItem("Green" );
- comboBox.addItem("Blue" );
- comboBox.addItem("Indigo" );
- comboBox.addItem("Violet" );
- comboBox.addItem("Beige" );
- comboBox.addItem("blanc" );
- TableColumn colorColumn = tableView.getColumn("Habituel Color" );
- // Use the combo box as the editor in the "Habituel Color" column.
- colorColumn.setCellEditor(new DefaultCellEditor(comboBox));
- // Set a pink background and tooltip for the Color column renderer.
- DefaultTableCellRenderer colorColumnRenderer = new DefaultTableCellRenderer();
- colorColumnRenderer.setBackground(Color.pink);
- colorColumnRenderer.setToolTipText("Click for combo box" );
- colorColumn.setCellRenderer(colorColumnRenderer);
- // Set a tooltip for the header of the colors column.
- TableCellRenderer headerRenderer = colorColumn.getHeaderRenderer();
- if (headerRenderer instanceof DefaultTableCellRenderer)
- ((DefaultTableCellRenderer)headerRenderer).setToolTipText("Hi Mom!" );
- // Set the width of the "Present oui non" column.
- TableColumn presentouinonColumn = tableView.getColumn("Present oui non" );
- presentouinonColumn.setPreferredWidth(100);
- // Show the values in the "Masse Volumique" column in different colors.
- TableColumn numbersColumn = tableView.getColumn("Masse Volumique" );
- DefaultTableCellRenderer numberColumnRenderer = new DefaultTableCellRenderer() {
- public void setValue(Object value) {
- int cellValue = (value instanceof Number) ? ((Number)value).intValue() : 0;
- setForeground((cellValue > 30) ? Color.black : Color.red);
- setText((value == null) ? "" : value.toString());
- }
- };
- numberColumnRenderer.setHorizontalAlignment(JLabel.RIGHT);
- numbersColumn.setCellRenderer(numberColumnRenderer);
- numbersColumn.setPreferredWidth(110);
- // Finish setting up the table.
- JScrollPane scrollpane = new JScrollPane(tableView);
- scrollpane.setBorder(new BevelBorder(BevelBorder.LOWERED));
- scrollpane.setPreferredSize(new Dimension(800, 600));
- getContentPane().add(scrollpane);
- pack();
- setVisible(true);
-
- }
- public static void main(String[]arguments){
- CoupeGeologique coupe=new CoupeGeologique();
-
- }
- /*** methodes heritées de l interface WindowListener ***/
- public void windowOpened(WindowEvent e)
- {}
- public void windowClosing(WindowEvent e)
- {}
- public void windowClosed(WindowEvent e)
- {}
- public void windowIconified(WindowEvent e)
- {}
- public void windowDeiconified(WindowEvent e)
- {}
- public void windowActivated(WindowEvent e)
- {}
- public void windowDeactivated(WindowEvent e)
- {}
-
- }
|
et encore merci |