JAVA 显示(GUI)

窗口显示

多个窗口显示 (封装)

package GUIstudy;

import java.awt.Color;
import java.awt.Frame;

public class TestFrame2{
       public static void main(String[] arg) {
    	   MyFrame myframe1 = new MyFrame(100,100,100,100,Color.black);
    	   MyFrame myframe2 = new MyFrame(200,100,100,100,Color.red);
    	   MyFrame myframe3 = new MyFrame(100,200,100,100,Color.yellow);
    	   MyFrame myframe4 = new MyFrame(200,200,100,100,Color.black);
       }
}
class MyFrame extends Frame{
	static int id = 0;
	
	
	public MyFrame(int x,int y,int w,int h,Color color){
		super("MyFrame+"+(id++));
		setBackground(color);
		setBounds(x,y,w,h);
		setVisible(true);
	}
	
}

单个窗口显示

package GUIstudy;
import java.awt.*;

public class TestFrame {
       public static void main(String[] arg) {
    	   Frame frame = new Frame("第一个GUI图形界面"); 
    	   //设置窗口可见
    	   frame.setVisible(true);
    	   //设置窗口大小
    	   frame.setSize( 400,400);
    	   //设置背景颜色
    	   frame.setBackground(Color.red);
    	   //弹出初始位置
    	   frame.setLocation(500,300);
    	   //设置大小固定
    	   frame.setResizable(false);
       }
}

面板

 布局

流式布局:

package GUIstudy;

import java.awt.*;

public class TestFlowLayout {
       public static void main(String[] arg) {
    	   Frame frame = new Frame();
    	   //组件按钮
    	   Button button1 = new Button("11111");
    	   Button button2 = new Button("22222");
    	   Button button3 = new Button("33333");
    	   //设置为流式布局
    	   frame.setLayout(new FlowLayout());
    	   
    	   frame.setSize(200,200);
    	   //把按钮添加上去
    	   frame.add(button1);
    	   frame.add(button2);
    	   frame.add(button3);
    	   
    	   frame.setVisible(true);
       }
}

东南西北中

 表格布局

 6、课堂练习讲解及总结_哔哩哔哩_bilibili练习

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值