Java 7 教學手冊 第五版 作者:洪維恩著 旗標 書號:F2733

setBackground(Random_Color);

Chapter18 事件處理

ch18.7z

Button

app18_1.java (Button + no action)

app18_2.java (Button + frm actionPerformed)

app18_4.java (which button is pressed, Button btn = (Button) e.getSource())

CheckBox => ItemEvent

app18_5.java (itemStateChanged)

TextArea =>TextEvent

app18_6.java (textValueChanged)

Combination: TextListener,ActionListener,ItemListener)

key

app18_7.java (keyPressed, keyReleased, keyTyped)

(int keyCode = e.getKeyCode();)
(char keyChar = e.getKeyChar();)

Mouse

app18_9.java (mouseEntered, MouseClicked, mousePressed, mouseReleased)

app18_10.java (MouseMotion)

Window

app18_12.java (windowActivated)

 


int R = (int )(Math.random() * 255 + 1);
int G = (int )(Math.random() * 255 + 1);
int B = (int )(Math.random() * 255 + 1);
Color Random_Color = new Color(R, G, B);
setBackground(Random_Color);