• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to use a canvas class

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello friend
I have a project in j2me and I'm totally lost so i wish someone could help me
well it's how to use the( Canvas )class for change the font in j2me
this is the class

class FontCanvas extends Canvas {
private Font mSystemFont, mMonospaceFont, mProportionalFont;

public FontCanvas() {
this(Font.STYLE_PLAIN);
}

public FontCanvas(int style) {
setStyle(style);
}

public void setStyle(int style) {
mSystemFont = Font.getFont(Font.FACE_SYSTEM, style, Font.SIZE_MEDIUM);
mMonospaceFont = Font.getFont(Font.FACE_MONOSPACE, style, Font.SIZE_MEDIUM);
mProportionalFont = Font.getFont(Font.FACE_PROPORTIONAL, style, Font.SIZE_MEDIUM);
}


public void paint(Graphics g) {
int w = getWidth();
int h = getHeight();

int x = w/2 ;
int y = 40;

y += showFont(g, "HELLO THISE IS MY PROG.", x, y, mSystemFont);
y += showFont(g, "HELLO THISE IS MY PROG.", x, y, mMonospaceFont);
y += showFont(g, "HELLO THISE IS MY PROG.", x, y, mProportionalFont);
}

private int showFont(Graphics g, String s, int x, int y, Font f) {
g.setFont(f);
g.drawString(s, x, y, Graphics.TOP | Graphics.HCENTER);

return f.getHeight();
}
}

my question is how could I make this class change the font for any word pass from MIDlet class(another class) ?
I mean in this code it's only change the font for "HELLO THISE IS MY PROG." sentence
what is the changes that I should do it on this class to make it change the font for any word according to my request(the word i send to it)?
and I'll be thankful for you all
my regards
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A "canvas" is just a rectangular area that you can do raw graphics in. So you can't really do "smart" things using a Canvas like tell the text output functions to shift fonts for certain words.

When you paint into a canvass, what you get is exactly what you tell it to paint and no more and no less.
 
Amy konan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well this will change whole my project
any way thank you Tim
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic