看板 java 關於我們 聯絡資訊
在一個視窗上放置一個按鈕,按下時背景會2種顏色交換?? import java.awt.*; import java.awt.event.*; import javax.swing.*; public class app23_1_1 extends JFrame implements ActionListener{ static app23_1_1 frm = new app23_1_1(); static Container cp = frm.getContentPane(); static Button btn1 = new Button("button1"); static Button btn2 = new Button("button2"); public static void main(String[] args){ cp.add(btn1); cp.add(btn2); cp.setLayout(new FlowLayout()); cp.setBackground(Color.pink); btn1.addActionListener(frm); frm.setTitle("jframe window"); frm.setSize(200,150); frm.setVisible(true); } public void actionPerformed(ActionEvent e){ for(int i=0; i<1000000000; i++){} cp.setBackground(Color.yellow); for(int i=0; i<1000000000; i++){} cp.setBackground(Color.pink); } } 但結果只會直接顯示粉紅色...中間並不會變黃色?? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.26.131.90
yanshencun:建議你可以用Thread.sleep(500);//休息500ms 09/04 00:52
yanshencun:不過外面要包一層try catch就是了... 09/04 00:56
sbrhsieh:這樣沒有幫助。 09/04 01:31