package com.company;

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

public class Main extends JFrame {
    public Main(){
        setBounds(100,100,200,150);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        Container c=getContentPane();
        c.setLayout(null);//将容器的布局设为绝对布局
        JButton b1=new JButton("按钮1"),b2=new JButton("按钮2");//创建两个按钮
        b1.setBounds(10,30,80,30);//设置按钮在容器中的坐标和大小
        b2.setBounds(60,70,100,20);
        c.add(b1);
        c.add(b2);
        setVisible(true);
    }

    public static void main(String[] args) {
        new Main();
    // write your code here
    }
}

绝对布局,setLayout(null)绝对布局,setLayout(null)

 

相关文章:

  • 2021-09-08
  • 2021-09-08
  • 2021-09-14
  • 2021-09-25
  • 2021-11-30
  • 2021-10-01
  • 2021-08-16
  • 2021-12-10
猜你喜欢
  • 2021-09-22
  • 2021-08-02
  • 2021-09-17
  • 2021-09-08
  • 2021-09-08
  • 2021-09-08
  • 2021-09-08
  • 2021-11-21
相关资源
相似解决方案