程序
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
public class temp extends JFrame
{
Container container;
JList list;
JTextField field;
JPanel selectcolor;
public temp()
{
container=this.getContentPane();
container.setLayout(new BorderLayout());
Color[] colors={Color.orange,Color.pink,Color.red,Color.black,Color.blue,Color.cyan,Color.green,Color.lightGray};
list=new JList(colors);
JScrollPane jp=new JScrollPane(list);
selectcolor=new JPanel();
field=new JTextField();
selectcolor.setPreferredSize(new Dimension(20,20)); //设置panel的首选尺寸
container.add(field,BorderLayout.NORTH);
container.add(jp,BorderLayout.CENTER);
container.add(selectcolor,BorderLayout.SOUTH);
list.addListSelectionListener(new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
Color t=(Color)list.getSelectedValue();
selectcolor.setBackground(t);
field.setText(" B="+t.getBlue()+" G="+t.getGreen()+" R="+t.getRed());
field.setBackground(t);
list.setBackground(t);
}
});
setSize(300,200);setVisible(true);
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
temp x=new temp();
}
}
----------------解决方案--------------------------------------------------------
哦
知道了
呵呵
----------------解决方案--------------------------------------------------------