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

📄 funpanel.java

📁 本书透彻讲解了经典的《设计模式:可复用面向对象软件的基础》一书涵盖的23种基本设计模式。本书将这些设计模式分成五类:接口型模式、责任型模式、构造型模式、操作型模式
💻 JAVA
字号:
package com.oozinoz.applications;


import java.awt.*;
import javax.swing.*;
import com.oozinoz.function.*;

/*
 * Copyright (c) 2001 Steven J. Metsker.
 * 
 * Steve Metsker makes no representations or warranties about
 * the fitness of this software for any particular purpose, 
 * including the implied warranty of merchantability.
 *
 * Please use this software as you wish with the sole
 * restriction that you may not claim that you wrote it.
 */
/**
 * Plots a curve given parametric functions x and y that
 * are parameterized on time t, where t goes 0 to 1 during
 * the life of the curve.
 * 
 * @author Steven J. Metsker
 */
public class FunPanel extends JPanel 
{



protected void paintComponent(Graphics g)
{
	super.paintComponent(g);
	double h = (double) (getHeight() - 1);
	double w = (double) (getWidth() - 1);
	for (int i = 0; i < nPoint; i++)
	{
		double t = ((double) i) / (nPoint - 1);
		xArray[i] = (int) (w * (fx.f(t) - xMin) / (xMax - xMin));
		yArray[i] =
			(int) (h - h * (fy.f(t) - yMin) / (yMax - yMin));
	}
	g.setColor(Color.black);
	g.drawPolyline(xArray, yArray, nPoint);
}

/**
 * Establish the functions to plot.
 *
 * @param fx the x function
 * @param fy the y function
 */
public void setXY(Function fx, Function fy)
{
	this.fx = fx;
	this.fy = fy;
	calculateExtrema();
	repaint();
}


	protected Function fx = new T();
	protected Function fy = new T();
	protected int nPoint = 101;
	protected int[] xArray = new int[nPoint];
	protected double xMax = 1;
	protected double xMin = 0;
	protected int[] yArray = new int[nPoint];
	protected double yMax = 1;
	protected double yMin = 0;

protected void calculateExtrema()
{
	for (int i = 0; i < nPoint; i++)
	{
		double t = ((double) i) / (nPoint - 1);
		double dx = fx.f(t);
		double dy = fy.f(t);
		if (i == 0 || dx > xMax)
		{
			xMax = dx;
		}
		if (i == 0 || dx < xMin)
		{
			xMin = dx;
		}
		if (i == 0 || dy > yMax)
		{
			yMax = dy;
		}
		if (i == 0 || dy < yMin)
		{
			yMin = dy;
		}
	}
}
}

⌨️ 快捷键说明

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