import javax.swing.JPanel; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Dimension; import java.awt.Color; import java.awt.Polygon; import javax.swing.BorderFactory; import java.util.Iterator; import java.util.GregorianCalendar; import java.util.Date; import java.text.DateFormat; /** A panel on which a map will be drawn * * Starter version * * @author MD * @date 10/2002 */ public class MapPanel extends JPanel { /** just for convenience -- a shorter name */ // final static MDDimUtils dimU = new MDDimUtils(); final static int defaultWidth = 500; final static int defaultHeight = 500; final static double aspectRatio = ( (double) defaultWidth)/defaultHeight; final static Dimension desiredSize = new Dimension(defaultWidth, defaultHeight); public MapPanel() { super(); this.setPreferredSize(desiredSize); this.setBackground(Color.pink); this.setBorder(BorderFactory.createRaisedBevelBorder()); } //end constructor /** Method paintComponent is called AUTOMATICALLY when needed. * The following is general Java stuff, not specific to this project. * Rules: * 1. Don't call this method directly! * You may call repaint(); if you want the picture redrawn at any time * 2. This method should COMPLETELY redraw the ENTIRE image you want * on the panel * 3. Don't call ANY graphics methods from any other method in the program, * unless that method is called only as a result of this one * Not exactly rules, but still: * 1. You probably should not override any other methods of the base class * 2. You probably do not want to declare any objects of this class, * unless you are writing your own GUI. * * If at any time while working on this project, you feel you need to violate * one of those rules, and don't see any way around it -- ask! */ public void paintComponent(Graphics oldG) { //don't change this line //in a Swing application, g is always an instance of Graphics2D Graphics2D g2 = (Graphics2D) oldG; //don't change this line super.paintComponent(g2); //probably not needed //add code here to draw whatever you want! g2.setColor(Color.blue); g2.drawString("Please draw a map on me!", 20, defaultHeight - 60); } } //end mapPanel