📄 player.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -