Problème d'éxecution d'application

mouhamedba911 - 10 janv. 2013 à 10:31
 mouhamedba911 - 16 janv. 2013 à 11:36
bonjour...
j'ai un problème encore avec mon code source.. si je lance l'application, le programme me dit
Launch Error: Selection does not contain a main type...
en plus me met des croix rouges au niveau du Try, partout ou il y'a Test en m'indiquant Test cannot be resolved
voici mon code...
package projetjava;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class Securite extends JFrame  implements ActionListener{

/**
 * 
 */
private static final long serialVersionUID = 1L;
JPanel pan = new JPanel();
JLabel ltype= new JLabel("type user:");
JLabel llogin= new JLabel("Login:");
JLabel lpass= new JLabel("Password:");


JComboBox type = new JComboBox();
JTextField login = new JTextField("",15);
JPasswordField pass = new JPasswordField(15);
JButton valider = new JButton("Valider");

public Securite(){
pan.setBackground(Color.green);
this.setContentPane(pan);
pan.setLayout(new GridBagLayout());
GridBagConstraints g = new GridBagConstraints();
g.gridx= 0;
g.gridy=0;
g.insets=new Insets(5,5,5,5);
pan.add(ltype,g);


g = new GridBagConstraints();
g.gridx=1;
g.gridy=0;
g.insets=new Insets(5,5,5,5);
pan.add(type,g);

g = new GridBagConstraints();
g.gridx=0;
g.gridy=1;
g.insets=new Insets(5,5,5,5);
pan.add(llogin,g);

g = new GridBagConstraints();
g.gridx=1;
g.gridy=1;
g.insets=new Insets(5,5,5,5);
pan.add(login,g);

g = new GridBagConstraints();
g.gridx=0;
g.gridy=2;
g.insets=new Insets(5,5,5,5);
pan.add(lpass,g);

g = new GridBagConstraints();
g.gridx=1;
g.gridy=2;
g.insets=new Insets(5,5,5,5);
pan.add(pass,g);

g = new GridBagConstraints();
g.gridx=0;
g.gridy=3;
g.insets=new Insets(5,5,5,5);
g.gridwidth=2;
pan.add(valider,g);
this.setSize(700,700);
this.setVisible(true);
//les tables de la base de données à selectionner dans un menu deroulant(profil)
type.addItem("User");
type.addItem("Organisateur");
type.addItem("Administrateur");
valider.addActionListener(this);
}

@SuppressWarnings("deprecation")
@Override
public void actionPerformed(ActionEvent av) {
if(av.getSource()== valider){
if((login.getText().length())>0 && (pass.getText().length())>0){
String lg= login.getText();
String ps= pass.getText();
String ty=(String) type.getSelectedItem();

String req="Select * from "+ ty+ " where login='"+lg+ "' and pass='"+ps+"'";

try {
Statement st=  Test.con.createStatement();
ResultSet res;
res=st.executeQuery(req);
if (res.next()){
if(ty.equalsIgnoreCase("Administrateur")){

Test.f.setContentPane(new Administrateur());
Test.f.pack();

}  
 //affichage profil administrateur



if(ty.equalsIgnoreCase("user")){


      Test.f.setContentPane(new Simpl_user());
Test.f.pack();

}                          



if(ty.equalsIgnoreCase("Organisateur")){

Test.f.setContentPane(new Organisateur());
Test.f.pack();


}                           
}

else JOptionPane.showConfirmDialog(this,"login ou mot de passe incorrecte");


}

catch (SQLException e) {

e.printStackTrace();



}


}
else JOptionPane.showConfirmDialog(this,"Vous n'avez rien saisi");
}

}





}

merci d'avance..

4 réponses

cs_Julien39 Messages postés 6414 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 29 juillet 2020 371
10 janv. 2013 à 11:37
bonjour,

L'erreur signifie que tu n'as pas de méthode main qui te permet de créer le lanceur de ton programme dans la classe :

public static void main(String[] args){
   new Securite();
}


Ce morceau de code va régler ton problème.
0
cs_Julien39 Messages postés 6414 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 29 juillet 2020 371
10 janv. 2013 à 11:38
Pour ce qui est des erreur sur Test.con, tu utilises des objets, soit les attributs sont publics soit il faut créer des getters.

Je pense que tu devrais trouver un tutoriel sur la programmation objet en java pour t'en sortir. Je pense que quelque part, tu devrais avoir :

Test test = new Test();
test.getCon();


Par exemple
0
mouhamedba911
16 janv. 2013 à 11:29
Bonjour Julien39..
désolé pr tt ce temps...j'avais un problème avec mon système d'installation..
mais j'ai eu à compiler un code d'une autre application qui fonctionne trés bien mais je voudrais insérer un scrollbar (un bar défilement horizontal) dans ce code ci-dessous afin de visualiser toutes mes colonnes (au nombre de 61),dépassant non seulement la longueur de l'écran,mais réduisant mes champs qui sont presque plus vibles.

package Ihm;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.UnknownHostException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.swing.JButton;
import javax.swing.JComponent;
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.JTextPane;


public class FRecherche extends JPanel implements ActionListener{

JTextField recherche= new JTextField("",30);
JLabel titre= new JLabel("Recherche");
JButton ok= new JButton("Ok");
JButton quitter= new JButton("quitter");
JPanel affiche=new JPanel();
JPanel mere=new JPanel();
JScrollPane saffiche=new JScrollPane(affiche);
int nbchamp=61;
GridBagConstraints g;

FRecherche(){
this.setLayout(new GridBagLayout());
afficheConnexion();

ok.addActionListener(this);
quitter.addActionListener(this);
saffiche.setPreferredSize(new Dimension(1400,600));
}
public void afficheConnexion(){
this.removeAll();
this.setLayout(new GridBagLayout());

g=new GridBagConstraints();
g.gridx=0;
g.gridy=0;
g.insets=new Insets(10,10,90,10);
g.gridwidth=2;
this.add(titre,g);

g=new GridBagConstraints();
g.gridx=0;
g.gridy=1;
g.anchor=GridBagConstraints.WEST;
g.insets=new Insets(10,10,10,10);
this.add(recherche,g);

g=new GridBagConstraints();
g.gridx=1;
g.gridy=1;
this.add(ok,g);

g=new GridBagConstraints();
g.gridx=0;
g.gridy=2;
g.gridwidth=2;
g.anchor=GridBagConstraints.WEST;
g.insets=new Insets(10,10,10,10);
this.add(saffiche,g);

g=new GridBagConstraints();
g.gridx=0;
g.gridy=3;
g.insets=new Insets(10,10,10,10);
g.anchor=GridBagConstraints.WEST;
this.add(quitter,g);

this.updateUI();
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==quitter){
Test.fenetre.setContentPane(Test.fenetre.mere);
}
if(e.getSource()==ok){
try{
if((recherche.getText().length()>0)){
Statement st=Test.conusers.createStatement();
ResultSet r ;
String titre[]=new String[]{"RE_ID","BILLING_NBR","BILLING_IMSI","CALLING_NBR","CALLED_NBR","THIRD_PART_NBR","START_TIME","DURATION","TRUNK_OUT","TRUNK_IN","EVENT_SRC_ID","FILE_ID","RECORD_SEQ","CELL_A"};

r = st.executeQuery("select * from cdr where RE_ID='"+recherche.getText()+"' or BILLING_NBR='"+recherche.getText()+"' or BILLING_IMSI='"+recherche.getText()+"' or CALLING_NBR='"+recherche.getText()+"' or CALLED_NBR='"+recherche.getText()+"' or THIRD_PART_NBR='"+recherche.getText()+"' or START_TIME='"+recherche.getText()+"' or DURATION='"+recherche.getText()+"' or TRUNK_OUT='"+recherche.getText()+"' or TRUNK_IN='"+recherche.getText()+"' or EVENT_SRC_ID='"+recherche.getText()+"' or FILE_ID='"+recherche.getText()+"' or RECORD_SEQ='"+recherche.getText()+"' or CELL_A='"+recherche.getText()+"'");
   int n=0;
while(r.next())
n++;


String don[][]=new String[n][nbchamp];
 r = st.executeQuery("select * from cdr where RE_ID='"+recherche.getText()+"' or BILLING_NBR='"+recherche.getText()+"' or BILLING_IMSI='"+recherche.getText()+"' or CALLING_NBR='"+recherche.getText()+"' or CALLED_NBR='"+recherche.getText()+"' or THIRD_PART_NBR='"+recherche.getText()+"' or START_TIME='"+recherche.getText()+"' or DURATION='"+recherche.getText()+"' or TRUNK_OUT='"+recherche.getText()+"' or TRUNK_IN='"+recherche.getText()+"' or EVENT_SRC_ID='"+recherche.getText()+"' or FILE_ID='"+recherche.getText()+"' or RECORD_SEQ='"+recherche.getText()+"' or CELL_A='"+recherche.getText()+"'");
int i=0;
 while(r.next()){
    	for(int j=0;j<nbchamp;j++)
    		don[i][j]=r.getString(j+1);
    		i++;
    }
 
 JTable table=new JTable(don,titre);
 actualiser(table);

}
else
JOptionPane.showConfirmDialog(this,"Veuillez saisir un mot","Erreur saisie",JOptionPane.CANCEL_OPTION,JOptionPane.CANCEL_OPTION,null);

}
catch(SQLException s){
s.printStackTrace();
}

}
}
public void actualiser(JComponent p){
this.remove(saffiche);
saffiche=new JScrollPane(p);
saffiche.setPreferredSize(new Dimension(1400,600));
g=new GridBagConstraints();
g.gridx=0;
g.gridy=2;
g.gridwidth=2;
g.anchor=GridBagConstraints.WEST;
g.insets=new Insets(10,10,10,10);
this.add(saffiche,g);
this.updateUI();

}
}


0
mouhamedba911
16 janv. 2013 à 11:36
les String titre[] doivent etre au nombre de 61 mais ici par défaut de barre de défilement je me suis limiter à 15 seulement pour pouvoir les visualiser tous..
mais j'arrive à insérer la barre de défilement horizontale alors je pourrai compléter les 46 string titre restants( d'ou le nombre total de mes colonnes égal à 61)
0
Rejoignez-nous