JavaSE系列代码45:GridLayout类的使用

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);
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Bol5261

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值