`BorderLayout` 是 `java.awt` 包中的一个类,它是用于布局管理的。它把容器分成5个区域

BorderLayoutjava.awt 包中的一个类,它是用于布局管理的。它把容器分成5个区域:NORTH、SOUTH、EAST、WEST和CENTER,每个区域只能包含一个组件。

以下是一个简单的使用 BorderLayout 的示例:

import java.awt.*;
import javax.swing.*;

public class BorderLayoutDemo {
    public static void main(String[] args) {
        JFrame frame = new JFrame("BorderLayout Demo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 300);

        Container contentPane = frame.getContentPane();
        contentPane.setLayout(new BorderLayout());

        JButton btn1 = new JButton("North");
        JButton btn2 = new JButton("South");
        JButton btn3 = new JButton("East");
        JButton btn4 = new JButton("West");
        JButton btn5 = new JButton("Center");

        contentPane.add(btn1, BorderLayout.NORTH);
        contentPane.add(btn2, BorderLayout.SOUTH);
        contentPane.add(btn3, BorderLayout.EAST);
        contentPane.add(btn4, BorderLayout.WEST);
        contentPane.add(btn5, BorderLayout.CENTER);

        frame.setVisible(true);
    }
}

在这个例子中,我们创建了一个 JFrame,然后设置了其内容面板的布局为 BorderLayout。然后我们添加了5个按钮到不同的区域。最后,我们设置窗口可见。

The abstract class cannot create an object with the new operator, it must produce its subclass, which creates the object. If there is an abstract method in the class body of an abstract class, it can only be declared but not implemented. The subclass of the class must implement the abstract method, that is, override the abstract method of the parent class. An abstract class only cares about whether a subclass has a certain function, not about the specific implementation of the function. The specific implementation is the responsibility of the subclass.

import java.awt.*; 
public class Javase_43 extends Frame
{
  static Frame frm=new Frame("边界式布局管理器BorderLayout");
  public static void main(String[] args)
  {
    BorderLayout border=new BorderLayout (5,10);
    frm.setLayout(border);      //设置页面布局为边界式布局方式
    frm.setSize(280,200);
    frm.add(new Button("上北"), BorderLayout.NORTH);
    frm.add(new Button("下南"), BorderLayout. SOUTH);
    frm.add(new Button("左西"), BorderLayout.WEST);
    frm.add(new Button("右东"), BorderLayout.EAST);
    frm.add(new Button("中央"), BorderLayout.CENTER);
    frm.setVisible(true);
  }
}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Bol5261

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

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

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

打赏作者

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

抵扣说明:

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

余额充值