import java.awt.Color;
import javax.swing.*;
import javax.swing.ImageIcon;
import javax.swing.SwingConstants;
import java.awt.FlowLayout;
import javax.swing.border.*;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
public class finalexam extends JFrame{
private static final long serialVersionUID = 1L;
private JList colorList;
private final String colorNames[]={"PINK","BLUE","GREEN","YELLOW","GRAY"};
private final Color colors[]={Color.pink,Color.blue,Color.green,Color.yellow,Color.GRAY};
private EtchedBorder eb= new EtchedBorder(1, Color.black, Color.gray);
public finalexam(){
super("MY PICTURE PROFILE");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500, 500);
setLayout(new FlowLayout());
colorList = new JList(colorNames);
colorList.setSelectionMode(0);
colorList.setBorder(eb);
add(new JScrollPane(colorList));
colorList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
getContentPane().setBackground(colors[colorList.getSelectedIndex()]);
}
});
add(colorList);
setVisible(true);
}
JFrame myWindow=new JFrame();
myWindow.setSize(WIDTH,HEIGHT);
myWindow.getContentPane().setLayout(null);
JLabel myLabel=new JLabel("MY PICTURE GALLERY");
myLabel.setIcon(new ImageIcon("winter.jpg"));
myLabel.setHorizontalTextPosition(SwingConstants.LEFT);
myLabel.setBounds(450,10,350,20);
myWindow.getContentPane().add(myLabel);
myWindow.setVisible(true);
public static void main(String args[]){
new ListFrame();
}
}