473,386 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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
Jul 17 '05 #1
3 8512
"Amey Samant" <am*****@yahoo.com> wrote in message
news:66**************************@posting.google.c om...
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

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.
Jul 17 '05 #2
am*****@yahoo.com (Amey Samant) wrote in message news:<66**************************@posting.google. com>...
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 ?


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:
http://java.sun.com/j2se/1.4.2/docs/...d-bookTOC.html
Jul 17 '05 #3
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 "AffineTransform tutorial" on sun's
site.
and then check transforming Text,Images,Shapes 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(new Color(90,90,180));
at = new AffineTransform();
textAt= new AffineTransform();
textTl= new TextLayout("Game Over!!!", new Font("Helvetica", 1, 46),
new FontRenderContext(null, false, false));
textAt.translate(0, (float)textTl.getBounds().getHeight());
shape= textTl.getOutline(textAt);
}
public void paint(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
Dimension d = getSize();
w = d.width;
h = d.height;

at.setToIdentity();
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(new BasicStroke(2.0f));
g2.transform(at);
g2.setColor(Color.cyan);
g2.fill(shape);
g2.setColor(Color.darkGray);
g2.draw(shape);
}
}
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: timtos | last post by:
I am working on a custom treeView and have some problems with a) node.Bounds.Width b) concatenate strings drawn with DrawString(...) a) I want to highlight a selected node and used the...
1
by: David Lindgren | last post by:
Hello! I am using the DrawString method with different StringAlignments passed to it and the result varies alot! Take a look at this screenshot:...
1
by: Drew | last post by:
I posted this to framework.drawing, but did not get any responses... Maybe here?? I am drawing some text using DrawString() and using a bounding rectangle so that when the string is too long it...
4
by: Geert Gerrits | last post by:
Hi, I'm trying to print a string under an angle. Is there a way to do this ? Thanks.
1
by: Joao | last post by:
Hi, I'm trully excited to use VB.NET's PrintDocument to make my printouts. On them I draw strings, images and lines. All perfect, if I invoke the Print or the PrintPreview one time per run. At...
5
by: johnb41 | last post by:
I need to print out a string of text and obviously i'm using the DrawString command. But the string must be placed AFTER some "programmatically generated text" (also printed using DrawString). ...
2
by: ChrisNightingale | last post by:
Hi everybody, I have an odd issue which I'm not sure how to resolve. I'm basically implementing a print mechanism which takes a series of controls and reproduces them on a print document. So...
2
by: Tony Johansson | last post by:
Hello! If I use the DrawString below with object of StringFormat as the last object it works good. If I instead remove object StringFormat below as the last object of DrawString I get some rows...
9
by: kynos | last post by:
I would like to paint a box using DrawString, standard Unicode characters (box drawings characters) and monospaced font. Unfortunately for some fonts painted lines contain a break. Example...
6
by: Dilip | last post by:
Howdy Folks I have a display where the Graphics.DrawString function is called to display something. Since the text seems to be larger than its bounding rectangle, the call basically splits the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.