import java.awt.*; import java.awt.Event; class Gui{ //1)创建组件引用 Frame fr; Label lb1,lb2,lb3; TextField tx1,tx2,tx3; Button b1,b2,b3,b4,b5; Panel p1,p2; Gui(){ init(); } //2)创建组件 void init(){ fr = new Frame("Calculator"); fr.setBounds(200,200,300,200); p1 = new Panel(new GridLayout(3,2,2,3)); p1.setBackground(Color.yellow); lb1 = new Label("Value 1"); lb2 = new Label("Value 2"); lb3 = new Label("Result"); tx1 = new TextField(15); tx2 = new TextField(15); tx3 = new TextField(15); tx3.setEditable(false); fr.add(p1); p1.add(lb1);p1.add(tx1); p1.add(lb2);p1.add(tx2); p1.add(lb3);p1.add(tx3); p2 = new Panel(); b1 = new Button("+"); b2 = new Button("-"); b3 = new Button("*"); b4 = new Button("/"); b5 = new Button("C"); fr.add(p2,BorderLayout.SOUTH); p2.setBackground(new Color(128,0,128)); p2.add(b1);p2.add(b2); p2.add(b3);p2.add(b4); p2.add(b5); myEvent(); fr.setVisible(true); } void myEvent(){ } } public class SimCalculator { public static void main(String[] args) { new Gui(); } }
Java图形化配置
最新推荐文章于 2018-10-19 22:27:08 发布