player.java

来自「Usefull sample codes for Java. Containt 」· Java 代码 · 共 44 行

JAVA
44
字号
import java.awt.*;
import javax.swing.*;

public class Player extends JFrame {
    public Player() {
        super("Player");
        setSize(294, 396);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        PlayerPanel fp = new PlayerPanel();
        add(fp);
        setVisible(true);
    }

    public static void main(String[] arguments) {
        Player frame = new Player();
    }
}

class PlayerPanel extends JPanel {
    public PlayerPanel() {
        ImageIcon player = new ImageIcon("johnny-evers-1913.jpg");
        JLabel playerLabel = new JLabel(player);
        add(playerLabel);
    }
    
    public void paintComponent(Graphics comp) {
        super.paintComponent(comp);
        Graphics2D comp2D = (Graphics2D)comp;
        comp2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
        int width = getSize().width;
        int height = getSize().height;
        Font currentFont = new Font("Dialog", Font.BOLD, 18);
        comp2D.setFont(currentFont);
        comp2D.drawString("JOHNNY EVERS", width - 155, height - 50);
        currentFont = new Font("Dialog", Font.ITALIC, 12);
        comp2D.setFont(currentFont);
        comp2D.drawString("second baseman", width - 155, height - 30);
        currentFont = new Font("Dialog", Font.PLAIN, 12);
        comp2D.setFont(currentFont);
        comp2D.drawString("CHICAGO CUBS", width - 155, height - 10);
    }
}

⌨️ 快捷键说明

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