Dúvidas c/ instâncias

2 respostas
Q

Prezados Amigos:

Sou iniciante no Java e estou c/ difuldades em fazer c/ que uma determinada instância delcarada no inicio da classe, seja ‘vista’ pelos demais métodos da classe. O meu problema está na conversão de dados para o método drawOval da classe Graphics.
este é o meu código:

import java.awt.Graphics;

import javax.swing.*;

public class Cap03Ex18 extends JApplet

{

Integer x,y,width, height;

public void init ()
{

String n1,n2,n3,n4;

n1 = JOptionPane.showInputDialog

(Enter the value of x);

n2 = JOptionPane.showInputDialog

(Enter the value of y);

n3 = JOptionPane.showInputDialog

(Enter the value of width);

n4 = JOptionPane.showInputDialog

(Enter the value of height);
x = Integer.parseInt(n1);

y = Integer.parseInt(y);

width  = Integer.parseInt(width);

height = Integer.parseInt(height);

}

public void paint (Graphics g)

{
g.drawOval (x,y,width,height);

}
}

2 Respostas

Rafael_Steil

Olha, se o teu problema for o que estou pensando, o erro esta na parte

nao use a classe Integer, mas sim o tipo primitivo “int”, como abaixo:

int x,y,width, height

[]'s
Rafael Steil

aconstantino

Isso… ou então um cast (int)

Criado 25 de setembro de 2002
Ultima resposta 26 de set. de 2002
Respostas 2
Participantes 3