Frame

简介: Frame

Frame是GUI设计的基本,它是屏幕上window的对象,能够最大化、最小化、关闭,后续的一些标签、按钮和文本字段都需要在frame上体现。

1、基本框架的实现

package 狂神说__AWT;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

//GUI基础界面
//框架
public class TestFrame {
    public static void main(String[] args) {
        Frame frame=new Frame();
        //设置窗口可见性
        frame.setVisible(true);
        //设置窗口大小
        frame.setSize(400,400);
        //设置窗口颜色
        frame.setBackground(new Color(197,100,197));//基础颜色是red、green、blue
        //设置窗口位置
        frame.setLocation(200,200);
        //窗口界面固定
        frame.setResizable(false);
    }

}

2、Frame也支持window界面出现多个窗口

package 狂神说__AWT;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class TestFrame2 {
    public static void main(String[] args) {
        MyFrame myFrame1=new MyFrame(100,100,200,200,Color.blue);
        MyFrame myFrame2=new MyFrame(300,100,200,200,Color.red);
        MyFrame myFrame3=new MyFrame(100,300,200,200,Color.yellow);
        MyFrame myFrame4=new MyFrame(300,300,200,200,Color.magenta);
        myFrame1.addWindowFocusListener(new WindowAdapter() {
            @Override
            public void windowClosed(WindowEvent e) {
                System.exit(0);
            }
        });
    }
}
class MyFrame extends Frame{
    static int count=0;
    public MyFrame(int x,int y,int w,int h,Color color) {
        super("MF"+(++count));
        setBounds(x,y,w,h);
        setBackground(color);
        setVisible(true);
        setResizable(false);
    }

}

相关文章
|
2天前
|
Python 容器
Frame
Frame
21 3
|
9月前
nobuffer与av_read_frame的关系
nobuffer与av_read_frame的关系
40 0
|
9月前
ffmpeg编码报错:more samples than frame size (avcodec_encode_audio2)
ffmpeg编码报错:more samples than frame size (avcodec_encode_audio2)
54 0
ffmpeg编码报错:more samples than frame size (avcodec_encode_audio2)
|
2天前
|
Python
tkinter之frame
tkinter之frame
22 1
|
6月前
刷新frame
刷新frame
|
9月前
|
算法
frame_size (1536) was not respected for a non-last frame
frame_size (1536) was not respected for a non-last frame
62 0
frame_size (1536) was not respected for a non-last frame
|
程序员 iOS开发
frame 和 bounds的区别
frame 和 bounds的区别
105 0
frame 和 bounds的区别
成功解决AttributeError: module 'cv2.cv2' has no attribute 'CV_CAP_PROP_FPS'和 'CV_CAP_PROP_FRAME_WIDTH'
成功解决AttributeError: module 'cv2.cv2' has no attribute 'CV_CAP_PROP_FPS'和 'CV_CAP_PROP_FRAME_WIDTH'
|
iOS开发
深入浅出了解frame和bounds
对bounds和frame的理解
1496 0