drawString()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Amey Samant

    drawString()

    hi all

    i need to draw a string diagonally on an applet.
    the scenario is like ....
    i'm writing a game, when a player wins ....i'd like to draw string
    diagonally on the board saying XYZ wins the game or Game Over!!!
    how do i acheive this ?
    any ideas ?

    amey
  • Ryan Stewart

    #2
    Re: drawString()

    "Amey Samant" <ameyas7@yahoo. com> wrote in message
    news:669e50b8.0 312231938.4af88 [email protected] gle.com...[color=blue]
    > hi all
    >
    > i need to draw a string diagonally on an applet.
    > the scenario is like ....
    > i'm writing a game, when a player wins ....i'd like to draw string
    > diagonally on the board saying XYZ wins the game or Game Over!!!
    > how do i acheive this ?
    > any ideas ?
    >
    > amey[/color]
    If you just want some static text like "Game Over", make it a transparent
    GIF and draw it as an Image to your game board.


    Comment

    • Karl von Laudermann

      #3
      Re: drawString()

      [email protected] om (Amey Samant) wrote in message news:<669e50b8. 0312231938.4af8 [email protected] ogle.com>...[color=blue]
      > hi all
      >
      > i need to draw a string diagonally on an applet.
      > the scenario is like ....
      > i'm writing a game, when a player wins ....i'd like to draw string
      > diagonally on the board saying XYZ wins the game or Game Over!!!
      > how do i acheive this ?
      > any ideas ?[/color]

      I know that this can be done using the Java 2D API, but I don't know
      the specifics since I've never used it myself. Take a look at the
      documentation:

      Comment

      • Amey Samant

        #4
        Re: drawString()

        hi Karl
        thanx for the pointer :)
        i went through some of 2D graphics tutorial and found the solution.
        if you want you can search for "AffineTransfor m tutorial" on sun's
        site.
        and then check transforming Text,Images,Sha pes tutorial.
        i did not understand entirely ;) (still working on it ... inner
        details of AffineTransform )
        neways
        i wrote small test applet to see it work. i picked up bare minimum
        required lines from their tutorial code.
        if you are interested ... im posting the code below.
        their tutorial example is just awesome & worth having a look but i
        picked only minimum stuff

        cheers n Merry X'mas
        amey


        import java.awt.*;
        import java.awt.font.* ;
        import java.awt.geom.* ;
        import java.applet.*;

        //<applet code=MyApplet height=300 width=400></applet>
        public class MyApplet extends Applet
        {
        int w,h;
        AffineTransform textAt,at;
        Shape shape;
        TextLayout textTl;

        public void init()
        {
        setBackground(n ew Color(90,90,180 ));
        at = new AffineTransform ();
        textAt= new AffineTransform ();
        textTl= new TextLayout("Gam e Over!!!", new Font("Helvetica ", 1, 46),
        new FontRenderConte xt(null, false, false));
        textAt.translat e(0, (float)textTl.g etBounds().getH eight());
        shape= textTl.getOutli ne(textAt);
        }
        public void paint(Graphics g)
        {
        Graphics2D g2 = (Graphics2D) g;
        Dimension d = getSize();
        w = d.width;
        h = d.height;

        at.setToIdentit y();
        at.translate(w/2, h/2);
        at.rotate(Math. toRadians(315)) ; //315 = -45 degrees angle as 0=360

        Rectangle rect = shape.getBounds ();

        at.translate(-(rect.width/2), -(rect.height/2));

        g2.setStroke(ne w BasicStroke(2.0 f));
        g2.transform(at );
        g2.setColor(Col or.cyan);
        g2.fill(shape);
        g2.setColor(Col or.darkGray);
        g2.draw(shape);
        }
        }

        Comment

        Working...