当前位置: 代码迷 >> Java相关 >> 实在不知道哪里错了
  详细解决方案

实在不知道哪里错了

热度:137   发布时间:2005-09-26 20:40:00.0
实在不知道哪里错了

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呗
----------------解决方案--------------------------------------------------------
以下是引用tempnetbar在2005-9-27 8:28:07的发言: 自己lj就不要怪编译器嘛~我用JC好好的。实在不会用就用JDK呗
谢谢各位大仙了, 偶的确是垃圾啊, 什么都不懂,只懂抄书本上的代码
----------------解决方案--------------------------------------------------------
  相关解决方案