/* * Created on Apr 7, 2005 */ package WordPro2Controller; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JPanel; import WordPro2Speller.ISpellChecker; /** A class which displays a spelling dictionary. * You need to modify this class. * If you define additional fields or methods, they must be private. */ public class SpellerViewer extends JPanel { private ISpellChecker theChecker; /** Request that the full dictionary be displayed on this panel, * one word per line, with the words sorted in alphabetical order. * Normally MySpellChecker would call this method from MySpellChecker. The * argument would normally be 'this'. * You should not have to change this method. If you think you do, * you probably should think again. * @param aDocument a non-null document. */ public void display(ISpellChecker aChecker) { this.theChecker = aChecker; repaint(); } /** Display all the words of the dictionary, one per line, in * alphabetical order. * DO NOT CALL THIS METHOD. Take it on blind faith that it will * get called when needed. In fact, display, as coded above, will * cause this method to be called indirectly. Instead of calling this method, you * normally should just call display. * But do modify it! All your code for displaying the information should * be here. */ public void paintComponent(Graphics oldG) { //Always start your paint methods with this cast. Graphics2D g = (Graphics2D) oldG; //then always do this call to the superclass super.paintComponent(g); int x = 5; int y = 10; final int linespacing = 20; g.drawString("aardvark", x, y); y += linespacing; g.drawString("acorn", x, y); y += linespacing; g.drawString("adam", x, y); y += linespacing; g.drawString("This is not really a dictionary, " + "as your users would rightly guess.", x, y); y += linespacing; //for more hints on displying text, see DocumentViewer starter code. } }