I am having a great question about how to pass the data from the read2File method to the variables hairX and hairY, in readingFile2D it runs through a file populating vx and vy with the values of .txt, can someone give me a light on how to do this ?
Follow the class below:
public class Monalisa extends JFrame {
Polygon hair;
int[] hairX=new int[15];
int[] hairY=new int[15];
public Monalisa(){
hair = new Polygon(hairX,hairY,15);
setBackground(Color.lightGray);
repaint();
}
public static boolean leituraArquivo2D(String arquivo, int vx[],int vy[]){
try{
FileReader arq = new FileReader(arquivo);
BufferedReader lerArq = new BufferedReader(arq);
String linha = lerArq.readLine();
int id=0;
while((linha=lerArq.readLine())!=null){
String vetXY[]=linha.split(" ");
vx[id]=Integer.parseInt(vetXY[0]);
vy[id]=Integer.parseInt(vetXY[1]);
id=id+1;
}
arq.close();
return true;
}catch(IOException e){
System.out.println("Erro na abertura do arquivo:"+arquivo);
return false;
}
}
public void paint(Graphics g){
g.setColor(Color.white);
g.fillRoundRect(147, 84, 103, 74,23,23);
g.fillOval(147, 94, 103, 132);
g.setColor(Color.black);
g.fillPolygon(hair);
int[] eyebrow1X={151,168,174,171,178,193};
int[] eyebrow1Y={145,140,148,184,191,188};
g.drawPolyline(eyebrow1X, eyebrow1Y, 6);
int[] eyebrow2X={188,197,213,223};
int[] eyebrow2Y={146,141,142,146};
g.drawPolyline(eyebrow2X, eyebrow2Y, 4);
int[] mouthX={166,185,200};
int[] mouthY={199,200,197};
g.drawPolyline(mouthX, mouthY, 3);
g.fillOval(161, 148, 10, 3);
g.fillOval(202, 145, 12, 5);
}
public static void main(String[] args) {
Monalisa mona = new Monalisa();
mona.setSize(400, 400);
mona.setVisible(true);
}
}