-
AWT colour chooser and paint
Hi, this is quite simple but I don't know how to do it, please help!
The following code should do the following: click in a colour, and paint with the chosen colour .. I cannot make it paint with the colour I choose 
import java.awt.*;
import java.awt.event.*;
public class E3Events
extends Frame
implements MouseListener, MouseMotionListener
{
Color colorActual;
public static void main(String[] args)
{
E3Events e3 = new E3Events();
e3.setTitle("Paint");
e3.setSize(500, 500);
e3.addMouseListener(e3);
e3.addMouseMotionListener(e3);
e3.show();
}
public void paint(Graphics g)
{
g.setColor(Color.GREEN);
g.fillRect(0, 0, 100, 100);
g.setColor(Color.YELLOW);
g.fillRect(100, 0, 100, 100);
g.setColor(Color.RED);
g.fillRect(200, 0, 100, 100);
g.setColor(Color.ORANGE);
g.fillRect(300, 0, 100, 100);
g.setColor(Color.BLUE);
g.fillRect(400, 0, 100, 100);
}
public void mouseDragged(MouseEvent e)
{
Graphics g = getGraphics();
g.setColor(colorActual);
int x = e.getX();
int y = e.getY();
g.fillOval(x, y, 10, 10);
}
public void mouseClicked(MouseEvent e)
{
}
/**
* @see java.awt.event.MouseListener#mouseEntered(MouseEvent)
*/
public void mouseEntered(MouseEvent arg0)
{
}
/**
* @see java.awt.event.MouseListener#mouseExited(MouseEvent)
*/
public void mouseExited(MouseEvent arg0)
{
}
/**
* @see java.awt.event.MouseListener#mousePressed(MouseEvent)
*/
public void mousePressed(MouseEvent arg0)
{
}
/**
* @see java.awt.event.MouseListener#mouseReleased(MouseEvent)
*/
public void mouseReleased(MouseEvent arg0)
{
}
/**
* @see java.awt.event.MouseMotionListener#mouseMoved(MouseEvent)
*/
public void mouseMoved(MouseEvent arg0)
{
}
Thanks a million in advance
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks