How can i make images and buttons displayed when a button is pressed?
Hi
I'm doing kids game project. I have designed two pages. Fistr page is the Home page in which game options are displayed(2 or 3 buttons) each representing a game. When I click a button it should display the corresponding page which contains images and buttons. How can i make images and buttons displayed when a button is pressed?
[346 byte] By [
Arthreya] at [2007-9-30 23:15:41]

Hi Arthreya
I believe strongly in separation of GUI and 'program guts', ie.
to have the program and its functions as non-entangled with the GUI features
as possible.
In this case, you should have methods in your program to go to a certain page or
whatever other action you want.
You should also have a few JButtons, and add ActionListeners (or Actions) to them
so that, when pressed, the method you want will be executed.
Example:
import javax.swing.*;
import java.awt.event.*;
import java.awt.Toolkit;
import java.awt.Dimension;
/** Class to test the Beeper's functionality,
* and to demonstrate the separation of GUI function
* from 'inner program' function...
*
* The beep method of the Beeper class is independent of
* any GUI stuff. This is desirable.
*/
public class BeeperGUITester
{
public static void main (String[] args)
{
//The Beeper object to use
final Beeper beeper = new Beeper ();
JFrame fram = new JFrame ("Beeper");
//The button that will be pressed (funnily enough)
JButton pressMe = new JButton ("Press me!");
pressMe.addActionListener (new ActionListener ()
{
//This method is called when the button is pressed
public void actionPerformed (ActionEvent e)
{
beeper.beep ();
}
}
);
JPanel panel = new JPanel ();
panel.setBorder (new javax.swing.border.EmptyBorder (10, 10, 10, 10));
panel.add (pressMe);
fram.getContentPane ().add (panel);
//Now setup the frame:
fram.setSize (new Dimension (200, 100));
fram.setLocationRelativeTo (null);
fram.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
//Finally, display the frame:
fram.setVisible (true);
}
}
class Beeper
{
private final Toolkit toolkit;
public Beeper ()
{
this.toolkit = Toolkit.getDefaultToolkit ();
}
//The method to make a beep sound (on this Beeper object)
public void beep ()
{
toolkit.beep ();
}
}