import java.awt.*;
import java.awt.event.*;
import java.util.HashMap;
import javax.swing.*;
public class SmallProgram extends JFrame
{
// These variables for the main window.
static JTextField txtName, txtCustomerName, txtEmail, txtAddress;
static JLabel lblName, lblCustomerName, lblEmail, lblAddress, lblEmpty3,
lblCustomizeYourOrder,lblEmpty, lblEmpty2 , lblTypeInfo, lblEmpty1;
static JButton btnCheckOut, btnAdd, btnQuit;
static JComboBox colours, sizes, logos; // Variables for drop box
static JLabel picture, logo; // Labels.
static JPanel pnlNorth, pnlSouth, pnlWest, pnlInWest;
static JLayeredPane jlayerPane; // To make layer on top of other one.
private static String[] fileName = {"src/white.gif", "src/green.gif", // array of the images names will
"src/blue.gif", "src/brown.gif", //
"src/black.gif", "src/red.gif", //
"src/gray.gif"}; // store the T-shirt pics.
private static String[] logosList = {"src/likeMe.gif", "src/followMe.gif",
"src/youtube.gif"};
private static String[] sizeList = {"XS", "S", "M", "L", "XL", "XXL"}; // To hold Sizes for T-shirts.
private Icon[] pics = { new ImageIcon(fileName[0]), new ImageIcon(fileName[1]), // array of images will store
new ImageIcon(fileName[2]), new ImageIcon(fileName[3]), new ImageIcon(fileName[4]), // the the all images.
new ImageIcon(fileName[5]), new ImageIcon(fileName[5]), new ImageIcon(fileName[6])};
private Icon[] logs = { new ImageIcon(logosList[0]), new ImageIcon(logosList[1]), //To hold logos for T-shirts.
new ImageIcon(logosList[2])};
// "Window" GUI.
public SmallProgram ()
{
///////////////////////////////////////////////////////////////////////////////
/////// ALSO HERE I CANN'T CHANGE THE NAME OF THE FILES USING HASH MAP ////////
///////////////////////////////////////////////////////////////////////////////
// Hash map to change the files name to the colours names.
HashMap <String, String> fileMap = new HashMap <String, String>();
fileMap.put("src/white.gif", "WHITE");
// Set the panels settings.
pnlNorth = new JPanel ( new GridLayout ( 3, 3));
pnlSouth = new JPanel(new GridLayout(1,4,8,8));
pnlWest = new JPanel(new GridLayout(10,2));
// Adding the components to the panels.
// add the dropList to the panel.
pnlNorth.add(colours = new JComboBox (fileName)); // put the colours list in the ( fileName array ) in list for us.
pnlNorth.add(sizes = new JComboBox ( sizeList )); // put the sizes list in the ( sizeList array ) in list for us.
pnlNorth.add(logos = new JComboBox ( logosList ));// put the logos list in the ( logoList array ) in list for us.
// Then add it to the container.
add(pnlNorth, BorderLayout.NORTH);
// Then add it to the container.
add(pnlSouth, BorderLayout.SOUTH);
// Then add it to the west panel.
add(pnlWest, BorderLayout.EAST);
///////////////////////////////////////
///////////////////////////////////////
///////// HERE IS MY PROBLEM //////////
///////////////////////////////////////
///////////////////////////////////////
// JLayerPane to put 2ed layer "logo" on top of the picture.
jlayerPane = new JLayeredPane();
jlayerPane.setPreferredSize(new Dimension (300,300));
jlayerPane.setLayout(new FlowLayout());
picture = new JLabel (pics[0]);
logo = new JLabel (logs [0]);
// Manually set layout the components, and add it.
jlayerPane.add(picture, new Integer (50));
jlayerPane.add(logo, new Integer (49));
// Add the JLayerPane to the container.
add(jlayerPane);
// Manually set layout the components.
picture.setBounds(600, 100, picture.getWidth(), picture.getHeight());
logo.setBounds(600, 100, logo.getWidth(), logo.getHeight());
/////////////////////////
//// Action Listeners ///
/////////////////////////
// Add an action listener to buttons.
// The add button.
colours.addActionListener
(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
colours.getSelectedItem();
}
});
sizes.addActionListener
(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
sizes.getSelectedItem();
}
});
logos.addActionListener
(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
logos.getSelectedItem();
}
});
//
// Add an action listener to the colours JComboBox.
colours.addItemListener(
new ItemListener()
{
// will choose a picture if the button has been selected.
public void itemStateChanged (ItemEvent event)
{
// if button selected pick the picture.
if(event.getStateChange() == ItemEvent.SELECTED)
picture.setIcon(pics[colours.getSelectedIndex()]);
}
}
);
// Add an action listener to the logos to JComboBox.
logos.addItemListener(
new ItemListener()
{
// will choose a logo if the button has been selected.
public void itemStateChanged (ItemEvent event)
{
// if button selected pick the logo.
if(event.getStateChange() == ItemEvent.SELECTED)
logo.setIcon(logs[logos.getSelectedIndex()]);
}
}
);
}// End the main GUI contractor.
// The Main method.
public static void main (String []args)
{
SmallProgram gui = new SmallProgram();
gui.setSize(550,420);
gui.setResizable(false);
gui.setVisible(true);
gui.setLocationRelativeTo(null);
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}// End Main.
}