⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kivahan.java

📁 jbshortcourse
💻 JAVA
字号:
import java.awt.*;

public class KivaHan extends Canvas {

  private String msg;
  private int width, height;

  public KivaHan () {
    this ("Coffee: 10 lira");
  }
  public KivaHan (String s) {
    this (s, 200, 200);
  }
  public KivaHan (String s, int width, int height) {
    msg = s;
    this.width = width;
    this.height = height;
    setForeground (SystemColor.controlText);
    setFont (new Font ("Serif", Font.ITALIC, 24));
    setSize (getPreferredSize());
  }
  public void paint (Graphics g) {
    Dimension d = getSize();
    FontMetrics fm = g.getFontMetrics();
    int len = fm.stringWidth (msg);
    int x = Math.max (((d.width - len) / 2), 0);
    int y = d.height / 2;
    g.drawString (msg, x, y);
  }
  public void setMessage (String s) {
    msg = s;
    repaint();
  }
  public String getMessage () {
    return msg;
  }
  public Dimension getPreferredSize () {
    return new Dimension (width, height);
  }
}

⌨️ 快捷键说明

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