/* * 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 { private RandCharsModel theChars; //the model private OuijaViewer 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 Ouija Board"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(frameWidth, frameHeight); this.setBackground(java.awt.Color.yellow); //ineffective java.awt.Container contentPane = this.getContentPane(); contentPane.setLayout(new java.awt.FlowLayout()); contentPane.setBackground(java.awt.Color.white); this.theChars = new RandCharsModel(startChar, endChar); this.charsViewer = new OuijaViewer(theChars); this.charsViewer.addMouseListener(new RandCharMouseListener()); contentPane.add(this.charsViewer); contentPane.add(new PublicInfoPanel(this.theChars)); contentPane.add(new PublicInfoPanel(this.charsViewer)); 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 */ 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 } }