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

📄 ecurve.java

📁 二次曲线绘制:启动之后开始绘制二次曲线和小人
💻 JAVA
字号:
import java.awt.*;
import java.awt.geom.*;
import java.applet.*;
import java.awt.event.*;
public class eCurve extends Applet implements ItemListener{
	int a, b, c;
	int x1, y1;
	int wide;
	int offx = 200;
	int offy = 120;
	String des[] ={ "绿色", "红色", "蓝色", "黄色", "青色" };
	Color s[] ={ Color.green, Color.red, Color.blue, Color.yellow, Color.cyan };
	Color drawColor = Color.pink;
	Image img;
	int q= x1 - 10;
	int k = 0;
	public void init()
	{
		a = Integer.parseInt(getParameter("va"));
		b = Integer.parseInt(getParameter("vb"));
		c = Integer.parseInt(getParameter("vc"));
		wide = Integer.parseInt(getParameter("vd"));
		x1 = -b / (2 * a);
		y1 = (4 * a * c - b * b) / (4 * a);
		CheckboxGroup style = new CheckboxGroup();
		for (int i = 0; i < des.length; i++)
		{
			Checkbox one = new Checkbox(des[i], false, style);
			one.addItemListener(this);
			add(one);
		}
		img = createImage(10, 10);
		Graphics gimg = img.getGraphics();
		gimg.drawOval(3, 0, 4, 4);
		gimg.drawLine(5, 4, 5, 8);
		gimg.drawLine(5, 4, 3, 6);
		gimg.drawLine(5, 4, 7, 6);
		gimg.drawLine(5, 6, 3, 8);
		gimg.drawLine(5, 6, 7, 8);
	}
	public void paint(Graphics g)
	{
		int w = a * q* q + b * q + c;
		Graphics2D g2d = (Graphics2D)g;
		g2d.setStroke(new BasicStroke(2));
		g2d.setPaint(Color.black);
		g2d.draw(new Line2D.Float(offx, offy - 60, offx, offy + 60));
		g2d.draw(new Line2D.Float(offx - 5, offy - 57, offx, offy - 60));
		g2d.draw(new Line2D.Float(offx + 5, offy - 57, offx, offy - 60));
		g2d.draw(new Line2D.Float(offx - 100, offy, offx + 100, offy));
		g2d.draw(new Line2D.Float(offx + 95, offy - 3, offx + 100, offy));
		g2d.draw(new Line2D.Float(offx + 95, offy + 3, offx + 100, offy));
		g2d.draw(new Line2D.Float(offx + x1, offy + y1 - 60, offx + x1, offy + y1 + 60));
		g2d.drawString("x", offx + 105, offy);
		g2d.drawString("y", offx, offy - 65);
		g2d.drawString(" " + 0, offx - 10, offy + 10);
		GeneralPath polly = new GeneralPath();
		polly.moveTo(offx + x1 - 10, offy - (a * (x1 - 10) * (x1 - 10) + b * (x1 - 10) + c));
		for (int i = x1 - 10, j = 0; j <= 20; i++, j++)
		{
			float x = i;
			float y = (float)(a * x * x + b * x + c);
			polly.lineTo(offx + x, offy - y);
		}
		g2d.setPaint(drawColor);
		g2d.setStroke(new BasicStroke(wide));
		g2d.draw(polly);
		g.drawImage(img, offx + q - 5, offy - w - 5, this);
		q++;
		k++;
		try{
		Thread.sleep(100);
		}catch (InterruptedException e) { }
		repaint();
	        if (k % 24 == 0) q = x1 - 10;
	}
	public void update(Graphics g)
	{
		g.setColor(Color.white);
		g.fillRect(0, 0, getWidth(), getHeight());
		paint(g);
	}
	public void itemStateChanged(ItemEvent e)
	{
		Checkbox temp = (Checkbox)e.getItemSelectable();
		for (int i = 0; i < des.length; i++)
		{
			if (temp.getLabel() == des[i])
			{drawColor = s[i];
			 repaint();
			 break;
			}
		}
	}
}

  

⌨️ 快捷键说明

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