cs_lamia88
Messages postés53Date d'inscriptionvendredi 12 mars 2010StatutMembreDernière intervention11 juillet 2012
-
24 nov. 2010 à 01:47
cs_lamia88
Messages postés53Date d'inscriptionvendredi 12 mars 2010StatutMembreDernière intervention11 juillet 2012
-
29 nov. 2010 à 22:38
bonjours,
jai crée un jlable nommé label2,et je veut modifier ca place,jai utilisée setbounds mais sa ne fonctionne pas.
qulqun peut maider et merci d'avance.
voila le code que jai crée:
package Pck_CRC;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.LineBorder;
public class Interface_graphique extends JPanel
{
static JComboBox combo;
static JLabel label1,label2;
static String tabcomb[]={"Sélectionner un polynome","CRC-4","CRC-12","CRC-16","CRC-32"};
static JPanel panel1,panel2,panel3,panel4;
static JTextField fName,text2,text3;
static JButton put;
private static final long serialVersionUID = 1L;
Image backGround = null;
public Interface_graphique()
{
/** ___________________________Creation de La fenetre principale:_____________________________ **/
JFrame frm = new JFrame("La Detection Des erreurs");
frm.setBounds(0,0,600,500 );
frm.setLocation(200,145);
frm.setVisible(true);
setOpaque( false );
frm.getContentPane().setLayout(new BorderLayout() );
/** ___________________________Le panel qui contient le fond ecran:_____________________________ **/
panel2 = new PanelAvecFond( loadImages( frm, ".//fondecran.jpg" ) );
panel2.setLayout(null);
/** ___________________________Panel4 et son continu:_____________________________ **/
panel4 = new PanelAvecFond( loadImages( frm, "" ) );
panel4.setBounds(0,0,600,50);
panel4.setBorder(new LineBorder(Color.BLACK));
label1=new JLabel("Code Cyclique De Redondance");
label1.setFont(new Font("Cooper Black", Font.BOLD, 32));
label1.setForeground(Color.blue);
panel4.add(label1);
panel2.add(panel4,BorderLayout.NORTH);
/** ___________________________panel1 a gauche::_____________________________ **/
panel1=new PanelAvecFond.pane2AvecFond(loadImages(frm,""));
panel1.setBounds(0,50,200,450);
label2=new JLabel("La chaine à analysée");
label2.setBounds(10,10,0,100);//ne fonctionne pas
panel1.add(label2);
fName = new JTextField(8);
panel1.add(fName);
panel1.setBorder(new LineBorder(Color.green));
panel2.add(panel1, BorderLayout.EAST);
panel3 = new PanelAvecFond.pane2AvecFond(loadImages(frm,"" ));
panel3.setBounds(200,50,400,450);
text3 = new JTextField(8);
panel3.add(text3);
combo=new JComboBox();
combo.setSize(200,20);
for(int t=0;t<tabcomb.length;t++)
{
combo.addItem(tabcomb[t]);
}
combo.setEditable(true);
combo.setSelectedItem(tabcomb[0]);
combo.setBackground(Color.white);
combo.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
Object src = e.getSource();
if(src=="CRC-4")
{
text3.setText("haloow");
}
}
}
);
panel3.add(combo);
put = new JButton( "Put" );
put.addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
String g=fName.getText();
text3.setText(g);
}
} );
panel1.add( put );
panel3.setBorder(new LineBorder(Color.red));
panel2.add(panel3, BorderLayout.WEST);
frm.getContentPane().add( panel2 );
frm.setVisible( true );
}
/** ___________________________La méthode paint:_____________________________ **/
public void paint(Graphics g)
{
if ( backGround != null )
{
g.drawImage(backGround, 0, 0,getSize().width, getSize().height, this);
super.paint(g);
}
}
/** ___________________________La méthode load picture:_____________________________ **/
private static Image loadImages(JFrame frm, String imageFile )
{
try
{
MediaTracker mTrack = new MediaTracker( frm ); // load les image avant de les afficher
Image image = frm.getToolkit().getImage(getURL( imageFile));
mTrack.addImage(image,0);
mTrack.waitForAll();
return image;
}
catch (Exception e){System.out.println("getimages:" + e );}
return null;
}
/** ___________________________La méthode getURL:_____________________________ **/
public static URL getURL(String file)throws MalformedURLException
{
URL documentBase = new URL("file:///" + System.getProperty("user.dir")+ "/");
return new URL( documentBase, file );
}
/** ___________________________La Classe JPanelAvecFond:_____________________________ **/
@SuppressWarnings("serial")
public static class pane2AvecFond extends JPanel
{
Image backGround = null;
public pane2AvecFond( Image backGround )
{
this.backGround = backGround;
setOpaque( false );
}
public void paint( Graphics g )
{
if ( backGround != null )
g.drawImage( backGround, 0, 0,getSize().width, getSize().height, this );
super.paint( g );
}
}
public static void main(String args[])
{
Interface_graphique prog_prcpl=new Interface_graphique();
}
}
didoux95
Messages postés845Date d'inscriptionmardi 25 avril 2006StatutMembreDernière intervention 1 août 20172 28 nov. 2010 à 18:23
Il faut que tu utilises "setLayout(null);" pour quasiment tous les composant de type conteneur de ton application.
Je viens de relire le code plus attentivement et j'ai vu que tu n'utilises aucun LayoutManager..
cs_lamia88
Messages postés53Date d'inscriptionvendredi 12 mars 2010StatutMembreDernière intervention11 juillet 2012 29 nov. 2010 à 22:38
yes yes il marche trés bien,merci bcp Je n'oublierai jamais cette information(Lorsque j'utilisais setBound(..) il fallait qu'il n'y ai aucun layout sur le composant parent.).