import java.awt.*; import javax.swing.*;
public class ShowColors2 extends JFrame{ private JButton changeColorButton; private Color color = Color.LIGHT_GRAY; private Container container; public ShowColors2() { super("Using JColorChooser"); container = getContentPane(); container.setLayout(new FlowLayout()); changeColorButton = new JButton("Change Color"); changeColorButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { color = JColorChooser.showDialog( ShowColor2.this, "Chooes a color",color); if(color == null ) color = Color.LIGHT_GRAY; container.setBackground(color); } } ); container.add(changeColorButton); setSize(400,130); setVisible(true); } public static void main(String args[]) { ShowColors2 application = new ShowColors2(); application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } 我用的是JC, 垃圾,编译提示错误只有1句话, cant not resolve 。。。 ,唉
----------------解决方案--------------------------------------------------------
import java.awt.*; import javax.swing.*; import java.awt.event.*; //add this... public class ShowColors2 extends JFrame{ private JButton changeColorButton; private Color color = Color.LIGHT_GRAY; private Container container;
public ShowColors2() { super("Using JColorChooser"); container = getContentPane(); container.setLayout(new FlowLayout()); changeColorButton = new JButton("Change Color"); changeColorButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { color = JColorChooser.showDialog( new ShowColors2(), "Chooes a color",color); //edit if(color == null ) color = Color.LIGHT_GRAY; container.setBackground(color); } } ); container.add(changeColorButton); setSize(400,130); setVisible(true); } public static void main(String args[]) { ShowColors2 application = new ShowColors2(); application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
----------------解决方案--------------------------------------------------------
那个ActionListener 需要头文件
加上头文件 import java.awt.event.*;
----------------解决方案--------------------------------------------------------
自己lj就不要怪编译器嘛~我用JC好好的。实在不会用就用JDK呗
----------------解决方案--------------------------------------------------------
----------------解决方案--------------------------------------------------------