Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package Java64;
- import javax.swing.*;
- import javax.swing.event.*;
- import java.awt.*;
- /**
- *
- * @author ggj11091
- */
- public class JavaList extends JFrame{
- private JList list;
- private static String[] colornames = {"black","blue", "red", "white"};
- private static Color[] colors = {Color.BLACK,Color.BLUE,Color.RED,Color.WHITE};
- public JavaList(){
- super("Java List");
- setLayout(new FlowLayout());
- list = new JList(colornames);
- list.setVisibleRowCount(4);
- list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- add(new JScrollPane(list));
- list.addListSelectionListener(new ListSelectionListener(){
- public void valueChanged(ListSelectionEvent event){
- getContentPane().setBackground(colors[list.getSelectedIndex()]);
- }
- }
- );
- }
- }
Add Comment
Please, Sign In to add comment