Загрузка данных
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
public class Main {
// Цвета интерфейса
static final Color BACKGROUND = new Color(3, 10, 20);
static final Color PANEL = new Color(5, 17, 32);
static final Color PANEL_LIGHT = new Color(7, 24, 43);
static final Color BLUE = new Color(35, 180, 255);
static final Color GREEN = new Color(40, 220, 130);
static final Color RED = new Color(255, 55, 90);
static final Color TEXT = new Color(220, 235, 250);
static final Color SECONDARY = new Color(120, 170, 210);
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
JFrame window = new JFrame("Dota 2 Stats");
window.setSize(1400, 850);
window.setMinimumSize(new Dimension(1100, 700));
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setLocationRelativeTo(null);
MainPanel mainPanel = new MainPanel();
window.setContentPane(mainPanel);
window.setVisible(true);
});
}
// ==========================================
// ГЛАВНАЯ ПАНЕЛЬ
// ==========================================
static class MainPanel extends JPanel {
MainPanel() {
setBackground(BACKGROUND);
setLayout(new BorderLayout());
add(new HeaderPanel(), BorderLayout.NORTH);
JPanel teams = new JPanel();
teams.setBackground(BACKGROUND);
teams.setLayout(new BoxLayout(teams, BoxLayout.Y_AXIS));
teams.setBorder(new EmptyBorder(10, 15, 15, 15));
teams.add(new TeamPanel(
"THE RADIANT",
true,
createRadiantPlayers()
));
teams.add(Box.createVerticalStrut(12));
teams.add(new TeamPanel(
"THE DIRE",
false,
createDirePlayers()
));
JScrollPane scrollPane = new JScrollPane(teams);
scrollPane.setBorder(null);
scrollPane.getVerticalScrollBar().setUnitIncrement(20);
add(scrollPane, BorderLayout.CENTER);
}
}
// ==========================================
// ВЕРХНЯЯ ПАНЕЛЬ
// ==========================================
static class HeaderPanel extends JPanel {
HeaderPanel() {
setPreferredSize(new Dimension(100, 75));
setBackground(new Color(2, 8, 17));
setLayout(new BorderLayout());
JLabel title = new JLabel(" DOTA 2 STATS");
title.setForeground(TEXT);
title.setFont(new Font("Segoe UI", Font.BOLD, 28));
JLabel score = new JLabel(
"СЧЁТ 28 - 22 ",
SwingConstants.RIGHT
);
score.setForeground(BLUE);
score.setFont(new Font("Segoe UI", Font.BOLD, 25));
add(title, BorderLayout.WEST);
add(score, BorderLayout.EAST);
}
}
// ==========================================
// КОМАНДА
// ==========================================
static class TeamPanel extends JPanel {
TeamPanel(
String teamName,
boolean radiant,
List<Player> players
) {
setLayout(new BorderLayout());
setBackground(PANEL);
setBorder(
BorderFactory.createLineBorder(
radiant ? BLUE : RED,
1
)
);
JPanel teamHeader = new JPanel(
new BorderLayout()
);
teamHeader.setBackground(
radiant
? new Color(4, 35, 55)
: new Color(45, 8, 20)
);
teamHeader.setBorder(
new EmptyBorder(10, 15, 10, 15)
);
JLabel name = new JLabel(teamName);
name.setForeground(
radiant ? BLUE : RED
);
name.setFont(
new Font(
"Segoe UI",
Font.BOLD,
22
)
);
JLabel result = new JLabel(
radiant
? " ПОБЕДА "
: " "
);
result.setForeground(GREEN);
result.setFont(
new Font(
"Segoe UI",
Font.BOLD,
14
)
);
teamHeader.add(name, BorderLayout.WEST);
teamHeader.add(result, BorderLayout.EAST);
add(teamHeader, BorderLayout.NORTH);
JPanel content = new JPanel();
content.setBackground(PANEL);
content.setLayout(
new BoxLayout(
content,
BoxLayout.Y_AXIS
)
);
// Заголовки колонок
content.add(
new ColumnHeader()
);
// Игроки
for (int i = 0; i < players.size(); i++) {
content.add(
new PlayerRow(
i + 1,
players.get(i),
radiant
)
);
}
add(content, BorderLayout.CENTER);
}
}
// ==========================================
// ЗАГОЛОВКИ
// ==========================================
static class ColumnHeader extends JPanel {
ColumnHeader() {
setMaximumSize(
new Dimension(
Integer.MAX_VALUE,
38
)
);
setPreferredSize(
new Dimension(100, 38)
);
setBackground(
new Color(4, 15, 28)
);
setLayout(
new GridLayout(1, 7)
);
add(label("#"));
add(label("ИГРОК"));
add(label("РАНГ"));
add(label("ПОСЛЕДНИЕ МАТЧИ"));
add(label("МАТЧЕЙ"));
add(label("WINRATE"));
add(label("САМЫЕ ЧАСТЫЕ ГЕРОИ"));
}
JLabel label(String text) {
JLabel label = new JLabel(
text,
SwingConstants.CENTER
);
label.setForeground(BLUE);
label.setFont(
new Font(
"Segoe UI",
Font.BOLD,
13
)
);
return label;
}
}
// ==========================================
// ИГРОК
// ==========================================
static class PlayerRow extends JPanel {
PlayerRow(
int number,
Player player,
boolean radiant
) {
setMaximumSize(
new Dimension(
Integer.MAX_VALUE,
78
)
);
setPreferredSize(
new Dimension(100, 78)
);
setBackground(
new Color(4, 14, 27)
);
setBorder(
BorderFactory.createMatteBorder(
0,
0,
1,
0,
new Color(15, 45, 70)
)
);
setLayout(
new GridLayout(1, 7)
);
// Номер
JLabel numberLabel =
new JLabel(
String.valueOf(number),
SwingConstants.CENTER
);
numberLabel.setForeground(SECONDARY);
numberLabel.setFont(
new Font(
"Segoe UI",
Font.BOLD,
15
)
);
// Игрок
JPanel playerPanel =
new JPanel(
new FlowLayout(
FlowLayout.LEFT,
8,
10
)
);
playerPanel.setOpaque(false);
JLabel avatar =
new JLabel(
player.heroIcon
);
avatar.setPreferredSize(
new Dimension(50, 50)
);
avatar.setHorizontalAlignment(
SwingConstants.CENTER
);
avatar.setOpaque(true);
avatar.setBackground(
new Color(15, 45, 70)
);
JPanel playerInfo =
new JPanel();
playerInfo.setOpaque(false);
playerInfo.setLayout(
new BoxLayout(
playerInfo,
BoxLayout.Y_AXIS
)
);
JLabel playerName =
new JLabel(
player.name
);
playerName.setForeground(TEXT);
playerName.setFont(
new Font(
"Segoe UI",
Font.BOLD,
15
)
);
JLabel lane =
new JLabel(
player.lane
);
lane.setForeground(SECONDARY);
lane.setFont(
new Font(
"Segoe UI",
Font.PLAIN,
12
)
);
playerInfo.add(playerName);
playerInfo.add(lane);
playerPanel.add(avatar);
playerPanel.add(playerInfo);
// Ранг
JPanel rankPanel =
new JPanel(
new FlowLayout(
FlowLayout.CENTER,
8,
10
)
);
rankPanel.setOpaque(false);
JLabel rankIcon =
new JLabel(
player.rankIcon
);
rankIcon.setPreferredSize(
new Dimension(50, 50)
);
rankIcon.setHorizontalAlignment(
SwingConstants.CENTER
);
rankIcon.setOpaque(true);
rankIcon.setBackground(
new Color(20, 30, 45)
);
JLabel rank =
new JLabel(
player.rank
);
rank.setForeground(BLUE);
rank.setFont(
new Font(
"Segoe UI",
Font.BOLD,
13
)
);
rankPanel.add(rankIcon);
rankPanel.add(rank);
// Последние матчи
JPanel recent =
new JPanel(
new FlowLayout(
FlowLayout.CENTER,
5,
18
)
);
recent.setOpaque(false);
for (String result : player.recentMatches) {
JLabel match =
new JLabel(result);
match.setHorizontalAlignment(
SwingConstants.CENTER
);
match.setPreferredSize(
new Dimension(30, 30)
);
match.setOpaque(true);
if (result.equals("W")) {
match.setBackground(
new Color(10, 100, 65)
);
match.setForeground(GREEN);
} else {
match.setBackground(
new Color(100, 20, 35)
);
match.setForeground(RED);
}
match.setFont(
new Font(
"Segoe UI",
Font.BOLD,
12
)
);
recent.add(match);
}
// Матчи
JLabel matches =
new JLabel(
String.valueOf(
player.matches
),
SwingConstants.CENTER
);
matches.setForeground(TEXT);
matches.setFont(
new Font(
"Segoe UI",
Font.BOLD,
14
)
);
// Winrate
JPanel winrate =
new JPanel();
winrate.setOpaque(false);
winrate.setLayout(
new BoxLayout(
winrate,
BoxLayout.Y_AXIS
)
);
JLabel winrateText =
new JLabel(
player.winrate + "%"
);
winrateText.setForeground(
player.winrate >= 55
? GREEN
: player.winrate < 50
? RED
: BLUE
);
winrateText.setFont(
new Font(
"Segoe UI",
Font.BOLD,
15
)
);
winrateText.setAlignmentX(
Component.CENTER_ALIGNMENT
);
JProgressBar bar =
new JProgressBar(
0,
100
);
bar.setValue(
player.winrate
);
bar.setPreferredSize(
new Dimension(130, 8)
);
bar.setMaximumSize(
new Dimension(130, 8)
);
bar.setBorderPainted(false);
bar.setForeground(
player.winrate >= 55
? GREEN
: player.winrate < 50
? RED
: BLUE
);
bar.setBackground(
new Color(15, 35, 55)
);
winrate.add(winrateText);
winrate.add(Box.createVerticalStrut(5));
winrate.add(bar);
// Частые герои
JPanel heroes =
new JPanel(
new FlowLayout(
FlowLayout.CENTER,
6,
12
)
);
heroes.setOpaque(false);
for (String hero : player.frequentHeroes) {
JLabel heroIcon =
new JLabel(hero);
heroIcon.setPreferredSize(
new Dimension(42, 42)
);
heroIcon.setHorizontalAlignment(
SwingConstants.CENTER
);
heroIcon.setOpaque(true);
heroIcon.setBackground(
new Color(20, 50, 70)
);
heroIcon.setForeground(TEXT);
heroes.add(heroIcon);
}
add(numberLabel);
add(playerPanel);
add(rankPanel);
add(recent);
add(matches);
add(winrate);
add(heroes);
}
}
// ==========================================
// ДАННЫЕ ИГРОКА
// ==========================================
static class Player {
String name;
String lane;
String rank;
String heroIcon;
String rankIcon;
int matches;
int winrate;
List<String> recentMatches;
List<String> frequentHeroes;
Player(
String name,
String lane,
String rank,
int matches,
int winrate,
String heroIcon,
String rankIcon,
String recent,
String heroes
) {
this.name = name;
this.lane = lane;
this.rank = rank;
this.matches = matches;
this.winrate = winrate;
this.heroIcon = heroIcon;
this.rankIcon = rankIcon;
this.recentMatches =
new ArrayList<>();
for (
char c :
recent.toCharArray()
) {
recentMatches.add(
String.valueOf(c)
);
}
this.frequentHeroes =
new ArrayList<>();
for (
char c :
heroes.toCharArray()
) {
frequentHeroes.add(
String.valueOf(c)
);
}
}
}
// ==========================================
// RADIANT
// ==========================================
static List<Player> createRadiantPlayers() {
List<Player> players =
new ArrayList<>();
players.add(
new Player(
"Akatalyio",
"⚔ Off Lane",
"Immortal",
206,
47,
"⚔",
"★",
"WWLWWW",
"ABC"
)
);
players.add(
new Player(
"w",
"⚔ Safe Lane",
"Divine I",
68,
76,
"◆",
"★",
"WLWWLW",
"DEF"
)
);
players.add(
new Player(
"Choki",
"⚔ Mid Lane",
"Ancient III",
347,
44,
"◆",
"★",
"LWWWLW",
"GHI"
)
);
players.add(
new Player(
"Papi chulko",
"♟ Hard Support",
"Legend II",
1259,
51,
"◆",
"★",
"WWLWWW",
"JKL"
)
);
players.add(
new Player(
"Player 5",
"◈ Support",
"Ancient V",
586,
59,
"◆",
"★",
"WLWWWL",
"MNO"
)
);
return players;
}
// ==========================================
// DIRE
// ==========================================
static List<Player> createDirePlayers() {
List<Player> players =
new ArrayList<>();
players.add(
new Player(
"MrPle@sant",
"⚔ Mid Lane",
"Divine II",
1509,
50,
"◆",
"★",
"WLWWLW",
"PQR"
)
);
players.add(
new Player(
"Kira",
"⚔ Off Lane",
"Legend I",
577,
51,
"◆",
"★",
"WWLWWL",
"STU"
)
);
players.add(
new Player(
"ENERU",
"⚔ Mid Lane",
"Immortal",
904,
60,
"◆",
"★",
"LWWLWW",
"VWX"
)
);
players.add(
new Player(
"Traxex",
"⚔ Safe Lane",
"Legend III",
133,
51,
"◆",
"★",
"WLWWWL",
"YZA"
)
);
players.add(
new Player(
"Player 10",
"♟ Hard Support",
"Ancient IV",
1251,
48,
"◆",
"★",
"WLLWWL",
"BCD"
)
);
return players;
}
}