依處理器所掛的位置,總共有5種寫法,以計時器處理器為例, A.處理器掛在外部類別下:import javax.swing.Timer; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class TimerTest1 { public static void main(String args[]) throws Exception { ActionListener al = new TimerHandler(); Timer t = new Timer(1000,al); t.start(); Thread.sleep(10000); t.stop(); } } class TimerHandler implements ActionListener { public void actionPerformed(ActionEvent ae) { System.out.println("執行每次叫醒要作的事1"); } }B.處理器掛在內部匿名類別下:import javax.swing.Timer; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class TimerTest2 { public static void main(String args[]) throws Exception { ActionListener al = new ActionListener() { public void actionPerformed(ActionEvent ae) { System.out.println("執行每次叫醒要作的事2"); } }; Timer t = new Timer(1000,al); t.start(); Thread.sleep(10000); t.stop(); } }C.處理器掛在內部有名類別下:import javax.swing.Timer; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class TimerTest3 { public static void main(String args[]) throws Exception { new TimerTest3(); } TimerTest3() throws Exception { ActionListener al = new TimerHandler(); Timer t = new Timer(1000,al); t.start(); Thread.sleep(10000); t.stop(); } private class TimerHandler implements ActionListener { public void actionPerformed(ActionEvent ae) { System.out.println("執行每次叫醒要作的事3"); } } }D.處理器掛在本身類別下:import javax.swing.Timer; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class TimerTest4 implements ActionListener { public void actionPerformed(ActionEvent ae) { System.out.println("執行每次叫醒要作的事4"); } public static void main(String args[]) throws Exception { ActionListener al = new TimerTest4(); Timer t = new Timer(1000,al); t.start(); Thread.sleep(10000); t.stop(); } }E.處理器同時掛在內部和外部類別下:import javax.swing.Timer; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class TimerTest5 { public static void main(String args[]) throws Exception { ActionListener al = new ActionAdapter() { public void actionPerformed(ActionEvent ae) { System.out.println("執行每次叫醒要作的事5x"); } }; Timer t = new Timer(1000,al); t.start(); Thread.sleep(10000); t.stop(); } } class ActionAdapter implements ActionListener { public void actionPerformed(ActionEvent ae) { System.out.println("執行每次叫醒要作的事5"); } }
5 kinds of event handler styles
訂閱:
張貼留言 (Atom)
how to deal with metric scale inconsistency in topn recommendation evaluation
🎯 推薦系統一般會回傳前 N 個排名的物品清單給用戶,稱為 Top‑N 推薦。 遇到推薦模型須要訓練及評估時,習慣先蒐集用戶與物品的互動資料,再將資料拆分成沒有重疊的訓練集及測試集。 模型在訓練時只看得到訓練集,評估時則拿測試集作為驗證的標準答案,以免作...
沒有留言:
張貼留言