import javax.swing.*; import java.awt.*; import java.util.*; import java.awt.event.*; public class RoadMap extends JFrame { public class TestRoadCanvas extends JPanel { private ImageIcon mPage1; private ImageIcon mPage2; private ImageIcon mQuiz1; public TestRoadCanvas() { super(); mPage1 = new ImageIcon("p1thumb.png"); mPage2 = new ImageIcon("p2thumb.png"); mQuiz1 = new ImageIcon("q1thumb.png"); setPreferredSize(new Dimension(60 + mPage1.getIconWidth() + mPage2.getIconWidth() + mQuiz1.getIconWidth(), 40 + mPage1.getIconWidth())); addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { /* Check to see if we hit one of the pictures */ Rectangle p1 = new Rectangle(10, 10, mPage1.getIconWidth(), mPage1.getIconHeight()); Rectangle p2 = new Rectangle(30 + mPage1.getIconWidth(), 10, mPage2.getIconWidth(), mPage2.getIconHeight()); Rectangle q1 = new Rectangle(50 + mPage1.getIconWidth() + mPage2.getIconWidth(), 10, mQuiz1.getIconWidth(), mQuiz1.getIconHeight()); Point here = new Point(e.getX(), e.getY()); if (p1.contains(here) || p2.contains(here) || q1.contains(here)) { new Page().setVisible(true); } } }); } public void paint(Graphics g) { int x1, y1; int x2, y2; /* Draw pictures and Labels */ mPage1.paintIcon(this, g, 10, 10); g.drawString("Introduction to Java", 10, 20 + mPage1.getIconHeight()); mPage2.paintIcon(this, g, 30 + mPage1.getIconWidth(), 10); g.drawString("Hello World Example", 30 + mPage1.getIconWidth(), 20 + mPage2.getIconHeight()); mQuiz1.paintIcon(this, g, 50 + mPage1.getIconWidth() + mPage2.getIconWidth(), 10); g.drawString("Lesson 1 Assessment", 50 + mPage1.getIconWidth() + mPage2.getIconWidth(), 20 + mQuiz1.getIconHeight()); /* Draw Arrows */ x1 = 10 + mPage1.getIconWidth(); y1 = 20 + mPage1.getIconHeight() / 2; x2 = x1 + 20; y2 = 20 + mPage2.getIconHeight() / 2; g.drawLine(x1, y1, x2, y2); g.drawLine(x2, y2, x2 - 5, y2 - 5); g.drawLine(x2, y2, x2 - 5, y2 + 5); x1 = x2 + mPage2.getIconWidth(); y1 = y2; x2 = x1 + 20; g.drawLine(x1, y1, x2, y2); g.drawLine(x2, y2, x2 - 5, y2 - 5); g.drawLine(x2, y2, x2 - 5, y2 + 5); g.dispose(); } } private Container mPane; private JPanel mPanel; private TestRoadCanvas mCanvas; public RoadMap() { super(); mPane = getContentPane(); mCanvas = new TestRoadCanvas(); mPanel = new JPanel(); setupLayout(); } private void setupLayout() { mPanel.setLayout(new GridBagLayout()); GridBagConstraints cons = new GridBagConstraints(); cons.gridx = cons.gridy = 0; mPanel.add(mCanvas, cons); cons.gridy++; cons.anchor = GridBagConstraints.EAST; mPanel.add(new JButton(new AbstractAction("FAQ", null) { public void actionPerformed(ActionEvent evt) { System.out.println("FAQ button pressed"); } }), cons); mPane.add(mPanel); pack(); } }