总结:方法,main函数的作用你还没搞清楚

//画一个矩形
import java.awt.*;

import javax.swing.*;

public class Test2 extends JFrame {
	public void paint(Graphics g) {
		this.setVisible(true);
		g.setColor(Color.red);// 将画笔放在图形前面,否则会默认为黑色,那么颜色设置无效
		g.drawOval(200, 100, 40, 40);// 圆
		g.fillOval(100, 100, 50, 100);// 椭圆,半径不同
		g.drawRect(100, 300, 390, 100);// 矩形
		this.setBounds(100, 200, 500, 500);
		this.setDefaultCloseOperation(3);
	}

	public static void main(String[] args) {

		new Test2().setVisible(true);// 你妹你发现没,这里如果不调用setVisible方法,窗口显示不出来啊

	}
}

  

相关文章:

  • 2022-12-23
  • 2022-01-10
  • 2022-12-23
  • 2021-06-26
  • 2021-12-18
  • 2021-04-02
  • 2021-09-12
  • 2021-08-05
猜你喜欢
  • 2022-12-23
  • 2021-11-15
  • 2022-12-23
  • 2021-07-05
  • 2022-12-23
  • 2023-03-15
相关资源
相似解决方案