drawing on Applet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cozsmin
    New Member
    • Mar 2007
    • 14

    #1

    drawing on Applet

    Hy all,
    i have aproblem, i made a simple applet that works fine at a first glance,
    so i just wanted to add some drawing on it like :

    [CODE=java]
    class Ap extends java.applet.App let {

    java.awt.Graphi cs g;

    public void start() {
    g = getGraphics();
    paint(getGraphi cs());
    getGraphics().d rawString("ok let's get it on !!",53,94);
    }

    public void paint(java.awt. Graphics g) {
    getGraphics().d rawString ("paint()",33,1 20);
    g = getGraphics();
    }
    }
    [/CODE]

    so put this applet in a page and see that it will only paint "paint()" , not what i wrote inside start(), if i did the same with a windowed component like frame/jframe/window it had printed both "ok lt's get it on " and "paint ()"
    and i want to have it done outside paint() as i need adtion triggered paintings, so i cannot rely only on paint

    Kind Regards !
    Last edited by JosAH; Feb 28 '08, 02:16 PM. Reason: fixed the [code] ... [/code] tags
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    What does 'getGraphics()' do and where does it come from?

    kind regards,

    Jos

    Comment

    • cozsmin
      New Member
      • Mar 2007
      • 14

      #3
      Originally posted by JosAH
      What does 'getGraphics()' do and where does it come from?

      kind regards,

      Jos
      well it comes like this.getGraphic s() , u should know that appet derives from container that has getGraphics(), if u do not know what getGraphics does in container then it is bad :)

      Kind Regards

      Comment

      • cozsmin
        New Member
        • Mar 2007
        • 14

        #4
        JosAH i did not mean to be meen :), i now realize that this is not a java specific forum, and i was wrong to assume u knew it all

        kind regards !

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by cozsmin
          JosAH i did not mean to be meen :), i now realize that this is not a java specific forum, and i was wrong to assume u knew it all
          No hard feelings and about that getGraphics() method, I could've looked it up.
          I find it a bit strange though that you're drawing 'on your own'. When I use swing
          I let the AWT thread determine when something needs to be drawn and stick
          the actual drawing functionality somewere in, or derived from the paint (or
          paintComponent) method. I never had to use the getGraphics method, i.e the
          AWT Thread always passes a Graphics object to my paint(Component ) method ...

          kind regards,

          Jos

          Comment

          • BigDaddyLH
            Recognized Expert Top Contributor
            • Dec 2007
            • 1216

            #6
            I suggest:

            1. moving from the old AWT to Swing
            2. Switching from (J)Applets to standalone applications
            3. Taking Sun's Swing tutorial: http://java.sun.com/docs/books/tutor...ing/index.html

            Comment

            Working...