If a class implements an interface, then the class must implement all methods of the interface, that is, provide method bodies for these methods. It should be noted that the methods in the interface are public and abstract by default. When declaring a method, the public and abstract keywords before the method can be omitted. However, when implementing an interface method, the class must use public to decorate it. The interface methods and constants in the interface implemented by the class can be called by the object of the class.
import java.awt.*;
public class Javase_45 extends Frame
{
static Panel pan=new Panel(); //创建一个面板对象pan
static Label lab=new Label("0. ",Label.RIGHT); //创建标签lab,文字右对齐
static Button b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,bp,ba,bs,bm,bd,be;
public static void main(String[] args)
{
app12_11 frm=new app12_11();
b0=new Button("0"); b1=new Button("1"); b2=new Button("2");
b3=new Button("3"); b4=new Button("4"); b5=new Button("5");
b6=new Button("6"); b7=new Button("7"); b8=new Button("8");
b9=new Button("9"); bp=new Button("."); ba=new Button("+");
bs=new Button("-"); bm=new Button("*"); bd=new Button("/");
be=new Button("=");
frm.setTitle("网格式布局管理器GridLayout");
frm.setLayout(null); //取消窗口的页面设置
frm.setSize(260,200);
frm.setResizable(false); //设置窗口的大小为不可改变
GridLayout grid=new GridLayout (4,4); //创建4行4列的页面配置
pan.setLayout(grid); //将面板对象pan的布局策略设为网格布局方式
pan.setBounds(20,60,150,120);
lab.setBounds(20,35,150,20);
lab.setBackground(Color.cyan); //设置标签的颜色
pan.add(b7); pan.add(b8); pan.add(b9); pan.add(bd);
pan.add(b4); pan.add(b5); pan.add(b6); pan.add(bm);
pan.add(b1); pan.add(b2); pan.add(b3); pan.add(bs);
pan.add(b0); pan.add(bp); pan.add(be); pan.add(ba);
frm.add(lab);
frm.add(pan);
frm.setVisible(true);
}
}