exercise14_2.java

来自「java程序设计 机械工业出版社 书籍代码」· Java 代码 · 共 42 行

JAVA
42
字号
// Exercise14_2.java: Use parameters in applets
import java.applet.Applet;
import java.awt.*;
import javax.swing.*;

public class Exercise14_2 extends JApplet {
  private String message; // Message to display
  private int x = 20; // Default x coordinate
  private int y = 20; // Default y coordinate
  private String color;
  private String fontName;
  private int fontSize = 20;

  // Initialize the applet
  public void init() {
    // Get parameter values from the HTML file
    message = getParameter("MESSAGE");
    x = Integer.parseInt(getParameter("X"));
    y = Integer.parseInt(getParameter("Y"));
    color = getParameter("COLOR");
    fontName = getParameter("FONTNAME");
    fontSize = Integer.parseInt(getParameter("FONTSIZE"));

    // Create a message panel
    MessagePanel messagePanel = new MessagePanel(message);
    messagePanel.setXCoordinate(x);
    messagePanel.setYCoordinate(y);

    if (color.equals("red")) {
      messagePanel.setForeground(Color.red);
    }
    else if (color.equals("yellow"))
      messagePanel.setForeground(Color.yellow);
    else if (color.equals("green"))
      messagePanel.setForeground(Color.green);

    messagePanel.setFont(new Font(fontName, Font.BOLD, fontSize));

    // Add the message panel to the applet
    getContentPane().add(messagePanel);
  }
}

⌨️ 快捷键说明

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