服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

实现阴影、镂空、离散等特种文字效果


  如何实现阴影、镂空、离散等特种文字效果?
  
   下面是从http://www.javaworld.com/javaworld/javatips/jw-javatip81.html 得到
   的一些实现特种文字效果的代码片断。感兴趣的网友可以自己去看原文。
  
   // shadow
   g.setcolor(new color(50, 50, 50));
   g.drawstring("shadow", shifteast(x, 2), shiftsouth(y, 2));
   g.setcolor(new color(220, 220, 220));
   g.drawstring("shadow", x, y);
  
   // engrave
   g.setcolor(new color(220, 220, 220));
   g.drawstring("engrave", shifteast(x, 1), shiftsouth(y, 1));
   g.setcolor(new color(50, 50, 50));
   g.drawstring("engrave", x, y);
  
   file://outline
   g.setcolor(color.red);
   g.drawstring("outline", shiftwest(x, 1), shiftnorth(y, 1));
   g.drawstring("outline", shiftwest(x, 1), shiftsouth(y, 1));
   g.drawstring("outline", shifteast(x, 1), shiftnorth(y, 1));
   g.drawstring("outline", shifteast(x, 1), shiftsouth(y, 1));
   g.setcolor(color.yellow);
   g.drawstring("outline", x, y);
  
   file://hollow
   g.setcolor(color.black);
   g.drawstring("hollow", shiftwest(x, 1), shiftnorth(y, 1));
   g.drawstring("hollow", shiftwest(x, 1), shiftsouth(y, 1));
   g.drawstring("hollow", shifteast(x, 1), shiftnorth(y, 1));
   g.drawstring("hollow", shifteast(x, 1), shiftsouth(y, 1));
   g.setcolor(bg);
   g.drawstring("hollow", x, y);
  
   file://segment
   int w = (g.getfontmetrics()).stringwidth("segment");
   int h = (g.getfontmetrics()).getheight();
   int d = (g.getfontmetrics()).getdescent();
   g.setcolor(new color(220, 220, 220));
   g.drawstring("segment", x, y);
   g.setcolor(bg);
   for (int i = 0; i < h; i += 3)
   g.drawline(x, y + d - i, x + w, y + d - i);
  
   file://3d effects
   color top_color = new color(200, 200, 0);
   color side_color = new color(100, 100, 0);
   for (int i = 0; i < 5; i++)
   {
   g.setcolor(top_color);
   g.drawstring("3-dimension", shifteast(x, i), shiftnorth(shiftsouth(y, i), 1));
   g.setcolor(side_color);
   g.drawstring("3-dimension", shiftwest(shifteast(x, i), 1), shiftsouth(y, ii));
   }
   g.setcolor(color.yellow);
   g.drawstring("3-dimension", shifteast(x, 5), shiftsouth(y, 5));
  
   file://motion
   for (int i = 0; i < 20; i++)
   {
   font_size = 12 + i;
   g.setfont(new font("timesroman", font.plain, font_size));
   w = (g.getfontmetrics()).stringwidth("motion");
   g.setcolor(new color(0, 65 + i * 10, 0));
   g.drawstring("motion", (width - w) / 2, shiftsouth(y, speed * i));
   }

扫描关注微信公众号