Citar
package graficadorclasico;
import java.applet.Applet;
import java.awt.*;
import java.awt.Graphics;
import java.io.*;
public class Main extends Applet
{
public static BufferedReader leer=new BufferedReader(new InputStreamReader(System.in));
int x0,y0, xn, yn;
int ancho,alto;
int esX, esY;
double max,min;
Font ft7=new Font("French Script MT",Font.ROMAN_BASELINE,15);//////NUmeros tamano
public void init()
{
this.setSize(800,700);
ancho = getSize().width-10;
alto=100*getSize().height/100;
x0=ancho/2;
y0=alto/2;
esX=20;
esY=20;
setBackground(Color.BLUE);
}
public void paint(Graphics g)
{
super.paint(g);
Graficar(g,x0,y0);
}
void Graficar (Graphics os, int xo, int yo )
{
int i=0,castmin,castmax,ycastmin,ycastmax ;
Graphics2D g=(Graphics2D)os;
//xo toma el valor de x0=400, yo toma el valor de y0=300
g.setColor(Color.GREEN);
g.drawLine(xo,0,xo,alto);
g.drawLine(10,yo,ancho-10,yo);
min=-1.0*xo/esX;
max=(1.0*(ancho-xo)/esX);
castmin=(int)Math.round(min);
castmax=(int)Math.round(max);
ycastmin=(int)Math.round(1.0*(yo-alto)/esY);
ycastmax=(int)Math.round(1.0*yo/esY);
g.setColor(Color.LIGHT_GRAY);
g.setFont(ft7);
int numpixel=ancho;
if(esX>5)
{
for(i=castmin+1;i<castmax;i++)
{
g.drawLine(xo+i*esX,yo-2,xo+i*esX,yo+2);
if(i>0)
g.drawString(""+i,xo+i*esX-2,yo+12);
if(i<0)
g.drawString(""+i,xo+i*esX-6,yo+12);
}
}
if (esY>5)
{
for(i=castmin+1;i<castmax;i++)
{
g.drawLine(xo-2,yo-i*esY,xo+2,yo-i*esY);
if(i>0)
g.drawString(""+i,xo-12,yo-i*esY+3);
if(i<0)
g.drawString(""+i,xo-14,yo-i*esY+3);
}
}}}
import java.applet.Applet;
import java.awt.*;
import java.awt.Graphics;
import java.io.*;
public class Main extends Applet
{
public static BufferedReader leer=new BufferedReader(new InputStreamReader(System.in));
int x0,y0, xn, yn;
int ancho,alto;
int esX, esY;
double max,min;
Font ft7=new Font("French Script MT",Font.ROMAN_BASELINE,15);//////NUmeros tamano
public void init()
{
this.setSize(800,700);
ancho = getSize().width-10;
alto=100*getSize().height/100;
x0=ancho/2;
y0=alto/2;
esX=20;
esY=20;
setBackground(Color.BLUE);
}
public void paint(Graphics g)
{
super.paint(g);
Graficar(g,x0,y0);
}
void Graficar (Graphics os, int xo, int yo )
{
int i=0,castmin,castmax,ycastmin,ycastmax ;
Graphics2D g=(Graphics2D)os;
//xo toma el valor de x0=400, yo toma el valor de y0=300
g.setColor(Color.GREEN);
g.drawLine(xo,0,xo,alto);
g.drawLine(10,yo,ancho-10,yo);
min=-1.0*xo/esX;
max=(1.0*(ancho-xo)/esX);
castmin=(int)Math.round(min);
castmax=(int)Math.round(max);
ycastmin=(int)Math.round(1.0*(yo-alto)/esY);
ycastmax=(int)Math.round(1.0*yo/esY);
g.setColor(Color.LIGHT_GRAY);
g.setFont(ft7);
int numpixel=ancho;
if(esX>5)
{
for(i=castmin+1;i<castmax;i++)
{
g.drawLine(xo+i*esX,yo-2,xo+i*esX,yo+2);
if(i>0)
g.drawString(""+i,xo+i*esX-2,yo+12);
if(i<0)
g.drawString(""+i,xo+i*esX-6,yo+12);
}
}
if (esY>5)
{
for(i=castmin+1;i<castmax;i++)
{
g.drawLine(xo-2,yo-i*esY,xo+2,yo-i*esY);
if(i>0)
g.drawString(""+i,xo-12,yo-i*esY+3);
if(i<0)
g.drawString(""+i,xo-14,yo-i*esY+3);
}
}}}