title: Read a file with both string and double to draw rectangle
body: <p>I have a input file-file.txt with below contents  </p>
  
  <blockquote>
  <pre><code>M1 100 100 400.89 400.72   
    400 400 450.89 450.72  
  </code></pre>
    
    <p>M2 100 100 440.56 440.82<br>
        M3 100 200 300.52 330.75<br>
           200 200 320.53 340.34<br>
            300 300 400.43 350.25  </p>
  </blockquote>
  
  <p>I have written a program to draw a rectangle.But I am not able to draw it for M1,M2 and M3   simultaneously.The four double values in each line represent the 2 coordinates of a rectangle. Also please help me out in solving this if in case my file is  </p>
  
  <blockquote>
    <p>M1 = [ 100 100 400.89 400.72;<br>
     400 400 450.89 450.72 ]<br>
    M2 = [100 100 440.56 440.82 ]<br>
    M3 = [100 200 300.52 330.75;<br>
     200 200 320.53 340.34;<br>
     300 300 400.43 350.25]     </p>
  </blockquote>
  
  <p>The code I have written is:</p>
  
  <pre><code>import java.util.*;
  import java.io.*;
  import java.awt.*;
  import java.awt.geom.*;
  import java.awt.image.*;
  import java.awt.event.*;
  import javax.swing.*;
  import java.lang.*;
  import java.math.*;
  import java.text.DecimalFormat.*;
  
  class Rectangles extends JComponent
  {
   public void paint(Graphics g)
  
   { 
   Graphics2D g2 = (Graphics2D) g;
     try
    {
  
     File x=new File("file.txt");
     Scanner sc=new Scanner(x);
   while(sc.hasNext())
   { 
    String s=sc.next();
   if(s.equals("M1"))
    {
   while(sc.hasNext())
    {
    double x1=sc.nextDouble();
    double y1=sc.nextDouble();
    double x3=sc.nextDouble();
    double y3=sc.nextDouble();
    double x2=x3;
    double y2=y1;
    double x4=x1;
    double y4=y3;
    double a=x1;
    double b=y1;
    double c1=Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
    double d1=Math.sqrt((x4-x1)*(x4-x1)+(y4-y1)*(y4-y1));
    double c=c1;
    double d=d1;
    g2.setPaint(Color.blue);
    g2.draw(new Rectangle2D.Double(a,b,c,d));
    g2.fill(new Rectangle2D.Double(a,b,c,d)); 
  
    }
  
    }
    }}      
  
     catch(Exception e)
      {
     System.out.println("reported Exception");
       }
  
     }
     }
  
  
     public class eighth
     {
  
    public static void main(String[] args)throws IOException
    {
  
     JFrame window = new JFrame();
     window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     window.setBounds(60, 60, 900, 900);
      window.getContentPane().add(new Rectangles());
      window.setVisible(true);
  
     }
    }
  </code></pre>
  
  <p>How to draw the three rectangles of type M1, M2 and M3 simultaneously?</p>