Está en la página 1de 2

/* * To change this template, choose Tools | Templates * and open the template in the editor.

*/ package funciones; /** * * @author JulioC unad Tunja */ import import import import java.applet.*; java.net.*; java.awt.*; java.math.*;

public class Coseno extends Applet { Button btnGraficar; TextField txtNum1,txtNum2; int num1,num2; @Override public void init(){ setLayout(null); btnGraficar = new Button("Graficar"); txtNum1 = new TextField(""); txtNum2 = new TextField(""); txtNum1.reshape(10,10,90,20); txtNum2.reshape(110,10,90,20); btnGraficar.reshape(310,10,60,20); add(txtNum1); add(txtNum2); add(btnGraficar); show(); } @Override public void paint (Graphics p) { p.drawString ("Funcion Coseno para el colaborativo 2 de C.Grafic a", 130, 80); hacerGrafica(); } public void hacerGrafica(){ Graphics p = getGraphics(); double punto,y; p.setColor(new Color(255,255,255)); p.fillRect(51,100,299,200);//Fondo para que borre a las anterior es p.setColor(new Color(0,0,0)); p.drawLine(50,300,300,300); //eje horizontal p.drawLine(150,100,150,350); //eje vertical

p.setColor(new Color(255,0,0)); for(double x=num1;x < num2;x+=0.01){ punto = 150 + x*30; y = 300 - Math.cos(x)*30; p.drawLine((int)punto,(int)y,(int)punto + 1,(int)y + 1); } } public boolean getDatos(){ boolean temp = true; try { num1 = Integer.parseInt(txtNum1.getText()); num2 = Integer.parseInt(txtNum2.getText()); } catch(Exception exc) { System.out.println("Error :)" + exc); temp = false; } return temp; } @Override public boolean action(Event e, Object o){ if (e.target == btnGraficar){ if(getDatos()) hacerGrafica(); } return true; } }

También podría gustarte