import javax.swing.*;
import java.awt.*;
public class Main {
public Main() {
// 获取屏幕的尺寸
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
Rectangle screenRect = ge.getMaximumWindowBounds();
// 创建主窗口并设置为全屏
JFrame frame = new JFrame();
frame.setSize(screenRect.width, screenRect.height); // 设置为屏幕大小
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setUndecorated(true); // 无窗口装饰(全屏)
frame.setLayout(new BorderLayout());
// 背景图片
JLabel imageLabel = new JLabel();
// 使用相对路径加载背景图片
ImageIcon image = new ImageIcon(getClass().getResource("/img/bj.jpg"));
imageLabel.setIcon(image);
// 使用JLayeredPane管理不同层级的组件
JLayeredPane layeredPane = frame.getLayeredPane();
layeredPane.setLayout(null);
// 将背景图片添加到底层
imageLabel.setBounds(0, 0, screenRect.width, screenRect.height); // 背景图片的大小为屏幕大小
layeredPane.add(imageLabel, Integer.valueOf(0)); // 设置背景层级为最低
// 假设Poke类已经正确实现
Poke e = new Poke();
e.set();
e.v();
e.c();
e.e();
String[][] poke = e.e;
// 创建一个面板来容纳所有玩家的内置窗口
JPanel playerPanel = new JPanel(new GridLayout(2, 2)); // 2行2列的网格布局,玩家面板
playerPanel.setOpaque(false); // 设置playerPanel透明
for (int j = 0; j < 4; j++) {
// 创建一个子面板来容纳每个玩家的卡片
JPanel playerSubPanel = new JPanel();
playerSubPanel.setLayout(new FlowLayout(FlowLayout.LEFT, -50, 5)); // 水平排列,左对齐,间距为5
playerSubPanel.setOpaque(false); // 设置playerSubPanel透明
playerSubPanel.setBorder(BorderFactory.createTitledBorder("玩家" + (j + 1)));
// 添加13张牌
for (int i = 0; i < 13; i++) {
// 使用相对路径加载每张牌的图片
ImageIcon picture = new ImageIcon(getClass().getResource("/img/" + poke[j][i]));
JButton button1 = new JButton(picture);
button1.setBounds(80 + 80 * i, 600, 134, 201);
button1.setPreferredSize(new Dimension(123, 201));
playerSubPanel.add(button1); // 将按钮添加到子面板中
}
playerPanel.add(playerSubPanel);
}
// 将所有玩家面板添加到LayeredPane
playerPanel.setBounds(0, 0, screenRect.width, screenRect.height); // 设置玩家面板位置和大小以占满屏幕
layeredPane.add(playerPanel, Integer.valueOf(1)); // 设置玩家面板的层级为上层
// 显示主窗口
frame.setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}