// Objective : When the user clicks the help button an image will pop up
import java.awt.*; import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.*;import java.io.*; import javax.swing.*;import javax.imageio.*; import java.awt.Color; import java.awt.Graphics; public class GridBags extends JFrame{ JPanel thePanel; public GridBags(){ super(); //general settings this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); this.setSize(1000, 500); this.setResizable(false); this.setTitle("Biology Review Program"); this.setVisible(true); this.setLayout(new GridBagLayout()); initComponents(); } public void initComponents(){ //This variable is changed to allow us to place buttons //and other components flexibly on the page. GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.NONE; JButton lesson = new JButton("Lessons"); c.gridwidth = 1; c.gridheight = 1; c.gridx = 1; c.gridy = 500; this.add(lesson, c); lesson.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ System.out.println("You clicked for Lesson?"); } }); //create the myCreature object thePanel = new JPanel(); //set the size and background of the panel thePanel.setPreferredSize(new Dimension(700, 500)); thePanel.setBackground(new java.awt.Color(0, 0, 0)); //add the panel to the pane c.gridwidth = 2; //six "buttons" wide c.gridheight = 1; c.gridx = 3; //left most c.gridy = 1; //top most this.add(thePanel, c); JButton quiz = new JButton("Quiz"); c.gridwidth = 1; c.gridheight = 1; c.gridx = 2; c.gridy = 500; this.add(quiz, c); quiz.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ System.out.println("You clicked for Quiz?"); } }); JButton help = new JButton("Help"); c.gridwidth = 1; c.gridheight = 1; c.gridx = 3; c.gridy = 500; this.add(help, c); help.addActionListener(new ActionListener() { [COLOR="#FF0000"] Image img=null; try {img=ImageIO.read(new File("help.jpg"));} catch(IOException e) {System.out.println("ok");System.exit(0);} g.drawImage(img,200,0,this);[/COLOR] public void actionPerformed(ActionEvent e){ System.out.println("You clicked for Help?"); } }); } public static void main(String[] args){ GridBags example = new GridBags(); example.pack(); example.show(); } }