Swing affichage de frame annexe

Signaler
Messages postés
1
Date d'inscription
samedi 5 juin 2004
Statut
Membre
Dernière intervention
5 juin 2004
-
Messages postés
237
Date d'inscription
mercredi 2 juin 2004
Statut
Membre
Dernière intervention
11 juillet 2006
-
Bonsoir,

pour une appli je tente depuis une fenetre principale d'ouvrir une frame annexe mais impossible et pourtant le compile me dit ok
je n'arrive pas a trouver l'erreur svp aidé moi

pour mieux visualisé l'erreur ou l'homission j'ai reduit le code a un jbutton et une frame annexe

je vous remercie d'avance a tous
Bien amicalement

@+ christian

pensé du jour:
le savoir ne vaut que si il est partagé



import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.Color;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.border.BevelBorder;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;

public class CuttingDrilling1 extends JFrame implements WindowListener,ActionListener
{


final JButton CoupeGeologique = new JButton("Coupe Geologique");


public CuttingDrilling1() {
super("FENETRE PRINCIPAL");
setSize(800, 600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);


//Panneau global de fond
JPanel fond = new JPanel(new GridLayout());
fond.setBackground (Color.blue);
getContentPane().add(fond);
setVisible(true);

JPanel pane = new JPanel();
GridLayout family = new GridLayout(1, 1, 10, 10);
pane.setBackground (Color.blue);
fond.add(pane);
pane.setLayout(family);
pane.add(CoupeGeologique);

setContentPane(pane);

// les menus :
MenuBar mb = new MenuBar( );
Menu mepri1 = new Menu("Fichier");
Menu mepri2 = new Menu("Edition");
Menu mepri3 = new Menu("Affichage");
Menu mepri4 = new Menu("Insertion");
Menu mepri5 = new Menu("Format");
Menu mepri6 = new Menu("Aide");
MenuItem ite1 = new MenuItem("Nouveaux");
MenuItem ite2 = new MenuItem("Ouvrir");
MenuItem ite3 = new MenuItem("Enregistrer");
MenuItem ite4 = new MenuItem("Enregistrer sous");
MenuItem ite5 = new MenuItem("Imprimer");
MenuItem ite6 = new MenuItem("Aperçu avant impression");
MenuItem ite7 = new MenuItem("Mise en page");
MenuItem ite8 = new MenuItem("Envoyer");
MenuItem ite9 = new MenuItem("Quitter");
setMenuBar(mb);
mepri1.add(ite1);
mepri1.add(ite2);
mepri1.add(ite3);
mepri1.add(ite4);
mepri1.add(ite5);
mepri1.add(ite6);
mepri1.add(ite7);
mepri1.add(ite8);
mepri1.add(ite9);
mb.add(mepri1);
mb.add(mepri2);
mb.add(mepri3);
mb.add(mepri4);
mb.add(mepri5);
mb.add(mepri6);
}
//Enregistrez tous les composants en tant qu'ecouteur

public void registerListeners(){
final JButton CoupeGeologique=new JButton("Coupe Geologique");
CoupeGeologique.setActionCommand("CoupeGeologique");
CoupeGeologique.addActionListener(this);
this.addWindowListener(this); }




public void actionPerformed(ActionEvent evt)
{
String cmde = evt.getActionCommand();
if(cmde.equals("CoupeGeologique"))
{
//creation d un objet de type CoupeGeologique
CoupeGeologique coupe= new CoupeGeologique();
coupe.setVisible(true);
}

}

public static void main(String[] arguments){
CuttingDrilling1 cut=new CuttingDrilling1();



}

/*** 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)
{}



}

class CoupeGeologique extends JFrame {


private JTable tableView;

private TableModel dataModel;


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();
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);



JPanel row1= new JPanel();
GridLayout grid=new GridLayout(5,5);
row1.setBackground(Color.blue);
fond.add(row1);
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);

//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);


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);

//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);

//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);


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.
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
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);

}

}





1 réponse

Messages postés
237
Date d'inscription
mercredi 2 juin 2004
Statut
Membre
Dernière intervention
11 juillet 2006

Pourquoi ne fais tu pas dans ton actionPerformed un :
ifi (e.getSource() == tonBouton)
new coupeGeologique.setVisible(true);

cid019