// Project: Recursion // Module: floodfill // Source code file: MyFrame.java // Illustrate the FloodFill algorithm. // The user draws a closed shape and // picks a seed point in the shape. // The application fills the shape with // a recursive algorithm. import javax.swing.*; import java.awt.*; import java.awt.event.*; @SuppressWarnings("serial") public class MyFrame extends JFrame { private MyPanel p; private JButton bFill, bReset; public MyFrame() { super("Flood Fill Recursive Algorithm"); p = new MyPanel(); bFill = new JButton("Fill"); bReset = new JButton("Reset"); p.setLayout(new FlowLayout()); p.add(bFill); p.add(bReset); ClickDetector cd = new ClickDetector(); bFill.addActionListener(cd); bReset.addActionListener(cd); setContentPane(p); setSize(410, 428); setVisible(true); } private class ClickDetector implements ActionListener { public void actionPerformed(ActionEvent e) { if(e.getSource() == bFill) { p.startFill(); } else { p.reset(); } } } }