0

This is what I have done so far.

import java.applet.Applet;
import java.awt.*;

public class myFirstAppletRun extends Applet
{public void paint (Graphics page)
{
page.drawLine(100, 0, 100, 600);
page.fillArc(7, 234, 115, 100, -20, 180);
}
}

How would I modify it so that it runs as an applet using Java Graphics2D because i would like to use the BasicStroke method found only in Graphics2D. When I enter BasicStroke method into this current block of code, I get an error. Can someone please modify the code to show me what I would need to do if I would like to make the line and the arc above thicker? Or maybe guide me through the use of casting. (Please note that I have called it Graphics page, and not Graphics g.) Thank you.

user2465406
  • 169
  • 1
  • 1
  • 7
  • 1) Why code an applet? If it is due due to spec. by teacher, please refer them to [Why CS teachers should stop teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). 2) Why AWT rather than Swing? See this answer on [Swing extras over AWT](http://stackoverflow.com/a/6255978/418556) for many good reasons to abandon using AWT components. If you need to support older AWT based APIs, see [Mixing Heavyweight and Lightweight Components](http://www.oracle.com/technetwork/articles/java/mixing-components-433992.html). – Andrew Thompson Jun 09 '13 at 16:23
  • Use a consistent and logical indent for code blocks. The indentation of the code is intended to help people understand the program flow. – Andrew Thompson Jun 09 '13 at 16:23

1 Answers1

1

Use the setStroke-method:

Graphics2D g2 = (Graphics2D) page;
g2.setStroke(new BasicStroke(2));

Result:

import java.applet.Applet;
import java.awt.*;

public class myFirstAppletRun extends Applet
{
    public void paint (Graphics page)
    {
        Graphics2D g2 = (Graphics2D) page;
        g2.setStroke(new BasicStroke(2));
        g2.drawLine(100, 0, 100, 600);
        g2.fillArc(7, 234, 115, 100, -20, 180);
    }
}
mfaerevaag
  • 730
  • 5
  • 29
  • Thank you very much! I compiled and ran it and I got the desired effect. – user2465406 Jun 09 '13 at 16:13
  • 1
    Good to be of help! If you could mark my answer as correct or upvote it, the question doesn't come up as unanswered. You would do me and the rest of the community a favour ;-) – mfaerevaag Jun 09 '13 at 18:15