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
Get step-by-step solutions from verified subject matter experts
