【发布时间】:2013-12-31 11:39:46
【问题描述】:
在此之前,我在使用颜色选择器时更改笔的颜色和背景颜色时遇到问题。现在可以更改颜色笔,但背景不能更改颜色。它可以改变背景颜色,但我需要点击绘图区域然后背景会改变..当我们选择颜色时它应该改变背景颜色对吗?但它没有..
按钮面板
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JColorChooser;
import java.awt.Color;
public class ButtonPanel extends JPanel implements ItemListener,
ActionListener
{
private DrawingArea drawingArea;
private String tools[] = {"Pencil", "Line", "Circle", "Rectangle", "Filled Circle", "Filled Rectangle", "Round Rectangle", "Filled Round Rectangle"};
private Color color = (Color.WHITE);
private JComboBox<String> jcbTool;
private JButton btnClear;
private JButton save;
private JButton infobutton;
private JButton colorBtn;
private JButton colorBg;
public void itemStateChanged(ItemEvent ie)
{
if (ie.getSource()==jcbTool)
{
String tool = (String)jcbTool.getSelectedItem();
drawingArea.setTool(tool);
}
// else
// if (ie.getSource()==eraser)
//{ String tool = (String)eraser.getSelectedItem();
// drawingArea.setTool(tool)
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==btnClear)
drawingArea.clear();
else if (e.getSource()==infobutton)
{
//default title and icon
JOptionPane.showMessageDialog(this,"Paint java created by bla bla bla bla bla blaa");
}
else if (e.getSource()==colorBtn)
{
color = JColorChooser.showDialog(null,"LOL",color);
drawingArea.setColorBtn(color);
}
else if (e.getSource()==colorBg)
{
color = JColorChooser.showDialog(null,"LOL",color);
drawingArea.setColorBg(color);
}
}
}
【问题讨论】:
标签: java swing colors background click