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

📄 centermessage.java

📁 JAVA程序设计导论那本书上的一些源代码. 在学那本书的下来的
💻 JAVA
字号:
import javax.swing.*;import java.awt.*;public class CenterMessage extends JPanel {  /** Main method */  public static void main(String[] args) {    JFrame frame = new JFrame("CenterMessage");    CenterMessage m = new CenterMessage();    m.setBackground(Color.white);    m.setFont(new Font("Californian FB", Font.BOLD, 30));    frame.getContentPane().add(m);    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);    frame.setSize(300, 200);    frame.setVisible(true);  }  /** Paint the message */  protected void paintComponent(Graphics g) {    super.paintComponent(g);    // Get font metrics for the current font    FontMetrics fm = g.getFontMetrics();    // Find the center location to display    int stringWidth = fm.stringWidth("Welcome to Java");    int stringAscent = fm.getAscent();    // Get the position of the leftmost character in the baseline    int xCoordinate = getWidth() / 2 - stringWidth / 2;    int yCoordinate = getHeight() / 2 + stringAscent / 2;    g.drawString("Welcome to Java", xCoordinate, yCoordinate);  }}

⌨️ 快捷键说明

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