gpt4 book ai didi

java - JColorChooser 程序出现 2 个错误

转载 作者:行者123 更新时间:2023-11-30 03:17:03 26 4
gpt4 key购买 nike

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.

public void ActionPerformed(ActionEvent e)

需要

public void actionPerformed(ActionEvent e)

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

 JOptionPane.showInputDialog();

关于java - JColorChooser 程序出现 2 个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32313588/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com