Delay

1 resposta
F

Olá, alguém sabe como usar o delay q existe no C++ no Java?? E alguma pessoa iluminada sabe me dizer pq o CloseWindowAndExit() dá erro no
meu programa? Obrigado.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public abstract class CirculoAnaliticov2 extends JFrame implements ActionListener{
    
    JLabel l1,l2,l3,l4;
    JTextField c1,c2,c3,c4;
    JButton b1,b2;
    
    
    public CirculoAnaliticov2(){
        super("Circunferência: Método Analítico");
        setSize(300,345);
        Panel p = new Panel();
        p.setBackground(SystemColor.control);
        p.add(l1 = new JLabel("x1:"));
        p.add(c1 = new JTextField(3));
        p.add(l2 = new JLabel("y1:"));
        p.add(c2 = new JTextField(3));
        p.add(l3 = new JLabel("x2:"));
        p.add(c3 = new JTextField(3));
        p.add(l4 = new JLabel("y2:"));
        p.add(c4 = new JTextField(3));
        p.add(b1 = new JButton("DESENHAR"));
        b1.addActionListener(this);
        p.add(b2 = new JButton("LIMPAR"));
        b2.addActionListener(this);
        add("South",p);
        addWindowListener(new CloseWindowAndExit());
        
    }
    
    int x1, y1, x2, y2;
    int dx, dy;
    
    
    public double Raio(int dx,int dy){
        dx = x2 - x1;
        dy = y2 - y1;
        return (Math.sqrt((Math.pow(dx,2))+(Math.pow(dy,2))));
    }
    
    
    
    
    public void paint(Graphics g){
        
        
        double passo = (int) 1/Raio(dx, dy);
        double t = 0;
        while (t<2*Math.PI){
            double x = (int) Raio(dx, dy)*Math.cos(t);
            double y = (int) Raio(dx,dy)*Math.sin(t);
            int a = (int) x + x1;
            int b = (int) y + y1;
            g.setColor(Color.black);
            g.drawRect(x2,y2,90,90);
            g.setColor(Color.red);
            g.drawArc((int)a,(int)b,0,(int)t,90,90);
            
            
            t = (int) t + passo;
        }
        
        
    }
    
    public void ActionPerformed(ActionEvent e){
        if (e.getSource() == b1){
            try{
                x1 = Integer.parseInt(c1.getText());
                y1 = Integer.parseInt(c2.getText());
                x2 = Integer.parseInt(c3.getText());
                y2 = Integer.parseInt(c4.getText());
                c1.setText(" ");
                c2.setText(" ");
                c3.setText(" ");
                c4.setText(" ");
            }
            catch (NumberFormatException exc){
                Toolkit.getDefaultToolkit().beep();
            }
        }
        repaint();
    }
    
    public static void main(String args []) {
        CirculoAnalitico implementa = new CirculoAnalitico();
        implementa.show();
	
    }
    
}

1 Resposta

Rafael_Steil

Voce pode tentar com Thread.sleep(ms).

Em relacao ao CloseWindowAndExit(), onde vc definiou essa classe? Voce pode fazer ela como

class CloseWindowAndExit extends WindowAdapter  {
	public void windowClosing( WindowEvent e ) {
		System.exit( 0 );
	}
}

Rafael

Criado 6 de julho de 2004
Ultima resposta 6 de jul. de 2004
Respostas 1
Participantes 2