|
-
Jan 22nd, 2010, 09:43 AM
#1
Thread Starter
Addicted Member
[RESOLVED] ? using applet with graphics
If anyone can help. I was experimenting with graphics in java and was trying to get my oval shapes filled with color. The way the program is now. I get the three circles drawn but they do not fill with colors. Also, the lines created with draw lines are not appearing. What am I leaving out or not doing correctly?
Code:
//Program done as an applet
import javax.swing.JApplet;
import java.awt.*;
public class Picture extends JApplet
{
public void paint (Graphics page)
{
setBackground (Color.cyan);
page.setColor (Color.blue);
page.fillOval (75, 65, 60, 60);
page.setColor (Color.green);
page.fillOval (150, 45, 60, 60);
page.setColor (Color.red);
page.fillOval (225, 65, 60, 60);
page.drawline (75, 140, 90, 190);
page.drawline (150, 210, 120, 190);
page.drawline (225, 285, 150, 190);
}
}
-
Jan 22nd, 2010, 06:14 PM
#2
Re: ? using applet with graphics
For a start use Applet instead of JApplet AWT is much better for drawing
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jan 22nd, 2010, 07:46 PM
#3
Thread Starter
Addicted Member
Re: ? using applet with graphics
I used the commands shown in the text example.
I tried with you suggestion and I'm still getting the same results, the ovals arn't filling with the colors. Do you suggest anything else that could be causing it not to work?
Code:
import java.applet.*;
import java.awt.*;
public class Picture extends java.applet.Applet
{
public void paint (Graphics page)
{
setBackground (Color.cyan);
g.setColor (Color.blue);
g.fillOval (75, 65, 60, 60);
g.setColor (Color.green);
g.fillOval (150, 45, 60, 60);
g.setColor (Color.red);
g.fillOval (225, 65, 60, 60);
g.drawline (75, 140, 90, 190);
g.drawline (150, 210, 120, 190);
g.drawline (225, 285, 150, 190);
}
}
-
Jan 23rd, 2010, 04:33 PM
#4
Re: ? using applet with graphics
I don't know how you got your code to compile in the first place. This is your code fixed out of syntax errors. I tried it and it worked fine
Code:
import java.awt.Color;
import java.awt.Graphics;
public class Picture extends java.applet.Applet {
@Override
public void paint(final Graphics g) {
setBackground(Color.cyan);
g.setColor(Color.blue);
g.fillOval(75, 65, 60, 60);
g.setColor(Color.green);
g.fillOval(150, 45, 60, 60);
g.setColor(Color.red);
g.fillOval(225, 65, 60, 60);
g.drawLine(75, 140, 90, 190);
g.drawLine(150, 210, 120, 190);
g.drawLine(225, 285, 150, 190);
}
}
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jan 23rd, 2010, 11:37 PM
#5
Thread Starter
Addicted Member
Re: ? using applet with graphics
Thank you for looking at it. It's good to know it works.
I'm using jGRASP. I must be using the IDE incorrectly. I pasted the code with your corrections and when I debug I get a pop up window that says the class does not appear to be an Applet, continue anyway or cancel. I continue anyway.
then...
The Applet viewer pops up but the display is blank and at the bottom it says "Start: applet not initialized".
this is where I'm at.
-
Jan 24th, 2010, 08:09 AM
#6
Re: ? using applet with graphics
I don't know about jGRASP but it worked on Netbeans. Give it a try, it's a good IDE
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
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
|
Click Here to Expand Forum to Full Width
|