java中如何设置字体样式_如何在JAVA中设置字体样式和大小?

我是新来的Java和无法弄清楚如何格式化我的代码是这样的: 字体“宋体”字体大小“9”大胆如何在JAVA中设置字体样式和大小?

我想整个段落的格式化文本。我真的很感谢帮助。提前致谢!

下面是我的代码:

public class H_1

{

//--------------------------------------------------------------------

// main

//--------------------------------------------------------------------

public static void main (String[] args)

{

Graphics

// Declare variables

// int someInt;

// double someReal;

// String someString;

Scanner keyboard = new Scanner(System.in); // Connect to keyboard

// Show application header

System.out.println("Welcome to my Application!");

System.out.println("--------------------------\n");

// Display output

System.out.println("I'm singing in the rain");

System.out.println("Just singing in the rain");

System.out.println("What a glorious feelin'");

System.out.println("I'm happy again \n");

System.out.println("I'm laughing at clouds");

System.out.println("So dark up above");

System.out.println("The sun's in my heart");

System.out.println("And I'm ready for love \n");

System.out.println("I walk down the lane");

System.out.println("With a happy refrain");

System.out.println("Just singin',");

System.out.println("Singin' in the rain");

// keyboard.nextInt() reads token from keyboard and converts to whole number

// keyboard.nextDouble() reads token from keyboard and converts to real number

// keyboard.next() reads token from keyboard

// keyboard.nextLine() reads line from keyboard through end-of-line character

// Close keyboard

keyboard.close();

// Show application close

System.out.println("\nEnd of my Application");

}

}

2016-09-12

Emma

+0

你想改变你的文本窗口的字体? –

+0

您的意思是在IDE中为代码编辑格式化字体?这将取决于IDE,并且应该为该IDE记录。 –

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.awt.font.*; public class Clipping extends Canvas { public Clipping() { setBackground(Color.white); } public void paint(Graphics g) { Graphics2D g2; g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); int w = getSize().width; int h = getSize().height; FontRenderContext frc = g2.getFontRenderContext(); Font f = new Font("Helvetica",Font.BOLD,w/8); String s = new String("By"); TextLayout tl = new TextLayout(s, f, frc); float sw = (float) tl.getBounds().getWidth(); AffineTransform transform = new AffineTransform(); transform.setToTranslation(w/2-sw/2,h/2); Shape shape = tl.getOutline(transform); g2.setClip(shape); g2.setColor(Color.blue); g2.fill(shape.getBounds()); g2.setColor(Color.yellow); for (int j = shape.getBounds().y; j < shape.getBounds().y + shape.getBounds().height; j=j+3) { Line2D line = new Line2D.Float( 0.0f, (float) j, (float) w, (float) j); g2.draw(line); } } public static void main(String s[]) { WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) {System.exit(0);} public void windowClosed(WindowEvent e) {System.exit(0);} }; Frame f = new Frame("2D Text"); f.addWindowListener(l); f.add("Center", new Clipping()); f.pack(); f.setSize(new Dimension(400, 300)); f.show(); } } *********************************************

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值