⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drawshape.java

📁 用java语言实现的简单的绘图
💻 JAVA
字号:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class DrawShape 
{
	public static void main(String[] args)
	{
		new Frame1();
	}
}

class Rect
{
	private int x, y, width, height;

	Rect()
	{
		x = 50;
		y = 100;
		width = 100;
		height = 100;
	}

	void setPos(int posX, int posY)
	{
		x = posX;
		y = posY;
	}
	void setSize(int w, int h)
	{
		width = w;
		height = h;
	}

	void draw(Graphics g)
	{
		g.drawRect(x, y, width, height);
	}
};

class Frame1 extends Frame implements ActionListener
{
	Rect rect = new Rect();
	Button b = new Button("Rect");

	Frame1()
	{
		super("Draw a rectangle");
		setLayout(new FlowLayout());
		b.addActionListener(this);
		add(b);
		setSize(300, 400);
		show();
	}

	public void paint(Graphics g)
	{
		rect.draw(g);
	}

	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource() == b)
			repaint();
		else
			System.exit(0);
	}
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -