Help on changing colour please....

I am doing a paint package that involve scribbling, I have the basic class and I have setted up the windows interface....... I want to allow the user to choose the colour of the line..... I have setted up the button but I am not sure how should I code to set the colour when the button is pressed..... I will leave my codes here......
DrawingTools.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.geom.*;
public class DrawingTools {
public static void main (String [] args) {
     Toolkit tk = Toolkit.getDefaultToolkit(); // get system dependent information
Dimension dim = tk.getScreenSize(); // encapsulate width and height of system
JFrame f = new DrawingToolFrame();
f.setSize(800, 550);
f.setTitle("Drawing Tool v1.10");
f.setIconImage(tk.getImage("Paint.gif"));
f.setVisible(true);
f.setResizable(false);
class DrawingToolFrame extends JFrame implements ActionListener {
private JCheckBox checkNormal, checkBold, checkDotted, checkSpray;
private JButton boldButton, dottedButton, sprayButton;
private JButton blackButton, blueButton, yellowButton, redButton, greenButton, houseButton, tvButton, starButton;
private ScribblePanel scribblePanel;
private JButton scribbleButton, undoButton, newButton, quitButton;
private JMenuItem newItem, quitItem, undoItem, houseItem, tvItem, starItem,/* normalItem,*/ boldItem, dottedItem, sprayItem, blackItem, blueItem, redItem, yellowItem, greenItem;
public DrawingToolFrame() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
Container contentPane = getContentPane();
JMenuBar menuBar = new JMenuBar();
     setJMenuBar(menuBar);
     JMenu fileMenu = new JMenu("File");
     newItem = new JMenuItem("New");
     newItem.setMnemonic(KeyEvent.VK_N); //add Alt-N to New short-cut
     newItem.addActionListener(this);
     fileMenu.add(newItem);
     quitItem = new JMenuItem("Quit");
     quitItem.setMnemonic(KeyEvent.VK_Q); //add Alt-Q to Quit short-cut
     quitItem.addActionListener(this);
     fileMenu.add(quitItem); // some code for menu.......
     menuBar.add(optionMenu);
JPanel p = new JPanel();
ImageIcon scribbleIcon = new ImageIcon("Scribble.gif");
scribbleButton = new JButton("Scribble", scribbleIcon);
scribbleButton.setMnemonic(KeyEvent.VK_S); //add Alt-S to Undo short-cut
scribbleButton.setToolTipText("Click this button and you can draw free hand lines.");
p.add(scribbleButton);
p.add(Box.createHorizontalStrut(20));
ImageIcon undoIcon = new ImageIcon("Undo.gif");
undoButton = new JButton("Undo", undoIcon);
undoButton.setMnemonic(KeyEvent.VK_U); //add Alt-U to Undo short-cut
undoButton.setToolTipText("Undo the last step");
p.add(undoButton);
p.add(Box.createHorizontalStrut(20));
ImageIcon newIcon = new ImageIcon("New.gif");
newButton = new JButton("New", newIcon);
newButton.setMnemonic(KeyEvent.VK_N); //add Alt-N to New short-cut
newButton.setToolTipText("Make a new Drawing");
p.add(newButton);
p.add(Box.createHorizontalStrut(20));
ImageIcon quitIcon = new ImageIcon("Door.gif"); //add icon to button
quitButton = new JButton("Quit", quitIcon);
quitButton.setMnemonic(KeyEvent.VK_Q); //add Alt-Q to exit short-cut
quitButton.setToolTipText("Click to Exit");
p.add(quitButton);
undoButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
scribblePanel.undo();}});
scribbleButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
scribblePanel.repaint();}});
newButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
scribblePanel.repaint();}});
quitButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
System.exit(0);}});
contentPane.add(p, "South");
p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
p.add(Box.createVerticalStrut(10));
ImageIcon boldIcon = new ImageIcon("Bold.gif"); //add icon to button
boldButton = new JButton("Bold", boldIcon);
p.add(boldButton);
p.add(Box.createVerticalStrut(10));
ImageIcon dottedIcon = new ImageIcon("Dotted.gif"); //add icon to button
dottedButton = new JButton("Dotted", dottedIcon);
p.add(dottedButton);
p.add(Box.createVerticalStrut(10));
ImageIcon sprayIcon = new ImageIcon("Spray.gif"); //add icon to button
sprayButton = new JButton("Spray", sprayIcon);
p.add(sprayButton);
contentPane.add(p, "East");
p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
p.add(Box.createVerticalStrut(10));
ImageIcon dIcon = new ImageIcon("Black.gif"); //add icon to button
blackButton = new JButton("Black", dIcon);
p.add(blackButton);
p.add(Box.createVerticalStrut(10));
ImageIcon eIcon = new ImageIcon("Blue.gif"); //add icon to button
blueButton = new JButton("Blue", eIcon);
p.add(blueButton);
p.add(Box.createVerticalStrut(10));
ImageIcon fIcon = new ImageIcon("Red.gif"); //add icon to button
redButton = new JButton("Red", fIcon);
p.add(redButton);
p.add(Box.createVerticalStrut(10));
ImageIcon gIcon = new ImageIcon("Yellow.gif"); //add icon to button
yellowButton = new JButton("Yellow", gIcon);
p.add(yellowButton);
p.add(Box.createVerticalStrut(10));
ImageIcon hIcon = new ImageIcon("Green.gif"); //add icon to button
greenButton = new JButton("Green", hIcon);
p.add(greenButton);
p.add(Box.createVerticalStrut(30));
ImageIcon houseIcon = new ImageIcon("house.gif");
houseButton = new JButton("House", houseIcon);
houseButton.setToolTipText("Click to add a house in the picture!");
p.add(houseButton);
p.add(Box.createVerticalStrut(10));
ImageIcon tvIcon = new ImageIcon("tv.gif");
tvButton = new JButton("Television", tvIcon);
tvButton.setToolTipText("Click to add a Television in the picture!");
p.add(tvButton);
p.add(Box.createVerticalStrut(10));
ImageIcon starIcon = new ImageIcon("star.gif");
starButton = new JButton("Star", starIcon);
starButton.setToolTipText("Click to add stars in the picture!");
p.add(starButton);
contentPane.add(p, "West");
scribblePanel = new ScribblePanel();
contentPane.add(scribblePanel, "Center");
private JButton addJButton(String text, Container container) {
JButton button = new JButton(text);
container.add(button);
return button;
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source instanceof JMenuItem) {
String arg = e.getActionCommand();
if (arg.equals("Undo"))
scribblePanel.undo();
else if (arg.equals("New"))
scribblePanel.repaint();
else if (arg.equals("Quit"))
System.exit(0);
ScribblePanel.java
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.image.BufferedImage;
public class ScribblePanel extends JPanel implements MouseListener, MouseMotionListener {
private int lastX, lastY;
private static final int PANEL_WIDTH = 800;
private static final int PANEL_HEIGHT = 550;
private Stroke stroke;
private Line2D line;
private BufferedImage currImage, oldImage, tmpImage;
public ScribblePanel() {
super();
setBackground(Color.white);
currImage = new BufferedImage(PANEL_WIDTH, PANEL_HEIGHT,
BufferedImage.TYPE_INT_ARGB);
oldImage = new BufferedImage(PANEL_WIDTH, PANEL_HEIGHT,
BufferedImage.TYPE_INT_ARGB);
addMouseListener(this);
addMouseMotionListener(this);
line = new Line2D.Double(0,0,0,0);
stroke = new BasicStroke(10, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND);
public void paintComponent (Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.drawImage(currImage, 0, 0, this);
//scribblePanel.drawAll(g);
public void undo() {
tmpImage = currImage;
currImage = oldImage;
oldImage = tmpImage;
repaint();
public void moveTo(int x, int y) {
lastX = x; lastY = y;
/*public void lineTo(int x, int y) {
Graphics2D g2 = currImage.createGraphics();
line.setLine(lastX, lastY, x, y);
g2.setPaint(Color.blue);
g2.setStroke(stroke);
g2.draw(line);
moveTo(x,y);
g2.dispose();
repaint();
public void lineTo(int x, int y) {
     Graphics2D g2 = currImage.createGraphics();
     line.setLine(lastX, lastY, x, y);
     /*if blueButton pressed
     g2.setPaint(Color.blue);
     else if redButton pressed
     g2.setPaint(Color.red);
     else if yellowButton pressed
     g2.setPaint(Color.yellow);
     else if greenButton pressed
     g2.setPaint(Color.green);
     else g2.setPaint(Color.black);*/
     /*if boldButton pressed
     g2.setStroke(stroke);
     else if dottedButton pressed
     g2.setStroke(dotted);
     else if sprayButton pressed
     g2.setStroke(spray);*/ // these are my imagination...... i knoe they
// are wrong but what should I do?????please
// help
     g2.setPaint(Color.blue);
     g2.draw(line);moveTo(x,y);
g2.dispose();
repaint();
public void mousePressed(MouseEvent e) {
     oldImage.setData(currImage.getData());
moveTo(e.getX(), e.getY());
public void mouseReleased(MouseEvent e) {}
public void mouseClicked(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseDragged(MouseEvent e) {
lineTo(e.getX(), e.getY());
public void mouseMoved(MouseEvent e) {}
BTW...... if I want to use the SetStroke (for thicker line, dotted line) method in the Graphics2D package what should i do?????

Two obvious routes: 1. Have a variable currentColor or somesuch which you set when the user clicks a button. Then before drawing the line call g.setColor(currentColor). 2. If you have access to the Graphics object when the button is clicked, call setColor directly.

Similar Messages

  • Help needed changing colour for each top Parent menu bar

    Can anyone help me I need the change the background of each
    parent menu block. with the child block keeping the same colour.
    but having a tint of the same colour in hover state.

    Can anyone help me I need the change the background of each
    parent menu block. with the child block keeping the same colour.
    but having a tint of the same colour in hover state.

  • Need some help with the colour profile please. Urgent! Thanks

    Dear all, I need help with the colour profile of my photoshop CS6. 
    I've taken a photo with my Canon DSLR. When I opened the raw with ACDSee, the colour looks perfectly ok.
    So I go ahead and open in photoshop. I did nothing to the photo. It still looks ok
    Then I'm prompt the Embedded Profile Mismatch error. I go ahead and choose Discard the embedded profile option
    And the colour started to get messed up.
    And the output is a total diasater
    Put the above photo side by side with the raw, the red has became crimson!!
    So I tried the other option, Use the embedded profile
    The whole picture turns yellowish in Photoshop's interface
    And the output is just the same as the third option.
    Could someone please guide me how to fix this? Thank you.

    I'm prompt the Embedded Profile Mismatch error. I go ahead and choose Discard the embedded profile option
    always use the embedded profile when opening tagged images in Photoshop - at that point Photoshop will convert the source colors over to your monitor space correctly
    if your colors are wrong at that point either your monitor profile is off, or your source colors are not what you think they are - if other apps are displaying correctly you most likely have either a defective monitor profile or source profile issues
    windows calibrate link:
    http://windows.microsoft.com/en-US/windows7/Calibrate-your-display
    for Photoshop to work properly, i recall you want to have "use my settings for this device" checked in Color Management> Device tab
    you may want to download the PDI reference image to check your monitor and print workflows
    and complete five easy steps to profile enlightenment in Photoshop
    with your settings, monitor profile and source profiles sorted out it should be pretty easy to pinpoint the problem...

  • Tried all 6steps to Error Message: An error has occurred when attempting to change modules-Please help thx

    Tried all 6steps to Error Message: An error has occurred when attempting to change modules-Please help thx

    Hi, I¹ve been through it again to ensure I¹ve not forgot things. Completely
    removed Lightroom and all files I can find, etc and reloaded. Some tedious
    result. Step 6 is too time consuming at the moment for me, too many things
    on the go since I¹m about to go on holiday and on return I shall need
    Lightroom on this iMac. Any clues? This iMac had Mavericks from new,
    uploaded to Yosemite and then loaded Photoshop CC, Lightroom etc and get
    this damned problem.
    Reading around the web I¹m not the only one with this issue, to suggest a
    new user a/c is a soft option without resolving the issue.
    I hope an expert from Adobe can resolve this,
    Regards, George (retired IT Manager and IT Systems Project Manager)

  • When trying to download or sync podcasts, I get an error code "you do not have the privilege to make changes". Please help!

    When trying to download or sync podcasts, I get an error code "you do not have the privilege to make changes". Please help! I tried uninstalling iTunes and reinstalling, but that did not work. Also, I rebooted and that didn't work, either.

    I tried to use an external hard drive from my windows computer that was formatted in NTFS Windows format.  Mac Pro sees that hard drive as "read only".  Itunes works on existing media on the hard drive to play music or movies, but when you try to purchase from itunes store and download you get the above message.  You need to move your library to a library that is formatted in exFAT format (which can be used both by "windows" and mac computers. 

  • Hello, I have been exporting my photos with a watermark. Without changing any settings, half way through my day things changed, and now about 1 out of 7 photos have the watermark after export. Change you helpe me change this back please?

    Hello, I have been exporting my photos with a watermark. Without changing any settings, half way through my day things changed, and now about 1 out of 7 photos have the watermark after export. Change you help me change this back please? Has anyone had this issue before?

        I'm sorry to learn that you have endured the audio issues outlined in your post for almost 2 years SusanLM1! This is certainly not normal! Let's get to the bottom of this issue, first please confirm your phone model; your mention that you have the iPhone 5 but your post is on the iPhone 5S forum. Also, share the iOS version currently installed on your phone. What is your ZIP code? Does this happen mainly while you make/receive calls from a particular location (home, office, etc)?
    AntonioC_VZW Follow us on Twitter at www.twitter.com/VZWSupport

  • In my 4s display option doesn't come to change colours when I go to Setting-General. I am bored with blue colour. Please advise.

    In my 4s display option doesn't come to change colours when I go to Setting-General. I am bored with blue colour. Please advise.

    Go to Settings > Wallpapers & Brightness.

  • HT1386 my iphone does not sync with itunes on my second authorized computer, please help. i changed the first authorized computer in May 2012 and have been using the second authorized computer since then but it cannot sync - please help!!

    my iphone does not sync with itunes on my second authorized computer, please help. i changed the first authorized computer in May 2012 and have been using the second authorized computer since then but it cannot sync - please help!!

    "I was thinking I would just connect my iPhone and all of my music and other stuff would transfer to the new computer. "
    Not true. The music and pic sync is one way - computer to iphone. The only exception is itunes purchases. Without syncing: File>Transfer Purchases
    You really should transfer everything from the old computer, or your backup copy of your computer. Since you do not have access to the old computer, then use your backup copy of the old computer.
    If for some reason you have failed to maintain a backup copy of your computer ( not good), then you would have to transfer itunes purchased as described earlier. Any other itunes content would be lost.
    You can e-mail photo library pics to yourself, but they will not be of the original quality.
    Before syncing, enter at least one unique contact and calendar entry on the computer. When you first sync, then you should get the option to merge the data.

  • When I play games in Mozilla on fb..some setting changed and now the pop up window that appears to send gifts to my friends only lists 3 ppl at a time some games i have a scroll down button others i dont..can u help m fix this please?

    When I play games in Mozilla on fb..some setting changed and now the pop up window that appears to send gifts to my friends only lists 3 ppl at a time some games i have a scroll down button others i dont..can u help m fix this please?

    Hi Winnie
    Unfortunately I have been sick and did not read the message before. I apologize.
    I have not received help beyond what is on the page. But when I get I tell you.
    I hope you can get answers. If you receive, I ask that you share with me.
    thank you very much
    best regards
    AC
    Date: Mon, 27 Feb 2012 09:33:10 -0700
    From: [email protected]
    To: [email protected]
    Subject: Pop up Window before saving remembering the need (forcing) to fill required fields in a form
        Re: Pop up Window before saving remembering the need (forcing) to fill required fields in a form
        created by Win_Form in Forms - View the full discussion
    Hi ACI wonder if you can share any responses on to your question above?I too have never used a script but, I have the same problems as you in regards to building a form. And wants to have the same 'protection' and message reminders for the end users. Any information, including a script and/or a contact email of experts you can share with me will help tremendously. Thank you so much in advance. Winnie
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4232307#4232307
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4232307#4232307. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in Forms by email or at Adobe Forums
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • I bought the ilife '11 iphoto upgrade.  It was supposed to update my library.  It has been 2 days and it is still loading. I have tried restarting with no change. Please help!

    I bought the ilife '11 iphoto upgrade.  It was supposed to update my library.  It has been 2 days and it is still loading. I have tried restarting with no change. Please help!

    Make a back up now.
    Most Simple Back Up
    Drag the iPhoto Library from your Pictures Folder to another Disk. This will make a copy on that disk.
    Slightly more complex:
    Use an app that will do incremental back ups. This is a very good way to work. The first time you run the back up the app will make a complete copy of the Library. Thereafter it will update the back up with the changes you have made. That makes subsequent back ups much faster. Many of these apps also have scheduling capabilities: So set it up and it will do the back up automatically. Examples of such apps: Chronosync or DejaVu . But are many others. Search on MacUpdate
    Then go on to Option 2
    Regards
    TD

  • Hi, I need someone to help me change the login screen. The computer I have is a macbook, its second hand and probably around 3-4 years old. The previous owner had the login screen has a lego or something. Could someone please help me change this??

    Hi, I need someone to help me change the login screen. The computer I have is a macbook, its second hand and probably around 3-4 years old. The previous owner had the login screen has a lego or something. Could someone please help me change this??

    computerilliterate52 wrote:
    hi all, i hope someone is very computer litterate about java that is i have a dell 2400 pc windows xp 2, well since msn isnt downloading anymore java updates we all have to download a compatible one to our computer i use explorer and i can play www.iwin.com online games, yet when i go on to the msn browswer it wont load the games all i see is it just trying to load and load nothing said and nothing done. what could be wrong it works on ie and not msn browser? i have zone alarm, i have avg spyware tester and spyblaster, but i thought it may of kept me from downloading all this yet it worked on IE please help and i dont have flash player either it wont seem to work any and i mean any help is welcome.i tried to change the browser settings and did all that stuff i am on broadband DSL and they dont seem to know they say that isnt there job its msn's so i asked them and they said no it is quest broadband since i am with them i just get the run around i have IE 6.0 ihave java plug in 1.4.2. o3 yet it says not verified, i have java 1.6.o o1 i have java plugin 1.6.0 01 i have that twice ? dont know why. and java envirinmemet i have the right stuff cuz like i said it plays or works on explorer not msn browserer bar. i see no picture's in center of the page as it tries to load it is a blank page any help thank you i have been trying going on 3 weeks now thanksI agree with the other posters; try Firefox. It sounds like a bit of a mess and what you may need is an onsite PC tech to do some maintenance on your PC.
    Also, learning to properly use punctuation (particularly periods) might not be a bad idea. As it is, your post was very hard to read.
    Good luck!

  • HT201240 Please Help me change my Mac Os X password!

    I have no account app in my system preferences. Therefor there is no way I know to change my account password. Please Help!

    Changing or resetting an account password
    When you say you
    I have no account app in my system preferences. Therefor there is no way I know to change my account password.
    Is the icon pictured below missing from your System Preferences?
    If that is the case, I'd try this.
    1. With System Prefernces closed, locate the file;
    ~/Library/Preferences/com.apple.systempreferences.plist
    and trash it.
    Restart your Mac.

  • When I boot into Win7 I see the windows boot up logo, the. I see my mouse and the screen goes black! It goes black in the login screen, I type my password and I hear the login sound but when I press F2 the brightness won't change! Please help!!!

    When I boot into Win7 I see the windows boot up logo, the. I see my mouse and the screen goes black! It goes black in the login screen, I type my password and I hear the login sound but when I press F2 the brightness won't change! Please help!!!

    Hi Emma,
    Thank you for using Apple Support Communities. 
    I understand that your Thunderbolt display is just showing a black screen when you boot your computer. The following article should be of help in troubleshooting your display. 
    Apple computers: Troubleshooting issues with video on internal or external displays - Apple Support
    Cheers, 
    Jeff D. 

  • On Calendar, I have tried to change the "Day starts at" and "Day ends at" many times however, it just does not seem to change. Please help.

    On Calendar, I have tried to change the "Day starts at" and "Day ends at" many times however, it just does not seem to change. Please help.
    This for Calendar on my Mac which of course effects my iPhone and iPad.
    I don't need to see the hours from 1 am to 6 am
    Please help!

    Well, assuming all of the above, Notifications, etc., it just might be time for a visit to the Apple tore genius center for a session with the techs.  See if it is a fault in the hardware or just an iOS reinstall is the answer.
    One more thing you could try, backup so you have a record of content, then restore to factory conditions be an Erase All Contents and Settings.  Then restore from the backup you just made.  That has helped some with WiFi problems, may be it would work with your problems.
    But with that behavior of another app with problems, the geniuses looks like a less stressful thing to do.

  • I need to need help with changing my app store to canada to us but i have 49cents balance can you remove it please

    I need to need help with changing my app store to canada to us but i have 49cents balance can you remove it please

    Contact iTunes Support - http://apple.com/emea/support/itunes/contact.html - and ask them to clear your balance.

Maybe you are looking for

  • CD not playing from both speakers

    iTunes - when I burn a CD I can play it on my computer, however, when I play it in a boombox cd player, I only hear one speaker. Other CD's are fine. It is not the boombox. I think I may be saving file or converting improperly. Any thoughts?

  • Urgent! Hard Drive Disappeared!

    Events: This afternoon I needed to boot the computer because it became unresponsive. As before everytime I boot the computer it does stay in the gray screen with apple logo. As always I tried to enter in Safe Mode, it did not work. I did the PRAM and

  • Re: Another complaint ignored by BT!!

    I too have logged 2 complaints with nothing done BT is very ignorant and rude and tell so many lies i am also fed up with them and would never recommend them to anyone x

  • Corrupt data error when using Windows backup on Oracle

    Our SAP servers include a SDLT internal tape drive that we use for doing a complete system backup.  When using Windows Backup we get the following message in the backup log: WARNING: Portions of "\oracle\T00\sapdata1\protd_2\PROTD.DATA2" cannot be re

  • Important licensing question for Adobe CS6 Production Premium (Student-Licensing)

    Hello dear Community! I have a very small film production and live in a flat share with students as my roommates. One of my associates is a good friend of mine and is also very interested in movie- and film-editing. He also asked me what softwares ar