2011-06-26 15 views
0

誰でもこの問題を解決する方法を教えてください。Javaの簡単な問題

public class Kuular implements ActionListener { 

    ImageIcon f1 = new ImageIcon("C:\\Users\\Student\\Desktop\\pic1.jpg"); 
    ImageIcon f2 = new ImageIcon("C:\\Users\\Student\\Desktop\\pic2.jpg"); 
    ImageIcon f3 = new ImageIcon("C:\\Users\\Student\\Desktop\\pic3.jpg"); 
    ImageIcon f4 = new ImageIcon("C:\\Users\\Student\\Desktop\\pic4.jpg"); 

    List<ImageIcon> list1 = Arrays.asList(f1, f2, f3, f4); 
    List<ImageIcon> list2 = new ArrayList<ImageIcon>(); 

    public void fs() { 
     Collections.shuffle(list1); 
    } 

    Kuular k = new Kuular(); 
    k.fs();; // HERE 

メソッドfsをどのように呼び出すことができますか? ありがとう!

答えて

3

main()方法を追加して、クラスをJavaで

public class Kuular implements ActionListener { 

    ImageIcon f1 = new ImageIcon("C:\\Users\\Student\\Desktop\\pic1.jpg"); 
    ImageIcon f2 = new ImageIcon("C:\\Users\\Student\\Desktop\\pic2.jpg"); 
    ImageIcon f3 = new ImageIcon("C:\\Users\\Student\\Desktop\\pic3.jpg"); 
    ImageIcon f4 = new ImageIcon("C:\\Users\\Student\\Desktop\\pic4.jpg"); 

    List<ImageIcon> list1 = Arrays.asList(f1, f2, f3, f4); 
    List<ImageIcon> list2 = new ArrayList<ImageIcon>(); 

    public void fs() { 
     Collections.shuffle(list1); 
    } 

    public static void main(String[] args) { 
     Kuular k = new Kuular(); 
     k.fs(); 
    } 
} 
0

を実行する、専用フィールドの初期化は、メソッドの外で発生することができます。他のすべての命令はメソッド内に含まれていなければならず、メソッドはクラス内になければなりません。

よろしくお願いします。 ステファン