Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 14th, 2012  |  syntax: Java  |  size: 2.59 KB  |  hits: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package principal;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.util.ArrayList;
  6.  
  7. import poo.edgraf.reprodutor.Quadro;
  8.  
  9. class Carregador {
  10.  
  11.         void carregar(BufferedReader in, Quadro quadro) throws IOException {
  12.                 String s;
  13.                 while ((s = in.readLine()).length() > 0) {
  14.  
  15.                         if (s.equals("RETANGULO")) {
  16.                                 carregarRetangulo(in, quadro);
  17.                         } else if (s.equals("CIRCULO")) {
  18.                                 carregarCirculo(in, quadro);
  19.                         } else if (s.equals("ELIPSE")) {
  20.  
  21.                         }
  22.                         ;// end caseof
  23.                                 // etc
  24.  
  25.                 }
  26.                 ;
  27.  
  28.         }
  29.  
  30.         void carregarRetangulo(BufferedReader in, Quadro quadro) throws IOException {
  31.                 int x1 = Integer.parseInt(in.readLine()), y1 = Integer.parseInt(in
  32.                                 .readLine()), x2 = Integer.parseInt(in.readLine()), y2 = Integer
  33.                                 .parseInt(in.readLine());
  34.  
  35.                 quadro.addFig(new RetanguloFig(new Ponto(x1, y1), new Ponto(x2, y2),
  36.                                 quadro));
  37.         }
  38.  
  39.         void carregarCirculo(BufferedReader in, Quadro quadro) throws IOException {
  40.                 int x = Integer.parseInt(in.readLine()), y = Integer.parseInt(in
  41.                                 .readLine()), r = Integer.parseInt(in.readLine());
  42.                 quadro.addFig(new CirculoFig(new Ponto(x, y), r));
  43.         }
  44.  
  45.         void carregarElipse(BufferedReader in, Quadro quadro) throws IOException {
  46.  
  47.                 int x = Integer.parseInt(in.readLine()), y = Integer.parseInt(in
  48.                                 .readLine()), a = Integer.parseInt(in.readLine()), b = Integer
  49.                                 .parseInt(in.readLine());
  50.                 quadro.addFig(new ElipseFig(new Ponto(x, y), a, b));
  51.         }
  52.  
  53.         void carregarLinha(BufferedReader in, Quadro quadro) throws IOException {
  54.                 int x1 = Integer.parseInt(in.readLine()), y1 = Integer.parseInt(in
  55.                                 .readLine()), x2 = Integer.parseInt(in.readLine()), y2 = Integer
  56.                                 .parseInt(in.readLine());
  57.                 quadro.addFig(new LinhaFig(new Ponto(x1, y1), new Ponto(x2, y2)));
  58.         }
  59.  
  60.         void carregarPoligono(BufferedReader in, Quadro quadro) throws IOException {
  61.                 boolean verdade = true;
  62.                 ArrayList<Ponto> arranjo = new ArrayList<Ponto>();
  63.  
  64.                 String s1;
  65.                 String s2;
  66.                 while (verdade == true) {
  67.  
  68.                         s1 = in.readLine();
  69.                         s2 = in.readLine();
  70.                         if (ehForma(s1) || ehForma(s2)) {
  71.                                 int x = Integer.parseInt(s1), y = Integer.parseInt(s2);
  72.                                 arranjo.add(new Ponto(x, y));
  73.  
  74.                         }
  75.  
  76.                 }
  77.  
  78.                 // como definir o tamanho do array ou o tamanho de n?
  79.  
  80.                 int n = 10;
  81.  
  82.                 int[] a = new int[n];
  83.  
  84.                 // como definir que chegou ao fim a captura de pontos do poligono ...
  85.  
  86.                 quadro.addFig(new PoligonoFig(a));
  87.         }
  88.  
  89.         private boolean ehForma(String s) {
  90.                 //TODO fazer um metodo que retorne false se for uma nova forma que estiver em jogo... ou podemos passar quantos vertices tem ou uma plavara como criterio de parada.
  91.                 return false;
  92.         }
  93. }//