首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在TextFields中拾取用户输入的信息不起作用?

在TextFields中拾取用户输入的信息不起作用?
EN

Stack Overflow用户
提问于 2016-03-17 02:22:52
回答 1查看 43关注 0票数 0

我正在写一个小代码,用户在一个带有不同按钮的框架上为烟花设置导火索,然后当他按下启动动画时,一个新的窗口弹出,烟花在上面绘制,使用一个名为peindre的方法,我知道它已经可以工作了(我已经仔细测试过了)。

当我编译用于这个帧的类时,一个带有所需按钮的窗口出现,并且一切正常,直到我按下启动动画,在这种情况下只出现一个黑色窗口。peindre做的第一件事(代码在下面)是把整个窗口涂成黑色,然后它为每个保险丝启动线程,等待一段时间,然后绘制保险丝并擦除它们,这在我直接测试它时起作用。但是在这里我看不到任何保险丝出现!我可以当我自己创建一个主要的,所以这确实是一个问题,我的程序没有得到正确的用户输入的信息。

代码语言:javascript
复制
//ATTRIBUTES
    public TextField duree, tpsExplosion, altitude, avancement, puissEtincelles ;
    public double dureed, tpsExplosiond, xf, yf, puissEtincellesd ;
    public boolean bicoloreb ;
    public Choice choixForme, choixCouleur ;
    public String forme ;
    public Color couleur ;
    public Button plus ;
    public Button animation ;
    public Checkbox bicolore ;
    public FenetreAnimeeSansCanvas fenetreAnimee ; 
    public FenetreNouvelleFusee fenetreNouvelleFusee ; 
    int numero = 0 ;
    public String choixFormes, choixCouleurs;
    static final long serialVersionUID=1L;  

    //CONSTRUCTOR
    public AnimationSansCanvas() { 
        super("AnimationSansCanvas") ;
        altitude = new TextField("Altitude de l'explosion") ;
        avancement = new TextField("Position de l'explosion sur l'axe des abscisses");
        duree = new TextField("Durée de l'affichage de la fusée") ;
        tpsExplosion = new TextField("Moment de l'explosion (par rapport au début de l'animation)");
        choixForme = new Choice();
        choixForme.add("Choix de la forme :");
        choixForme.add("Étoile");
        choixForme.add("Croix");
        choixForme.add("Point");
        choixCouleur = new Choice();
        choixCouleur.add("Choix de la couleur :");
        choixCouleur.add("Rouge");
        choixCouleur.add("Vert");
        choixCouleur.add("Bleu");
        choixCouleur.add("Rose");
        choixCouleur.add("Jaune");
        choixCouleur.add("Orange");
        puissEtincelles = new TextField("Puissance de 8 du nombre d'étincelles");
        plus = new Button("Ajouter une fusée") ;
        animation = new Button ("Lancer l'animation") ;
        bicolore = new Checkbox("Fusée bicolore (la deuxième moitié sera rouge)", false) ;
        setLayout(new FlowLayout());
        this.add(altitude) ;
        this.add(avancement) ;
        this.add(duree);
        this.add(tpsExplosion);
        this.add(choixForme);
        this.add(choixCouleur);
        this.add(puissEtincelles);
        this.add(plus);
        this.add(animation);
        this.add(bicolore);
        altitude.addActionListener(this);
        avancement.addActionListener(this);
        duree.addActionListener(this);
        tpsExplosion.addActionListener(this);
        puissEtincelles.addActionListener(this);
        plus.addActionListener(this);
        animation.addActionListener(this);
        choixCouleur.addItemListener(this);
        choixForme.addItemListener(this);
        bicolore.addItemListener(this);
        addWindowListener(new EcouteurPourFermetureFenetre()); //pour tout arrêter en cas de fermeture de fenêtre
        setResizable(true);

        fenetreAnimee = new FenetreAnimeeSansCanvas() ;
                fenetreAnimee.setVisible(true);
    }

    //METHODES
    public void actionPerformed(ActionEvent evt){
        if (evt.getSource() == plus){ 
            numero += 1 ;
            fenetreNouvelleFusee = new FenetreNouvelleFusee() ;
            fenetreNouvelleFusee.numero = numero ;
            fenetreNouvelleFusee.setVisible(true); 
            fenetreAnimee.fusees.add(fenetreNouvelleFusee.fuse) ; 
        }
        if (evt.getSource() == animation){
            numero += 1 ;
            Fusee fuse = new Fusee(numero) ;
            puissEtincellesd =
            Double.valueOf(puissEtincelles.getText());
            tpsExplosiond = Double.valueOf(tpsExplosion.getText());
            dureed = Double.valueOf(duree.getText());
            xf = Double.valueOf(avancement.getText());
            yf = Double.valueOf(altitude.getText());
            fuse.bicolore = bicolore.getState() ;
            fuse.couleur = couleur ;
            fuse.puissEtincelles = (int)puissEtincellesd ;
            fuse.xf = xf ;
            fuse.yf = yf ;
            fuse.forme = forme ;
            fuse.duree = dureed ;
            fuse.tpsDepart = tpsExplosiond ;
            fenetreAnimee.fusees.add(fuse) ; 
            fenetreAnimee.peindre(fenetreAnimee.getGraphics());  
            fenetreAnimee.setVisible(true); 
        }

    public void itemStateChanged(ItemEvent ivt){  
        if (ivt.getSource()==choixCouleur){
            if (choixCouleur.getSelectedItem()=="Rose"){
                couleur = Color.pink ;
            }
            if (choixCouleur.getSelectedItem()=="Bleu"){
                couleur = Color.blue ;
            }
            if (choixCouleur.getSelectedItem()=="Vert"){
                couleur = Color.green ;
            }
            if (choixCouleur.getSelectedItem()=="Rouge"){
                couleur = Color.red ;
            }
            if (choixCouleur.getSelectedItem()=="Jaune") {
                couleur = Color.yellow ;
            }
            if (choixCouleur.getSelectedItem()=="Orange") {
                couleur = Color.orange ;
            }
        }
    }


    //MAIN
    public static void main(String [] abs){
           AnimationSansCanvas anim = new AnimationSansCanvas();
           anim.setLocation(100, 100);
           anim.setSize(600, 450);
           anim.setVisible(true);
    }

}

在获取用户提供的信息时,我肯定做错了什么,但我看不到我的错误!当我自己在主体中添加一个保险丝时,它画得很好,它似乎没有得到我在框架中键入的信息。如果有人能告诉我我的程序出了什么问题,那就太好了:)

这是fenetreAnimeeSansCanvas,fenetreNouvelleFusee,Etincelle和Fusee的代码!(不要觉得你需要看它,只是为了以防万一你想编译整个程序)

(在peindre中,线程只计算时间的流逝,然后绘制保险丝,然后在时间结束时再次擦除它们)

代码语言:javascript
复制
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.* ;
import java.util.concurrent.*;


public class FenetreAnimeeSansCanvas extends Frame {


//ATTRIBUTS
    public LinkedList <Fusee> fusees ;
    int w,h, numEnCours=1, numMax = 1, puissEtincellesMax=1 ;
    double duree = 1 ;
    boolean suspended ;


    //CONSTRUCTEUR
        public FenetreAnimeeSansCanvas() {
            super("FenetreAnimeeSansCanvas") ;
            setSize(1200,700) ;
            setLocation(120,100) ;
            setResizable(true) ;
            w = this.getSize().width ;
            h = this.getSize().height ;
            addWindowListener(new EcouteurPourFermetureFenetre());
            fusees = new LinkedList() ;
        }

        //METHODES
        public void peindre(Graphics gr){       
            gr.setColor(Color.black);
            gr.fillRect(0, 0, w, h); 
            for (Fusee fus : fusees) {
                fus.g = gr ; 
                fus.anim.start();
            }
        }




        //MAIN
        public static void main(String [] abs){
               FenetreAnimeeSansCanvas fen = new FenetreAnimeeSansCanvas() ;
               fen.setVisible(true) ;

               Fusee fus = new Fusee(1) ;
                fus.forme = "point" ;
                fus.tpsDepart = 5 ;
                fus.puissEtincelles = 6 ;
                fus.couleur = Color.orange ;
                fus.duree = 10 ;
                fus.xf = 567 ;
                fus.yf = 590 ;
                fus.active = true ;
                fen.fusees.add(fus) ;        


                   Fusee fus1 = new Fusee(2) ;
                    fus1.forme = "etoile" ;
                    fus1.tpsDepart = 12 ;
                    fus1.puissEtincelles = 12 ;
                    fus1.couleur = Color.pink ;
                    fus1.duree = 20 ;
                    fus1.xf = 1000 ;
                    fus1.yf = 150 ;
                    fus1.active = true ;
                    fen.fusees.add(fus1) ;        


                       Fusee fus2 = new Fusee(3) ;
                        fus2.forme = "croix" ;
                        fus2.bicolore = true ;
                        fus2.tpsDepart = 10 ;
                        fus2.puissEtincelles = 8 ;
                        fus2.couleur = Color.green ;
                        fus2.duree = 32 ;
                        fus2.xf = 276 ;
                        fus2.yf = 290 ;
                        fus2.active = true ;
                        fen.fusees.add(fus2) ;   

                        Fusee fus3 = new Fusee(3) ; 
                        fus3.forme = "point" ;
                        fus3.tpsDepart = 14 ;
                        fus3.bicolore = true ;
                        fus3.puissEtincelles = 12 ;
                        fus3.couleur = Color.blue ;
                        fus3.duree = 20 ;
                        fus3.xf = 850 ;
                        fus3.yf = 370 ;
                        fus3.active = true ;
                        fen.fusees.add(fus3) ;  

               Graphics gr = fen.getGraphics();
               fen.peindre(gr);   
               } 
}

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.* ;

public class FenetreNouvelleFusee extends Frame implements ActionListener, ItemListener{

//ATTRIBUTS 
public TextField duree, tpsExplosion, altitude, avancement, puissEtincelles ;
public double dureed, tpsExplosiond, xf, yf, puissEtincellesd ;
public Choice choixForme, choixCouleur ;
public String forme ;
public Color couleur ;
public Button pret ;
public Checkbox bicolore ;
public int numero ;
public String choixFormes, choixCouleurs;
public Fusee fuse ;
static final long serialVersionUID=1L;  

//CONSTRUCTEUR
public FenetreNouvelleFusee() { 
    super("FenetreNouvelleFusee") ;
    setSize(600,450) ;
    setLocation(150,150) ;
    altitude = new TextField("Altitude de l'explosion") ;
    avancement = new TextField("Position de l'explosion sur l'axe des abscisses");
    duree = new TextField("Durée de l'affichage de la fusée") ;
    tpsExplosion = new TextField("Moment de l'explosion (par rapport au début de l'animation)");
    choixForme = new Choice();
    choixForme.add("Choix de la forme :");
    choixForme.add("Étoile");
    choixForme.add("Croix");
    choixForme.add("Point");
    choixCouleur = new Choice();
    choixCouleur.add("Choix de la couleur :");
    choixCouleur.add("Rouge");
    choixCouleur.add("Vert");
    choixCouleur.add("Bleu");
    choixCouleur.add("Rose");
    choixCouleur.add("Jaune");
    choixCouleur.add("Orange");
    bicolore = new Checkbox("Fusée bicolore (la deuxième moitié sera rouge)", false) ;
    puissEtincelles = new TextField("Puissance de 8 du nombre d'étincelles");
    pret = new Button("Fusée prête !") ;
    setLayout(new FlowLayout());
    this.add(altitude) ;
    this.add(avancement) ;
    this.add(duree);
    this.add(tpsExplosion);
    this.add(choixForme);
    this.add(choixCouleur);
    this.add(puissEtincelles);
    this.add(pret);
    this.add(bicolore);
    altitude.addActionListener(this);
    avancement.addActionListener(this);
    duree.addActionListener(this);
    tpsExplosion.addActionListener(this);
    puissEtincelles.addActionListener(this);
    pret.addActionListener(this);
    choixCouleur.addItemListener(this);
    choixForme.addItemListener(this);
    bicolore.addItemListener(this);
    addWindowListener(new EcouteurPourFermetureFenetre()); 
    setResizable(true);
}

//METHODES
    public void actionPerformed(ActionEvent evt){
        if (evt.getSource() == pret){ 
            numero += 1 ;
            fuse = new Fusee(numero) ;
            puissEtincellesd = Double.valueOf(puissEtincelles.getText());
            tpsExplosiond = Double.valueOf(tpsExplosion.getText());
            dureed = Double.valueOf(duree.getText());
            xf = Double.valueOf(avancement.getText());
            yf = Double.valueOf(altitude.getText());
            fuse.bicolore = bicolore.getState() ;
            fuse.couleur = couleur ;
            fuse.puissEtincelles = (int)puissEtincellesd ;
            fuse.xf = xf ;
            fuse.yf = yf ;
            fuse.forme = forme ;
            fuse.duree = dureed ;
            fuse.tpsDepart = tpsExplosiond ;
            fuse.puissEtincelles = (int)puissEtincellesd ;
            setVisible(false) ; 
        }
    }

    public void itemStateChanged(ItemEvent ivt){
        if (ivt.getSource()==choixCouleur){
            if (choixCouleur.getSelectedItem()=="Rose"){
                couleur = Color.pink ;
            }
            if (choixCouleur.getSelectedItem()=="Bleu"){
                couleur = Color.blue ;
            }
            if (choixCouleur.getSelectedItem()=="Vert"){
                couleur = Color.green ;
            }
            if (choixCouleur.getSelectedItem()=="Rouge"){
                couleur = Color.red ;
            }
            if (choixCouleur.getSelectedItem()=="Jaune") {
                couleur = Color.yellow ;
            }
            if (choixCouleur.getSelectedItem()=="Orange") {
                couleur = Color.orange ;
            }
        }
        if (ivt.getSource()==choixForme){
            forme = choixForme.getSelectedItem(); 
        }
    }

    //MAIN
    public static void main(String [] abs){
           FenetreNouvelleFusee fen = new FenetreNouvelleFusee();
           fen.setVisible(true) ;
           } 

}



import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.math.*;
import java.awt.Image;
import java.awt.image.BufferedImage;



public class Etincelle {
//ATTRIBUTS
public Color couleur ;
public double duree, x,y ;
public String forme ;
public BufferedImage image ;
Graphics g ; 
//CONSTRUCTEUR
public Etincelle(double a, double b){
    x=a;
    y=b;
    forme = "croix";
    couleur=Color.red ; 
    image = new BufferedImage(15,15, BufferedImage.TYPE_INT_ARGB); 
    g = image.createGraphics();
}

//METHODES
public void peindreEtincelle(Graphics globalg) {
    g.setColor(couleur);
    if (forme == "croix") {
        g.drawLine(6-5, 6, 6+5, 6);
        g.drawLine(6, 6-5, 6, 6+5); 
    }
    else if (forme == "point"){
        g.fillOval(6, 6, 8, 8);
    }
    else if (forme=="etoile"){
        g.drawLine(6-5, 6, 6+5, 6);
        g.drawLine(6, 6-5, 6, 6+5); 
        g.drawLine(6-5, 6-5, 6+5, 6+5);
        g.drawLine(6-5, 6+5, 6+5, 6-5); 
    }
    globalg.drawImage(image,(int)x,(int)y,null); 
}


//MAIN
public static void main(String[] args) {
     }




}


import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.math.*;


public class Fusee extends Canvas implements Runnable {
//ATTRIBUTS
public int num, puissEtincelles, nbEtincelles;
public double xf, yf, duree, tpsDepart ;
public boolean active = true, bicolore = false, suspended = false ;
public String forme ;
public Thread anim ;
public int k = 0 ;
public Color couleur, couleur2 = Color.red ;
public static double DIV = 1%(Math.sqrt(2)) ;
public LinkedList<Etincelle> liste;
public Graphics g;
int w, h ; 
static final long serialVersionUID=1L;


//CONSTRUCTEUR
public Fusee(int numero){   /
    num = numero ;
    active = true ;
    couleur = Color.red ;
    nbEtincelles = 1 + 8^puissEtincelles; 
    anim = new Thread(this) ; 
    liste = new LinkedList<Etincelle>() ; 
    liste.add(new Etincelle(xf,yf));   
    for (int k =1 ; k<=puissEtincelles ;k++){
        liste.add(new Etincelle(xf+10*k,yf));
        liste.add(new Etincelle(xf-10*k,yf));
        liste.add(new Etincelle(xf,yf+10*k));
        liste.add(new Etincelle(xf,yf-5*k));
        liste.add(new Etincelle(xf+10*k*DIV,yf+10*k*DIV));
        liste.add(new Etincelle(xf+10*k*DIV,yf-10*k*DIV));
        liste.add(new Etincelle(xf-10*k*DIV,yf+10*k*DIV));
        liste.add(new Etincelle(xf-10*k*DIV,yf-10*k*DIV));
    }

    w = 1200 ;
    h = 700 ;
}

 //METHODE
public void run(){                  
    while (true){
    if (active == true){
        if (tpsDepart == 0) {
          if (duree>0){ 
             if (bicolore == false) {
                 duree = duree-1 ;
                 peindreFusee(g) ;
                 if (k<puissEtincelles) {
                    k+=1 ;
                    }
             }
             else if (bicolore == true){
                 duree = duree-1 ;
                 peindreFuseeBicolore(g) ;
                 if (k<puissEtincelles) {
                    k+=1 ;
                    }
             }
          }
          else if (duree == 0){
             active = false ;
          }
        }
        else if (tpsDepart >0){
            tpsDepart = tpsDepart - 1 ; 
        }
    }
    else if (active == false){  
        couleur = Color.black ; 
             peindreFuseeFin(g) ;
         }
         else if (bicolore == true){
             couleur2 = Color.black ;
             peindreFuseeBicoloreFin(g) ;
         }
        anim.stop(); 
    }
    try {
        Thread.sleep(400);
      }
      catch(InterruptedException e) {
        System.out.println(e);
      }
    }
}






public String toString(){
    String chaine = "Numéro fusée" ;
    chaine += "  " + String.valueOf(num);
    chaine += "  " +String.valueOf(yf);
    chaine += "  " +String.valueOf(xf);
    chaine += "  " +String.valueOf(duree);
    chaine += "  " +String.valueOf(tpsDepart);
    chaine += "  " +String.valueOf(forme);
    chaine += "  " +String.valueOf(couleur);
    chaine += "  " +String.valueOf(puissEtincelles);
    chaine += "  " +String.valueOf(bicolore);
    return chaine ;
}





public void peindreFusee (Graphics g){

    Etincelle etinc0 = new Etincelle(xf,yf) ;  
    etinc0.couleur = couleur ;
    etinc0.forme = forme ;
    etinc0.duree = duree ;
    etinc0.peindreEtincelle(g);
        Etincelle etinc1 = new Etincelle(xf+10*k,yf) ;
        etinc1.couleur = couleur ;
        etinc1.forme = forme ;
        etinc1.duree = duree ;
        etinc1.peindreEtincelle(g);
        Etincelle etinc2 = new Etincelle(xf-10*k,yf) ;
        etinc2.couleur = couleur ;
        etinc2.forme = forme ;
        etinc2.duree = duree ;
        etinc2.peindreEtincelle(g);
        Etincelle etinc3 = new Etincelle(xf,yf+10*k) ;
        etinc3.couleur = couleur ;
        etinc3.forme = forme ;
        etinc3.duree = duree ;
        etinc3.peindreEtincelle(g);
        Etincelle etinc4 = new Etincelle(xf,yf-10*k) ;
        etinc4.couleur = couleur ;
        etinc4.forme = forme ;
        etinc4.duree = duree ;
        etinc4.peindreEtincelle(g);
        Etincelle etinc5 = new Etincelle(xf+10*k*DIV,yf+10*k*DIV) ;
        etinc5.couleur = couleur ;
        etinc5.forme = forme ;
        etinc5.duree = duree ;
        etinc5.peindreEtincelle(g);
        Etincelle etinc6 = new Etincelle(xf+10*k*DIV,yf-10*k*DIV) ;
        etinc6.couleur = couleur ;
        etinc6.forme = forme ;
        etinc6.duree = duree ;
        etinc6.peindreEtincelle(g);
        Etincelle etinc7 = new Etincelle(xf-10*k*DIV,yf+10*k*DIV) ;
        etinc7.couleur = couleur ;
        etinc7.forme = forme ;
        etinc7.duree = duree ;
        etinc7.peindreEtincelle(g);
        Etincelle etinc8 = new Etincelle(xf-10*k*DIV,yf-10*k*DIV) ;
        etinc8.couleur = couleur ;
        etinc8.forme = forme ;
        etinc8.duree = duree ;
        etinc8.peindreEtincelle(g);
    }


public void peindreFuseeBicolore (Graphics g){
        Etincelle etinc0 = new Etincelle(xf,yf) ;   
        etinc0.couleur = couleur ;
        etinc0.forme = forme ;
        etinc0.duree = duree ;
        etinc0.peindreEtincelle(g);
            Etincelle etinc1 = new Etincelle(xf+10*k,yf) ;
            etinc1.couleur = couleur ;
            etinc1.forme = forme ;
            etinc1.duree = duree ;
            etinc1.peindreEtincelle(g);
            Etincelle etinc2 = new Etincelle(xf-10*k,yf) ;
            etinc2.couleur = couleur2 ;
            etinc2.forme = forme ;
            etinc2.duree = duree ;
            etinc2.peindreEtincelle(g);
            Etincelle etinc3 = new Etincelle(xf,yf+10*k) ;
            etinc3.couleur = couleur ;
            etinc3.forme = forme ;
            etinc3.duree = duree ;
            etinc3.peindreEtincelle(g);
            Etincelle etinc4 = new Etincelle(xf,yf-10*k) ;
            etinc4.couleur = couleur2 ;
            etinc4.forme = forme ;
            etinc4.duree = duree ;
            etinc4.peindreEtincelle(g);
            Etincelle etinc5 = new Etincelle(xf+10*k*DIV,yf+10*k*DIV) ;
            etinc5.couleur = couleur ;
            etinc5.forme = forme ;
            etinc5.duree = duree ;
            etinc5.peindreEtincelle(g);
            Etincelle etinc6 = new Etincelle(xf+10*k*DIV,yf-10*k*DIV) ;
            etinc6.couleur = couleur ;
            etinc6.forme = forme ;
            etinc6.duree = duree ;
            etinc6.peindreEtincelle(g);
            Etincelle etinc7 = new Etincelle(xf-10*k*DIV,yf+10*k*DIV) ;
            etinc7.couleur = couleur2 ;
            etinc7.forme = forme ;
            etinc7.duree = duree ;
            etinc7.peindreEtincelle(g);
            Etincelle etinc8 = new Etincelle(xf-10*k*DIV,yf-10*k*DIV) ;
            etinc8.couleur = couleur2 ;
            etinc8.forme = forme ;
            etinc8.duree = duree ;
            etinc8.peindreEtincelle(g);

}


public void peindreFuseeFin(Graphics g){
    Etincelle etinc0 = new Etincelle(xf,yf) ;   
    etinc0.couleur = couleur ;
    etinc0.forme = forme ;
    etinc0.duree = duree ;
    etinc0.peindreEtincelle(g);
    for (int k=1 ; k<=puissEtincelles +3 ; k++){
        Etincelle etinc1 = new Etincelle(xf+10*k,yf) ;
        etinc1.couleur = couleur ;
        etinc1.forme = forme ;
        etinc1.duree = duree ;
        etinc1.peindreEtincelle(g);
        Etincelle etinc2 = new Etincelle(xf-10*k,yf) ;
        etinc2.couleur = couleur ;
        etinc2.forme = forme ;
        etinc2.duree = duree ;
        etinc2.peindreEtincelle(g);
        Etincelle etinc3 = new Etincelle(xf,yf+10*k) ;
        etinc3.couleur = couleur ;
        etinc3.forme = forme ;
        etinc3.duree = duree ;
        etinc3.peindreEtincelle(g);
        Etincelle etinc4 = new Etincelle(xf,yf-10*k) ;
        etinc4.couleur = couleur ;
        etinc4.forme = forme ;
        etinc4.duree = duree ;
        etinc4.peindreEtincelle(g);
        Etincelle etinc5 = new Etincelle(xf+10*k*DIV,yf+10*k*DIV) ;
        etinc5.couleur = couleur ;
        etinc5.forme = forme ;
        etinc5.duree = duree ;
        etinc5.peindreEtincelle(g);
        Etincelle etinc6 = new Etincelle(xf+10*k*DIV,yf-10*k*DIV) ;
        etinc6.couleur = couleur ;
        etinc6.forme = forme ;
        etinc6.duree = duree ;
        etinc6.peindreEtincelle(g);
        Etincelle etinc7 = new Etincelle(xf-10*k*DIV,yf+10*k*DIV) ;
        etinc7.couleur = couleur ;
        etinc7.forme = forme ;
        etinc7.duree = duree ;
        etinc7.peindreEtincelle(g);
        Etincelle etinc8 = new Etincelle(xf-10*k*DIV,yf-10*k*DIV) ;
        etinc8.couleur = couleur ;
        etinc8.forme = forme ;
        etinc8.duree = duree ;
        etinc8.peindreEtincelle(g);
    }
}



public void peindreFuseeBicoloreFin(Graphics g){
    Etincelle etinc0 = new Etincelle(xf,yf) ;   
    etinc0.couleur = couleur ;
    etinc0.forme = forme ;
    etinc0.duree = duree ;
    etinc0.peindreEtincelle(g);
    for (int k=1 ; k<=puissEtincelles +3; k++){
        Etincelle etinc1 = new Etincelle(xf+10*k,yf) ;
        etinc1.couleur = couleur ;
        etinc1.forme = forme ;
        etinc1.duree = duree ;
        etinc1.peindreEtincelle(g);
        Etincelle etinc2 = new Etincelle(xf-10*k,yf) ;
        etinc2.couleur = couleur2 ;
        etinc2.forme = forme ;
        etinc2.duree = duree ;
        etinc2.peindreEtincelle(g);
        Etincelle etinc3 = new Etincelle(xf,yf+10*k) ;
        etinc3.couleur = couleur ;
        etinc3.forme = forme ;
        etinc3.duree = duree ;
        etinc3.peindreEtincelle(g);
        Etincelle etinc4 = new Etincelle(xf,yf-10*k) ;
        etinc4.couleur = couleur2 ;
        etinc4.forme = forme ;
        etinc4.duree = duree ;
        etinc4.peindreEtincelle(g);
        Etincelle etinc5 = new Etincelle(xf+10*k*DIV,yf+10*k*DIV) ;etinc1.couleur = couleur ;
        etinc5.couleur = couleur ;
        etinc5.forme = forme ;
        etinc5.duree = duree ;
        etinc5.peindreEtincelle(g);
        Etincelle etinc6 = new Etincelle(xf+10*k*DIV,yf-10*k*DIV) ;
        etinc6.couleur = couleur2 ;
        etinc6.forme = forme ;
        etinc6.duree = duree ;
        etinc6.peindreEtincelle(g);
        Etincelle etinc7 = new Etincelle(xf-10*k*DIV,yf+10*k*DIV) ;
        etinc7.couleur = couleur2 ;
        etinc7.forme = forme ;
        etinc7.duree = duree ;
        etinc7.peindreEtincelle(g);
        Etincelle etinc8 = new Etincelle(xf-10*k*DIV,yf-10*k*DIV) ;
        etinc8.couleur = couleur2 ;
        etinc8.forme = forme ;
        etinc8.duree = duree ;
        etinc8.peindreEtincelle(g);
}
}


}
EN

回答 1

Stack Overflow用户

发布于 2016-03-17 19:18:50

您的代码不会覆盖boolean action()方法,因为程序只使用初始化TextField时使用的文本工作一次。在main方法之后添加以下代码:

代码语言:javascript
复制
@Override
public boolean action(Event EV, Object obj){
    repaint(); //this statement is missing in your code
    return true;
}

这应该是可行的。我在一个applet中测试了它的错误,我遇到了和你一样的错误。

编辑

由于您的程序没有paint()方法(我应该已经注意到了),并且按钮似乎不起作用,请尝试在您的程序中实现以下代码来处理单击按钮时触发的事件:(考虑将button Animation标记为"Start Animation")

代码语言:javascript
复制
public boolean handleEvent(Event EV){
    if(EV.target instanceof Button){
        if(EV.arg.equals("Start Animation"))
            //do what you want to do when button is clicked
    }
    return super.handleEvent(EV);
}

也许你错过了这一部分或类似的部分。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36043957

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档