- JDK :OpenJDK-11
- OS :CentOS 7.6.1810
- IDE :Eclipse 2019‑03
- typesetting :Markdown
package per.jizuiku.gui; import java.awt.Button; import java.awt.FlowLayout; import java.awt.Frame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; /** * @author 給最苦 * @date 2019/06/30 * @blog www.cnblogs.com/jizuiku */ public class Demo { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Frame f = new Frame(); // 設置窗體大小 int width = 300; int height = 400; f.setSize(width, height); // 建立按鈕對象,在按鈕上添加文字 Button b = new Button("I am a button."); b.setSize(10, 30); // 點擊按鈕後 b.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub System.out.println("點擊按鈕"); } }); // 採用了流式佈局 f.setLayout(new FlowLayout()); // 把按鈕添加到窗體上 f.add(b); // 設置窗體可見 f.setVisible(true); } }
點擊按鈕 點擊按鈕 點擊按鈕
/** * Adds the specified action listener to receive action events from * this button. Action events occur when a user presses or releases * the mouse over this button. * If l is null, no exception is thrown and no action is performed. * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" * >AWT Threading Issues</a> for details on AWT's threading model. * * @param l the action listener * @see #removeActionListener * @see #getActionListeners * @see java.awt.event.ActionListener * @since 1.1 */ public synchronized void addActionListener(ActionListener l) { if (l == null) { return; } actionListener = AWTEventMulticaster.add(actionListener, l); newEventsOnly = true; }
感謝幫助過 給最苦 的人們。
Java、Groovy和Scala等基於JVM的語言,優秀,值得學習。
規範的命名和代碼格式等,有助於溝通和理解。
JVM的配置、監控與優化,比較實用,值得學習。html