Please fix errors for the java code below. The program is a t square fractal (image below)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please fix errors for the java code below. The program is a t square fractal (image below)

 

import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;

//main class
public class SquareFractal {
 public static void main(String[] args)
 {
  FractalFrame tframe = new FractalFrame();
  tframe.setTitle("T Square Fractal");
  tframe.setVisible(true);
 }
}

//JFrame extended in fractal class 
class T_Fractal extends JFrame
{
 private JPanel panel;
    private int twidth, theight;
    private int x = 200;
    private int limit = 15;

 public T_Fractal()
 {
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  //default height and width
  final int Width  = 1000;
  final int Height = 1000;
  setSize(Width, Height);
  setLocation(200,50);

  panel = new JPanel();
  Container t_content = getContentPane();
  t_content.add(panel, "Center");
 }

 public void paint(Graphics graphics) {
        super.paint(graphics);
        Graphics2D g2 = (Graphics2D) graphics;
        twidth  = getWidth();
        theight = getHeight();
        graphics.setColor(Color.WHITE);

        int w = (twidth/2)-(x/2);
        int h = (theight/2)-(x/2);
        graphics.fillRect(w, h, x, x);
        if(limit > 0) drawSquare(w,h,graphics);
        JOptionPane.showMessageDialog(null, "Fractal Completed");
    }

    private void drawSquare(int w, int h, Graphics graphics) {
        int n = 0;
        graphics.fillRect(w-(x/2), h-(x/2), x/2, x/2);
        drawSquare(w-(x/2), h-(x/2), graphics, n, 0, x/2);
        graphics.fillRect(w+x, h-(x/2), x/2, x/2);        
        drawSquare(w+x, h-(x/2), graphics, n, 1, x/2);
        graphics.fillRect(w+x, h+x, x/2, x/2);
        drawSquare(w+x, h+x, graphics, n, 2, x/2);
        graphics.fillRect(w-(x/2), h+x, x/2, x/2);
        drawSquare(w-(x/2), h+x, graphics, n, 3, x/2);
    }
    private void drawSquare(int w, int h, Graphics graphics, int n, int origin, int size) {
        if(n == limit){
    return;
  }
        n++;
        origin = (origin+2)%4;
        if(origin != 0) {
            graphics.fillRect(w-(size/2), h-(size/2), size/2, size/2);
            drawSquare(w-(size/2), h-(size/2),graphics,n,0,size/2);
        }
        if(origin != 1) {
            graphics.fillRect(w+size, h-(size/2), size/2, size/2);      
            drawSquare(w+size, h-(size/2),graphics,n,1,size/2);
        }
        if(origin != 2) {
            graphics.fillRect(w+size, h+size, size/2, size/2);
            drawSquare(w+size, h+size,graphics,n,2,size/2);
        }
        if(origin != 3) {
            graphics.fillRect(w-(size/2), h+size, size/2, size/2);
            drawSquare(w-(size/2), h+size,graphics,n,3,size/2);
        }
    }
}

T Square Fractal
O
Transcribed Image Text:T Square Fractal O
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Files and Directory
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education