Java et frame

fredo -  
choubaka Messages postés 39442 Date d'inscription   Statut Modérateur Dernière intervention   -
/




j'ai un pb je n'arrive pas a recuperer les donnée du textField pour gerer les evenement, le compilateur m'indique aucune fote





/ P681

// Cree une fenêtre secondaire depuis une applet.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="AppletFrame" width=300 height=50>
</applet>
*/

// Cree une sous-classe de Frame.
class FenetreFrame extends Frame implements ActionListener{
TextField parite ;
Label par ;
TextField indice_ref ;
Label ind_ref ;
TextField ind_act ;
Label indact ;

String a,b,c ;
Double aa,bb,cc ;

FenetreFrame(String titre) {
super(titre);
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT) ;
setLayout(f1) ;


// cree un objet pour gere les evenements de fenetre
TextField parite = new TextField(8) ;
Label par = new Label("parite") ;
TextField indice_ref = new TextField(8) ;
Label ind_ref = new Label(" indice parite");
TextField ind_act = new TextField(8) ;
Label indact = new Label("indice actuel") ;
add(parite) ;
add(par) ;
add(indice_ref) ;
add(ind_ref) ;
add(ind_act) ;
add(indact) ;

parite.addActionListener(this) ;
indice_ref.addActionListener(this) ;
ind_act.addActionListener(this) ;

// cree un objet pour gere les evenements de fenetre
FenetreAdapter adapter = new FenetreAdapter(this);
// s'enregistre pour recevoir les evenements
addWindowListener(adapter);
}

public void actionPerformed(ActionEvent ae) {

a = parite.getText() ;
b = indice_ref.getText() ;
c = ind_act.getText() ;
// repaint();
/*
aa = Double.parseDouble(a) ;
bb = Double.parseDouble(b) ;
cc = Double.parseDouble(c) ;
*/
}



public void paint(Graphics g) {
g.drawString("Dans la fenetre Frame" + a+ b + c, 100, 40);



}
}

class FenetreAdapter extends WindowAdapter {
FenetreFrame fenetreFrame;
public FenetreAdapter(FenetreFrame fenetreFrame) {
this.fenetreFrame = fenetreFrame;
}
public void windowClosing(WindowEvent we) {
fenetreFrame.setVisible(false);
}
}

// Cree une fenetre Frame.
public class cert1 extends Applet {
Frame f;
public void init() {
f = new FenetreFrame("Une fenetre Frame");

f.setSize(250, 250);
f.setVisible(true);
}
public void start() {
f.setVisible(true);
}
public void stop() {
f.setVisible(false);
}
public void paint(Graphics g) {
g.drawString("Dans la fenetre d'applet"+a+b+c, 10, 20);
}
}
A voir également:

1 réponse

choubaka Messages postés 39442 Date d'inscription   Statut Modérateur Dernière intervention   2 105
 
salut, j'ai vu que tu déclarais deux fois des objets (textfield)

/ P681

// Cree une fenêtre secondaire depuis une applet.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="AppletFrame" width=300 height=50>
</applet>
*/

// Cree une sous-classe de Frame.
class FenetreFrame extends Frame implements ActionListener{
TextField parite ;
Label par ;
TextField indice_ref ;
Label ind_ref ;
TextField ind_act ;
Label indact ;

String a,b,c ;
Double aa,bb,cc ;

FenetreFrame(String titre) {
super(titre);
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT) ;
setLayout(f1) ;


// cree un objet pour gere les evenements de fenetre
parite = new TextField(8) ;
par = new Label("parite") ;
indice_ref = new TextField(8) ;
ind_ref = new Label(" indice parite");
ind_act = new TextField(8) ;
indact = new Label("indice actuel") ;
add(parite) ;
add(par) ;
add(indice_ref) ;
add(ind_ref) ;
add(ind_act) ;
add(indact) ;

parite.addActionListener(this) ;
indice_ref.addActionListener(this) ;
ind_act.addActionListener(this) ;

// cree un objet pour gere les evenements de fenetre
FenetreAdapter adapter = new FenetreAdapter(this);
// s'enregistre pour recevoir les evenements
addWindowListener(adapter);
}

public void actionPerformed(ActionEvent ae) {

a = parite.getText() ;
b = indice_ref.getText() ;
c = ind_act.getText() ;
// repaint();
/*
aa = Double.parseDouble(a) ;
bb = Double.parseDouble(b) ;
cc = Double.parseDouble(c) ;
*/
}



public void paint(Graphics g) {
g.drawString("Dans la fenetre Frame" + a+ b + c, 100, 40);



}
}

class FenetreAdapter extends WindowAdapter {
FenetreFrame fenetreFrame;
public FenetreAdapter(FenetreFrame fenetreFrame) {
this.fenetreFrame = fenetreFrame;
}
public void windowClosing(WindowEvent we) {
fenetreFrame.setVisible(false);
}
}

// Cree une fenetre Frame.
public class cert1 extends Applet {
Frame f;
public void init() {
f = new FenetreFrame("Une fenetre Frame");

f.setSize(250, 250);
f.setVisible(true);
}
public void start() {
f.setVisible(true);
}
public void stop() {
f.setVisible(false);
}
public void paint(Graphics g) {
g.drawString("Dans la fenetre d'applet"+a+b+c, 10, 20);
}
}


//essaye comme ça

Choubanimal : 
Recherche producteur pour superproduction ou + si affinités
0