我正在爲我的第一個java項目做一個簡單的應用程序。 它結合了各種字符串來產生輸出。例如 - 名稱。獲得一個按鈕來重複一個動作
但是我碰到了一個障礙,我把所有的GUI都佈置好了,我所有的字符串都組成了,他們都做了一個隨機的結果,並在告訴時把它寫到文本標籤上,但是如果我點擊按鈕再次 - 納達。沒有。
我的問題是這樣的 - 我如何做一個按鈕重複我正在做的過程?沒有人能夠向我解釋這一點。我不是在尋找一個快速解決方案,而是尋找一個'如何',因爲我想學習。 :)
這裏是我的代碼的簡化版本:
public static String[] name1 = {
"a", "b", "c", "d", "e", "f", "g", "h", "i",
"j", "k", "l", "n", "o", "p", "q", "r", "s",
"t", "u", "v", "w", "x", "y", "z"
};
public static String[] name2 = {
"oh noes", "its not working","sad face"
};
public static int name1length = name1.length;
public static int name2length = name2.length;
public static int rand1 = (int) (Math.random() * name1length);
public static int rand2 = (int) (Math.random() * name2length);
public static String phrase = name1[rand1] + " " + name2[rand2];
你能否把你的代碼放在「代碼中」樣本「,以便更容易閱讀 – brent777 2011-03-29 10:59:17
我做過,但它不能格式化它。 謝謝你修復它。 :) – 2011-03-29 11:05:49