Question subject: need help in changing the color of a graph
Posted: Sun Oct 31, 2010 7:39 pm
Joined: Sun Oct 31, 2010 7:17 pm Posts: 3 Has thanked: 0 time Have thanks: 0 time
Hi, I really need help in changing the color of a 3d graph. We were given the code of the graph and asked to change its color and also shape by adding checkboxes. I am a beginner at java so I learned how to use checkboxes by example and did a program that give different shape and different colors using checkboxes and it work. Unfortunately, I couldn’t make it work for the given code. I don’t know what is the problem. Here is the given code:
for ( j = 0; j < edges.length; ++j ) { g.drawLine( points[ edges[j].a ].x, points[ edges[j].a ].y, points[ edges[j].b ].x, points[ edges[j].b ].y ); } } public void mouseEntered( MouseEvent e ) { } public void mouseExited( MouseEvent e ) { } public void mouseClicked( MouseEvent e ) { } public void mousePressed( MouseEvent e ) { mx = e.getX(); my = e.getY(); e.consume(); } public void mouseReleased( MouseEvent e ) { } public void mouseMoved( MouseEvent e ) { } public void mouseDragged( MouseEvent e ) { // get the latest mouse position int new_mx = e.getX(); int new_my = e.getY(); // adjust angles according to the distance travelled by the mouse // since the last event azimuth -= new_mx - mx; elevation += new_my - my; // update the backbuffer drawWireframe( backg ); // update our data mx = new_mx; my = new_my; repaint(); e.consume(); }
@Override public void update( Graphics g ) { g.drawImage( backbuffer, 50, 50, this ); showStatus("Elev: "+elevation+" deg, Azim: "+azimuth+" deg"); }
@Override public void paint( Graphics g ) { update( g ); }
public void paint1(Graphics g) { if (radio1.getState()) g.setColor(Color.red); else if (radio2.getState()) g.setColor(Color.blue); else g.setColor(Color.green); if (shape1.getState()) g.drawRect(70,70 , 80, 100); else if (shape2.getState()) g.drawOval(70, 70, 100, 100); else g.drawRect(60,60,100,100); } public void actionPerformed(ActionEvent evt, Graphics g) { if (evt.getSource() == okButton) paint1(g); } }
I added the paint1 and actionperformed methods to the code. Please let me know how to fix it. Thank you and take care.
msi_333
Question subject: Re: need help in changing the color of a graph
Posted: Mon Nov 01, 2010 11:32 am
Joined: Tue Mar 27, 2007 10:55 pm Posts: 2279 Location: Earth Has thanked: 39 time Have thanks: 61 time
you all ready changing it here :
Code:
if (radio1.getState()) g.setColor(Color.red); else if (radio2.getState()) g.setColor(Color.blue); else g.setColor(Color.green);
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )
Laila
Question subject: Re: need help in changing the color of a graph
Posted: Mon Nov 01, 2010 5:03 pm
Joined: Sun Oct 31, 2010 7:17 pm Posts: 3 Has thanked: 0 time Have thanks: 0 time
Hi there, thanks for your response. It should work but it is not! I dont know y I still cant change the color of the graph. Did u try it? If yes then does the color change? Thank you again and take care.
msi_333
Question subject: Re: need help in changing the color of a graph
Posted: Tue Nov 02, 2010 10:51 pm
Joined: Tue Mar 27, 2007 10:55 pm Posts: 2279 Location: Earth Has thanked: 39 time Have thanks: 61 time
Are you sure from the conditions like
if (radio1.getState())
because my be else g.setColor(Color.green);
is the case always running .
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )
Laila
Question subject: Re: need help in changing the color of a graph
Posted: Wed Nov 03, 2010 12:01 am
Joined: Sun Oct 31, 2010 7:17 pm Posts: 3 Has thanked: 0 time Have thanks: 0 time
Yes I am sure cause I tried the following code and it did work: import java.awt.*; import java.applet.*; import java.awt.event.*; public class Buttons extends Applet implements ActionListener {
If you run it then u can see that both shapes and the colors are changing but when using the same code for the given 3d graph it did not? If you notice in this part: public class Buttons extends Applet implements ActionListener
There is an ActionListener but in the first code I coudlnt add it to the public class WireframeViewer, if I did then i will get some error.