I need helping adding three pictures into this split pane program. I have the co
ID: 3701914 • Letter: I
Question
I need helping adding three pictures into this split pane program. I have the correct name of the images appearing on the left side of the pane, but I need to click on them and have them appear on the right which I can't figure out. THIS PROGRAM IS IN JAVA
// Demonstrates the use a split pane and a list.
import java.awt.;
import javax.swing.;
public class PickImage{
//-----------------------------------------------------------------
// Creates and displays a frame containing a split pane. The
// user selects an image name from the list to be displayed.
//-----------------------------------------------------------------
public static void main(String[] args)
{
JFrame frame = new JFrame("Pick Image");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Demonstrates the use a split pane and a list.
//********************************************************************
import java.awt.;
import javax.swing.;
import javax.swing.event.*;
public class ListPanel extends JPanel
{
private JLabel label;
private JList list;
//-----------------------------------------------------------------
// Loads the list of image names into the list.
//-----------------------------------------------------------------
public
ListPanel(JLabel imageLabel)
{
label = imageLabel;
String[] fileNames = { "monster1.gif",
"monster2.gif",
"monster3.gif",
};
list = new JList(fileNames);
list.addListSelectionListener(new ListListener());
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
add(list);
setBackground(Color.white);
}
//*****************************************************************
// Represents the listener for the list of images.
//*****************************************************************
private class ListListener implements ListSelectionListener
{
public void valueChanged(ListSelectionEvent event)
{
if
(list.isSelectionEmpty())
label.setIcon(null);
else
{
String fileName = (String)list.getSelectedValue();
ImageIcon image = new ImageIcon(fileName);
label.setIcon(image);
}
}
}
}
Explanation / Answer
I came to understand that you have some inages on the right side and when yu clicked it has to move to right or some other location. That is the main requirement right.
I have went through your code it has flaws in many places.
Here is the working code for your requirements. If any modifications needed or any requirements that i missed please let me know through a comment i will help you.
Source Code