/*
 * 1.3 
 *  В един текстов файл са зададени данни за правоъгълници, 
 *  имащи страни съответно успоредни на координатните оси.
 * 	
 * В един ред са данните 
 *  - X и Y за горната лява точка, последвани от 
 *  - X и Y за долната дясна точка
 *  
 *  Като разделител служи интервал.
 *  
 *  Да се състави Application на Java за 
 *  - прочитане на този файл и за
 *  - графично представяне на правоъгълниците
 *  
 */

import java.awt.*;
import java.io.*;

public class CourseWork extends Frame {
	
	public static final String PATH_TO_FILE = "D:\\input.txt";
	
	// Default constructor - sets Frame settings like size, background color and ability to close it
	public CourseWork() {
		super("COP Course Work #1 - dvt32, 146518 - 1.3 Rectangles");
		addWindowListener(new WindowClosingAdapter(true));
		setBackground(Color.decode("#89cff0"));
		setSize(1024, 768);
		setVisible(true);
	}
	
	// Draws the rectangles on the screen
	public void paint(Graphics g) { 
		BufferedReader bufferedReader;
		FileReader fileReader;
		String lineInFile = "";
		
		// Try to open input file
		try {
			fileReader = new FileReader(PATH_TO_FILE);
			bufferedReader = new BufferedReader(fileReader);
		}
		catch (FileNotFoundException e) {
			System.out.println("File not found.");
			return;
		}
		
		// Read file line by line
		try {
			while ((lineInFile = bufferedReader.readLine()) != null) {
				String[] numbersOnLine = lineInFile.split("[ ,:!?]+");
				
				int upperLeftX = Integer.parseInt(numbersOnLine[0]);
				int upperLeftY = Integer.parseInt(numbersOnLine[1]);
				int lowerRightX = Integer.parseInt(numbersOnLine[2]);
				int lowerRightY = Integer.parseInt(numbersOnLine[3]);
				
				int widthOfRectangle = lowerRightX - upperLeftX;
				int heightOfRectangle = lowerRightY - upperLeftY;
				
				// Draw rectangle
				g.drawRect(upperLeftX, upperLeftY, widthOfRectangle, heightOfRectangle);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	    
		
		// Close streams
		try {
			fileReader.close();
			bufferedReader.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	// Main method
	public static void main(String[] args) {
		
		// Load main window and display rectangles
		CourseWork mainWindow = new CourseWork();
	
	}
	
}

@@ -454,16 +454,67 @@
 va.io.*;
+%0Aimport java.util.List;%0Aimport java.util.ArrayList;
 %0A%0Apublic
@@ -943,79 +943,122 @@
 %0A%09%0A%09
-// Draws the rectangles on the screen%0A%09public void paint(Graphics g) %7B 
+public List%3Cint%5B%5D%3E getCoordinatesFromFile(String pathToFile) %7B%0A%09%09List%3Cint%5B%5D%3E coordinates = new ArrayList%3Cint%5B%5D%3E();
 %0A%09%09B
@@ -1208,28 +1208,26 @@
 eReader(
-PATH_TO_FILE
+pathToFile
 );%0A%09%09%09bu
@@ -1364,16 +1364,28 @@
 %09%09return
+ coordinates
 ;%0A%09%09%7D%0A%09%09
@@ -1542,21 +1542,16 @@
 !?%5D+%22);%0A
-%09%09%09%09%0A
 %09%09%09%09int 
@@ -1772,21 +1772,16 @@
 ne%5B3%5D);%0A
-%09%09%09%09%0A
 %09%09%09%09int 
@@ -1883,50 +1883,79 @@
 tY;%0A
-%09%09%09%09%0A
 %09%09%09%09// 
-Draw rectangle%0A%09%09%09%09g.drawRect(
+Add coordinates to 2D ArrayList%0A%09%09%09%09coordinates.add(new int%5B%5D %7B 
 uppe
@@ -2009,16 +2009,18 @@
 ectangle
+ %7D
 );%0A%09%09%09%7D%0A
@@ -2081,19 +2081,16 @@
 %7D%0A%09    %0A
-%09%09%0A
 %09%09// Clo
@@ -2214,16 +2214,489 @@
 ();%0A%09%09%7D%0A
+%09%09%0A%09%09return coordinates;%0A%09%7D%0A%09%0A%09// Draws the rectangles on the screen%0A%09public void paint(Graphics g) %7B %0A%09%09List%3Cint%5B%5D%3E coordinates = getCoordinatesFromFile(PATH_TO_FILE);%0A%09%09for (int%5B%5D rowOfCoordinates : coordinates) %7B%0A%09%09%09int upperLeftX = rowOfCoordinates%5B0%5D;%0A%09%09%09int upperLeftY = rowOfCoordinates%5B1%5D;%0A%09%09%09int widthOfRectangle = rowOfCoordinates%5B2%5D;%0A%09%09%09int heightOfRectangle = rowOfCoordinates%5B3%5D;%0A%09%09%09g.drawRect(upperLeftX, upperLeftY, widthOfRectangle, heightOfRectangle);%0A%09%09%7D%0A
 %09%7D%0A%0A%09// 
@@ -2749,19 +2749,16 @@
 args) %7B%0A
-%09%09%0A
 %09%09// Loa
@@ -2839,16 +2839,12 @@
 ork();%0A%09
-%0A%09%7D%0A%09
+%7D
 %0A%7D%0A

Move file reading functionality to separate method