I have try many times but I don't know how to use JColorChooser,
the problem:
Swing contains the class JColorChooser that allows interactive color selections through a dialog box. Draw and fill a Rectangle and let it allow the selection of drawing colors using the JColorChooser class.
I have done one but it does not work properly:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.geom.*;
public class Alban extends JFrame implements ActionListener
{ Color ngjyra = Color.white;
JButton b;
public Alban()
{ b = new JButton("Zgjidh ngjyren");
b.addActionListener(this);
Container content = this.getContentPane();
content.setLayout(new FlowLayout());
content.add(b);
setTitle("Example1");
setSize(400, 450);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setResizable(false);
}
public void actionPerformed(ActionEvent e) {
ngjyra = JColorChooser.showDialog(this,
"Choose Background Color",
getBackground());
repaint();
}
public void paint(Graphics g)
{ Graphics2D g2 = (Graphics2D)g;
int w = this.getWidth();
int h = this.getHeight();
int r = Math.min(w, h)-100;
Area a = new Area(new Rectangle(r, r));
a.subtract(new Area(new Ellipse2D.Double(r/4, r/4, r/2, r/2)));
g2.translate((w-r)/2, (h-r)/2);
g2.setColor(ngjyra);
g2.fill(a);
g2.setColor(Color.black);
g2.draw(a);
}
public static void main(String[] args)
{ Alban f = new Alban();
}
}
I need to send it to my teacher until 23:59 today...
many thnks aRTx.