标签:form imp osi ram ada log 适配 ast add
85事件处理
import java.awt.Button; import java.awt.Frame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; class A implements ActionListener { public void actionPerformed(ActionEvent e) { System.out.println("hello"); } } public class Test { public static void main(String[] args) { Frame f = new Frame("haha"); Button bn = new Button("ok"); f.add(bn); A aa = new A(); bn.addActionListener(aa); f.pack(); f.setVisible(true); // 适配器,设置窗体可以关闭 f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } }
87十个按钮的设计
import java.awt.BorderLayout; import java.awt.Button; import java.awt.Frame; import java.awt.GridLayout; import java.awt.Panel; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class Test { public static void main(String[] args) { Frame f = new Frame(); f.setSize(300, 300); f.setLayout(new GridLayout(2, 1));// 2行1列 Panel p1 = new Panel(); p1.setLayout(new BorderLayout()); Panel p1_1 = new Panel(); p1_1.setLayout(new GridLayout(2, 1));// 2行1列 Button bn1 = new Button("BUTTON1"); Button bn2 = new Button("BUTTON2"); Button bn3 = new Button("BUTTON3"); Button bn4 = new Button("BUTTON4"); p1.add(bn1, BorderLayout.WEST); p1_1.add(bn3); p1_1.add(bn4); p1.add(p1_1, BorderLayout.CENTER); p1.add(bn2, BorderLayout.EAST); Panel p2 = new Panel(); p2.setLayout(new BorderLayout()); Panel p2_1 = new Panel(); p2_1.setLayout(new GridLayout(2, 2));// 2行2列 Button bn5 = new Button("BUTTON5"); Button bn6 = new Button("BUTTON6"); Button bn7 = new Button("BUTTON7"); Button bn8 = new Button("BUTTON8"); Button bn9 = new Button("BUTTON9"); Button bn10 = new Button("BUTTON10"); p2.add(bn5, BorderLayout.WEST); p2_1.add(bn7); p2_1.add(bn8); p2_1.add(bn9); p2_1.add(bn10); p2.add(p2_1, BorderLayout.CENTER); p2.add(bn6, BorderLayout.EAST); f.add(p1); f.add(p2); f.pack(); f.setVisible(true); // 适配器,设置窗体可以关闭 f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } }
1515
标签:form imp osi ram ada log 适配 ast add
原文地址:http://www.cnblogs.com/denggelin/p/6363700.html