center.java

来自「Java 入门书的源码」· Java 代码 · 共 25 行

JAVA
25
字号
//Copyright (c) 1998, Arthur Gittleman
//This example is provided WITHOUT ANY WARRANTY either expressed or implied.

// Debuging Exercise 7.8 -- Has Errors

              import java.awt.*;
              import java.applet.Applet;
              public class Center extends Applet {
                  Font f;
                  String s;
                  int x, w; 
                  public void init() {
                      f = new Font("Monospaced",Font.PLAIN,18);
                      setFont(f);
                      FontMetrics metrics = getFontMetrics(f);
                      s = f.getName(); 
                      w = metrics.stringWidth(s);
                  }
                  public void paint(Graphics g) {
                      Dimension d = getSize();
                      int x = w-d.height;
                      g.drawString(s,x,50);
                  }
              }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?