Java GUI Mad God Talking Series Video Summary (1)

Thanks to the Java crazy god! !


One, the most basic interface: Frame window

Supplement: Frame is a class for the development of graphical interfaces

1. Create a new object to create a Frame window

//这是我自己的包
package GUI;
//导入必要的包
import java.awt.*;
public class TestDemo {
    
    
	
	public static void main(String[] args) {
    
    
		// TODO Auto-generated method stub
		
		//生成一个窗口对象  设置标题
		Frame frame = new Frame("我的第一个Frame窗口");
		
		//设置背景颜色
		frame.setBackground(Color.cyan);
		
		//设置位置 相对于你电脑的左上角来说
		frame.setLocation(500, 500);
		
		//设置大小 图形界面大小
		frame.setSize(600, 600);
		
		//设置可见性  不设置为true的看不见的哦
		frame.setVisible(true);
		
		//设置大小固定 设置为false之后,就不能再对其进行大小的更改了,之前是可以进行拉动来放大或缩小的
		frame.setResizable(false);
	}
}
//这样的一个最基本的窗口就做成了,但是他暂时是关闭不掉的,需要有监听事件(之后详细叙述)

Insert picture description here

2. Directly inherit the Frame class to create the Frame window

//这是我自己的包
package GUI;
//导入必要的包
import java.awt.*;
public class TestDemo extends Frame {
    
    
			
			//构造器
			public TestDemo(String title){
    
    
				
			//设置标题
			setTitle(title);
			
			//设置背景颜色
			setBackground(Color.cyan);
			
			//设置位置 和大小 可以用这个代替上面的两个方法
			setBounds(500, 500,400,400);
			
			//设置可见性  不设置为true的看不见的哦
			setVisible(true);
			
			//设置大小固定 设置为false之后,就不能再对其进行大小的更改了,之前是可以进行拉动来放大或缩小的
			setResizable(false);
			}
	public static void main(String[] args) {
    
    

		//新建一个TestDemo对象,这个是继承了Frame的
		new TestDemo("我的第一个Frame窗口");
	}
}
//这样的一个最基本的窗口就做成了,但是他暂时是关闭不掉的,需要有监听事件(之后详细叙述)

It’s the same as the previous picture, but I reduced it

Two, you can create multiple windows

The code is as follows (example):

//这是我自己的包
package GUI;
//导入必要的包
import java.awt.*;
public class TestDemo extends Frame {
    
    

			//构造器
			public TestDemo(String title,int x,int y,int width,int height,Color color){
    
    

			
			//设置标题
			setTitle(title);
			
			//设置背景颜色
			setBackground(color);
			
			//设置位置 和大小
			setBounds(x, y,width,height);
			
			//设置可见性  不设置为true的看不见的哦
			setVisible(true);
			
			//设置大小固定 设置为false之后,就不能再对其进行大小的更改了,之前是可以进行拉动来放大或缩小的
			setResizable(false);
			}
	public static void main(String[] args) {
    
    
		//新建四个TestDemo对象,这个是继承了Frame的
		new TestDemo("1",100,100,200,200,Color.cyan);
		new TestDemo("2",300,100,200,200,Color.red);
		new TestDemo("3",100,300,200,200,Color.yellow);
		new TestDemo("4",300,300,200,200,Color.green);
	}
}

Insert picture description here

to sum up

This is the basic operation of creating a window! The above is the content of this blog, thanks for watching! ! ! ! !

Guess you like

Origin blog.csdn.net/qq_45911278/article/details/111506718