Charles Bell
Posts: 519
Nickname: charles
Registered: Feb, 2002
|
|
Re: scaling problem.....!??!!!!
|
Posted: Oct 26, 2002 9:29 AM
|
|
/** CosineWaveGrapher.java * @author Charles Bell * @version Oct 26, 2002 */
import java.awt.*; import javax.swing.*;
public class CosineWaveGrapher extends JFrame{ public CosineWaveGrapher(){ super("CosineWaveGrapher"); init(); } public static void main(String[] args){ CosineWaveGrapher grapher = new CosineWaveGrapher(); } public void init(){ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().add(new GrapherPanel(), BorderLayout.CENTER); pack(); setLocationRelativeTo(null); show(); } class GrapherPanel extends JPanel{ public GrapherPanel(){ super(); setPreferredSize(new Dimension(620,420)); } public void paint(Graphics g){ super.paintComponent(g); g.setColor(Color.black); g.translate(310, 210); g.drawLine(-300, 200, 300, 200); //across top g.drawLine(-300, 0, 300, 0); //across middle g.drawLine(-300,-200, 300, -200); //across bottom g.drawLine(-300, -200, -300, 200); //down left side g.drawLine(-150, -200, -150, 200); //down left side g.drawLine(0, -200, 0, 200); //down middle g.drawLine(150, -200, 150, 200); //down right side g.drawLine(300, -200, 300, 200); //down right side char piChar = '\u03c0'; g.drawString("-2" + piChar, -290, -10); g.drawString("-" + piChar , -140, -10); g.drawString("0" , 10, -10); g.drawString("+" +piChar, 160, -10); g.drawString("+2" +piChar, 270, -10); g.drawString("+1" , 10, -185); g.drawString("-1" , 10, 195); int x0 = -300; int y0 = 0; int x1 = -300; int y1 = 0; double pi = Math.PI; for (double theta = -2 * pi; theta <= 2 * pi; theta=theta + pi/500){ x1 = (int) ((theta*300)/(2 * pi)); y1 = -(int)(200 * Math.cos(theta)); g.drawLine(x0,y0,x1,y1); //System.out.println("x1: " + x1 + " y1: " + y1); x0 = x1; y0 = y1; } } } }
|
|