展开全部
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class test4 {
public test4() {
final JFrame f = new JFrame();
f.setBounds(500, 200, 200, 200);
JButton jb = new JButton("颜色选答散择清圆氏");
f.add(jb, BorderLayout.NORTH);
jb.addActionListener(new 腔乱ActionListener() {
@Override
public void actionPerformed(ActionEvent cc) {
Color ch = JColorChooser.showDialog(f, "颜色选择器",
f.getBackground());
if (ch != null) {
f.getContentPane().setBackground(ch);
f.getContentPane().repaint();
}
}
});
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
public static void main(String[] args) {
new test4();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询