JColorChooser程序给出了2个错误

时间:2015-08-31 14:26:07

标签: java swing awt jcolorchooser

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class JColorChooser extends JFrame implements ActionListener
{
JColorChooser()
{
setSize(500,500);
setLayout(new FlowLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
JButton b=new JButton("color");
add(b);
b.addActionListener(this);
setVisible(true);
}

public void ActionPerformed(ActionEvent e)
{
Color initialcolor=Color.WHITE;
Color y=JColorChooser.showDialog(this,"Select a color",initialcolor);
setBackground(y);
}

public static void main(String args[])
{
JColorChooser x=new JColorChooser();
}
}

我收到以下两个错误:

1)。

C:\Users\g0ku\Desktop\New folder\swing>javac JColorChooser.java
JColorChooser.java:5: error: JColorChooser is not abstract and does not override
 abstract method actionPerformed(ActionEvent) in ActionListener
public class JColorChooser extends JFrame implements ActionListener
       ^

2)。

JColorChooser.java:21: error: cannot find symbol
Color y=JColorChooser.showDialog(this,"Select a color",initialcolor);
                     ^
  symbol:   method showDialog(JColorChooser,String,Color)
  location: class JColorChooser
2 errors

1 个答案:

答案 0 :(得分:2)

1

public void ActionPerformed(ActionEvent e)

需要

public void actionPerformed(ActionEvent e)

2。     JFrame没有showDialog方法。我猜你想要这个:

 JOptionPane.showInputDialog();