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

📄 mydraw.java

📁 能够运用java完成画图程序
💻 JAVA
字号:
import java.awt.*;
import java.awt.Graphics;
import java.awt.event.*;


class DrawList extends Frame implements ActionListener
{
	MyShape[] shape;
	int flage;
	int f;

	Button line;
	Button rect;
	Button oval;
	Button draw;
	Button drawAll;
/*	
	Button inputNumber;
	Button line2;
	Button rect2;

	
	Label label1;
	Label label2;
	Label label3;
	Label label4;
	TextField textX1;
	TextField textY1;
	TextField textX2;
	TextField textY2;
*/	
	DrawList()
	{
	super("ͼ");	
	shape=new MyShape[10];	
	flage=-1;
	f=0;

	
/*	
	label1=new Label("X1");
	label2=new Label("Y1");
	label3=new Label("X2");
	label4=new Label("Y2");
	textX1=new TextField("",18);
	textY1=new TextField("",18);
	textX2=new TextField("",18);
	textY2=new TextField("",18);
	
	inputNumber=new Button("input oval");
	inputNumber.addActionListener(this);
	
*/	
	
	line=new Button("     line     ");
	line.addActionListener(this);
	rect=new Button("     rect     ");
	rect.addActionListener(this);
	oval=new Button("     oval     ");
	oval.addActionListener(this);
	draw=new Button("     draw     ");
	draw.addActionListener(this);
	drawAll=new Button("     drawAll     ");
	drawAll.addActionListener(this);
	
	setLayout(new FlowLayout());
	setBounds(200,200,400,500);
	add(line);
	add(rect);
	add(oval);
	add(draw);
	add(drawAll);
/*	
	
	add(label1);
	add(textX1);
	add(label2);
	add(textY1);
	add(label3);
	add(textX2);
	add(label4);
	add(textY2);
/*	
	add(inputNumber);
*/
	
	setVisible(true);
	
	
	}
	
	public void paint(Graphics g)
	{
		int i=0;
		if(flage>=0)
		shape[flage].draw(g);
		if(f==1)
		{
		for(i=0;i<=flage-1;i++)
			{shape[i].draw(g);}
			return;	
		}
		
	}
	
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==line)
		{
		flage++;
		shape[flage]=new MyLine();
		
		}
		
		if(e.getSource()==rect)
		{
		flage++;
		shape[flage]=new MyRect();
		
		}
		
		if(e.getSource()==oval)
		{
		flage++;
		shape[flage]=new MyOval();	
		
		}
		if(e.getSource()==draw)
		{
		repaint();
		}
		if(e.getSource()==drawAll)
		{
			f=1;
			repaint();
		}
		
/*		if(e.getSource()==inputNumber)
		{
			
		}
*/
	}
	
	
	
}


public class MyDraw
{
	public static void main(String[] agrs)
	{
		new DrawList();
	}
}

⌨️ 快捷键说明

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