/* * RandCharFrame.java * * Created on February 5, 2003, 5:04 PM */ package randchars; import MDUtils.*; import java.awt.event.MouseListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JPanel; import javax.swing.JFrame; /** A frame holding a panel to display a list of random characters, and other * imformation about the program. * This class acts as the controller for the application. * * @author dickey */ public class RandCharController extends JFrame { /** The model: holds all the characters generated so far. */ private RandCharModel theChars; //the model /** The viewer: A graphical display of the characters. */ private RandCharViewer charsViewer; //the viewer //private PublicInfoPanel charInfo; //info about the viewer private int frameWidth = 700, frameHeight = 600; /** Creates a new instance of RandCharController */ public RandCharController(char startChar, char endChar) { super("The Multi-Lingual Random Character Board"); System.out.println("Starting up... please be patient."); // Apparently Bluej doesn't like the following statement: this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(frameWidth, frameHeight); this.setBackground(java.awt.Color.yellow); //ineffective System.out.print("still working..."); java.awt.Container contentPane = this.getContentPane(); contentPane.setLayout(new java.awt.FlowLayout()); contentPane.setBackground(java.awt.Color.white); this.theChars = new RandCharModel(startChar, endChar); this.charsViewer = new RandCharViewer(theChars); this.charsViewer.addMouseListener(new RandCharMouseListener()); contentPane.add(this.charsViewer); contentPane.add(new PublicInfoPanel(this.theChars)); contentPane.add(new PublicInfoPanel(this.charsViewer)); System.out.println("Startup almost finished..."); this.show(); } /** Override the JFrame method. */ public void repaint() { this.pack(); //main reason is in case an image has finished loading. super.repaint(); } /** Listener for mouse clicks MouseAdapter is a standard Java class, which implements stubs for the methods of the Mouse Listener interface. */ class RandCharMouseListener extends MouseAdapter { /** If mouse is clicked, generate a new character, then ask the viewer * to refresh itself. */ public void mouseClicked(MouseEvent e) { theChars.randomlyAddChar(); charsViewer.repaint(); } //end mouse adapter } }