Pessoal, tenho os seguintes programinhas básicos para se fazer um circulo com a entrada do raio pela teclado.
DesenhaCirculo.java/*
* Created on 11/05/2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
import javax.swing.JFrame;
import java.awt.Container;
public class DesenhaCirculo extends JFrame{
public DesenhaCirculo() {
super("título");
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
Container c = getContentPane();
c.add(new Circulo());
this.setSize(800,600);
this.show();
}
public static void main (String args[]) {
DesenhaCirculo desenhaCirculo = new DesenhaCirculo();
}
}
/*
* Created on 11/05/2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
/**
* @author adenilson.mezini
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
import java.awt.Graphics;
import java.awt.Canvas;
import javax.swing.*;
public class Circulo extends Canvas{
private Graphics g;
public void desenhaCirculo(int x1, int y1, int Raio) {
int x, y;
float direcao = 1 - Raio;
x = 0;
y = Raio;
while (x < y) {
if (direcao < 0)
{
direcao = direcao + 2*x + 3;
x++;
}
else
{
direcao = direcao + 2*(x - y) + 5;
x++;
y--;
}
g.drawLine(x + x1, y + y1, x + x1, y + y1);
g.drawLine(x1 - x, y + y1, x1 - x, y + y1);
g.drawLine(x + x1, y1 - y, x + x1, y1 - y);
g.drawLine(x1 - x, y1 - y, x1 - x, y1 - y);
g.drawLine(y + y1, x + x1, y + y1, x + x1);
g.drawLine(y1 - y, x + x1, y1 - y, x + x1);
g.drawLine(y + y1, x1 - x, y + y1, x1 - x);
g.drawLine(y1 - y, x1 - x, y1 - y, x1 - x);
}
}//Função para desenhar o círculo utilizando o "Midpoint Algoritm"
public void paint(Graphics g)
{
int raio=0;
String msg="";
this.g = g;
msg = JOptionPane.showInputDialog("Digite o Raio: ");
raio = Integer.parseInt(msg);
desenhaCirculo(300,300,raio);
JOptionPane.exit(0);
}
}
Compilando e executando o desenhacirculo, ele pede a entrada do raio através de um JOptionPane.
Está funcionando, mas o JOptionPane entre em looping.
Como eu faço para que após a 1º entrada de dados não apareça mais a caixa de diálogo?
valeu@
:lol: :lol: :lol: :lol: :lol: