Results 1 to 3 of 3
- 03-16-2011, 05:49 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 12
- Rep Power
- 0
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
- 03-20-2011, 05:04 PM #2
Member
- Join Date
- Mar 2011
- Location
- chennai
- Posts
- 55
- Rep Power
- 0
what happen when we call the repaint() inside the if that will fill the color or not
-
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
-
Can anyone give a suggestion for the following :
By Manojx in forum New To JavaReplies: 0Last Post: 03-16-2011, 05:41 PM -
Suggestion Regarding SCJD
By ravjot28 in forum Java CertificationReplies: 0Last Post: 12-11-2010, 01:48 PM -
Need suggestion in parsing xml using sax
By Ms.Ranjan in forum XMLReplies: 4Last Post: 09-22-2009, 11:10 PM -
Suggestion needed
By java_newbie in forum NetBeansReplies: 5Last Post: 10-22-2008, 12:45 PM -
Give me some suggestion on wedding story book
By roots in forum Forum LobbyReplies: 1Last Post: 01-10-2008, 04:17 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks