Results 1 to 3 of 3
  1. #1
    Manojx is offline Member
    Join Date
    Mar 2011
    Posts
    12
    Rep Power
    0

    Exclamation Can anyone give a suggestion for the following :

    hi to all

    i'm working on creating a paint application that has 2 buttons circle and RECTANGLE below that empty space appears that enables you to draw one of these shapes as based on the button selected

    for example

    1 ) selects a circle button

    2) circle will be drawn in a space after your mouse movements on the empty area

    so in this i try to create a another check-box in which you select a color to be filled within the shape before your mouse movements so to implement this i was told to create action-listener but it was not working

    as far as i tried something like this for applying color to shape as based on color and the shape is selected
    i have been trying this for last 2 days still could not find anything useful
    and inside action block my codings are as follows

    Code:

    public void actionPerformed(ActionEvent e)
    {

    JComboBox box1 = (JComboBox)e.getSource();
    String Name = (String)cb.getSelectedItem();
    if (Name.equals("GREEN")) && (e.getSource() == bRect)

    g.setColor(0, 0, 255);

    g.fillRect(start.x, start.y, width, height);

    else if (Name.equals("BLUE")) && (e.getSource() == bRect)

    g.setColor(0,0,0);

    g.fillRect(start.x, start.y, width, height);

    return(true);
    } else
    return(false);
    i don't know how to implement this can anyone give me idea

    thnx in advance
    mano

  2. #2
    akiravelmont is offline Member
    Join Date
    Mar 2011
    Location
    bangalore
    Posts
    63
    Rep Power
    0

    Question

    what happen when we call the repaint() inside the if that will fill the color or not

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    The code posted above makes no sense as you should not be messing with Graphics objects inside of the actionPerformed method, and actionPerformed should not return a boolean. I suggest that you read the tutorials on graphics to see how to do simple drawings with Swing. You will want to change the state of class fields (a Color field and perhaps a boolean to tell the program what shape to draw), from within the actionPerformed method and then call repaint() inside of actionPerformed. Then the JPanel's paintComponent method will use the class fields to decide what to draw and what color to use.

Similar Threads

  1. Can anyone give a suggestion for the following :
    By Manojx in forum New To Java
    Replies: 0
    Last Post: 03-16-2011, 06:41 PM
  2. Suggestion Regarding SCJD
    By ravjot28 in forum Java Certification
    Replies: 0
    Last Post: 12-11-2010, 02:48 PM
  3. Need suggestion in parsing xml using sax
    By Ms.Ranjan in forum XML
    Replies: 4
    Last Post: 09-23-2009, 12:10 AM
  4. Suggestion needed
    By java_newbie in forum NetBeans
    Replies: 5
    Last Post: 10-22-2008, 01:45 PM
  5. Give me some suggestion on wedding story book
    By roots in forum Forum Lobby
    Replies: 1
    Last Post: 01-10-2008, 05:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •