-4

私はテストのためにいくつかの作業を行っていますが、スリープが機能しないと感じました。コンボボックス 100ms 300ms 500ms 1000ms から選択する必要があります。前もって感謝します。ここに私のコードがあります:

package vjezbanje;

import java.util.Random;

import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Move extends Thread {

    JComboBox cb = new JComboBox();
    JLabel lb = new JLabel();
    JPanel pl = new JPanel();
    ImageIcon ic;
    private String[] brzine = {"100ms","300ms","500ms","1000ms"};   

    public JComboBox getCb() {
        return cb;
    }

    public void setCb(JComboBox cb) {
        this.cb = cb;
    }

    public JLabel getLb() {
        return lb;
    }

    public void setLb(JLabel lb) {
        this.lb = lb;
    }

    public JPanel getPl() {
        return pl;
    }

    public void setPl(JPanel pl) {
        this.pl = pl;
    }

    public Move() {                     
    }

    public void run() {

        pl.add(lb);
        cb = new JComboBox(brzine);

        for(int t=0; t<10; t++) {
        if(cb.getSelectedItem().equals("100ms")) {
            try {

                Random r = new Random ();
                int s = r.nextInt(6)+1;
                // 0 1 2 3 4 5
                lb.setIcon(new ImageIcon("slike\\"+s+".jpg"));
                Thread.sleep(100);
            } catch (InterruptedException e) {  
                e.printStackTrace();
            }
        }                   

        if(cb.getSelectedItem().equals("300ms")) {
            try {

                Random r = new Random ();
                int s = r.nextInt(6)+1;
                // 0 1 2 3 4 5
                lb.setIcon(new ImageIcon("slike\\"+s+".jpg"));
                Thread.sleep(300);
            } catch (InterruptedException e) {  
                e.printStackTrace();
            }   
        }       

        if(cb.getSelectedItem().equals("500ms")) {
            try {

                Random r = new Random ();
                int s = r.nextInt(6)+1;
                // 0 1 2 3 4 5
                lb.setIcon(new ImageIcon("slike\\"+s+".jpg"));
                Thread.sleep(500);          
            } catch (InterruptedException e) {  
                e.printStackTrace();
            }   
        }


        if(cb.getSelectedItem().toString().equals("1000ms")) {
            try {

                Random r = new Random ();
                int s = r.nextInt(6)+1;
                // 0 1 2 3 4 5
                lb.setIcon(new ImageIcon("slike\\"+s+".jpg"));
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }   
        }               
    }               
}   
4

1 に答える 1