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

EBK JAVA PROGRAMMING
8th Edition
ISBN:9781305480537
Author:FARRELL
Publisher:FARRELL
Chapter16: Graphics
Section: Chapter Questions
Problem 13RQ
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.
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage