Question
Topic: Java Programming A Sierpinski Triangle is a fractal formed by drawing a triangle, and then using the midpoints of each side of triangle to
Topic: Java Programming
A Sierpinski Triangle is a fractal formed by drawing a triangle, and then using the midpoints of each side of triangle to form another triangle. This inner triangle is then removed. The result is three smaller triangles (one at the top and one in each corner) on which the process is repeated. After iteration N, the image will contain 3^N triangles, each of which is similar to the original triangle.
Task: Modify the following program so the maximum slider value changes, as appropriate, when the window is resized.
import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.util.*;
public class Driver extends JFrame implements ChangeListener{ private JSlider slider = new JSlider(JSlider.HORIZONTAL); private SierTriangle triangle = null; public Driver() { triangle = new SierTriangle(); triangle.setBackground(Color.WHITE); this.getContentPane().add(triangle, BorderLayout.CENTER); JPanel orderPanel = new JPanel(); orderPanel.add(new JLabel("Enter a Level: ")); orderPanel.add(slider); orderPanel.setBackground(Color.WHITE);
slider.setMaximum(10); slider.setMinimum(0); slider.setValue(0); Hashtable
displayTriangle(g, level - 1, p1, p1_2, p3_1); displayTriangle(g, level - 1, p1_2, p2, p2_3); displayTriangle(g, level - 1, p3_1, p2_3, p3); } } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started