Compare commits
8 Commits
1f983b68ad
...
2e42de650d
| Author | SHA1 | Date |
|---|---|---|
|
|
2e42de650d | |
|
|
54453eba45 | |
|
|
582a03178d | |
|
|
987bd867c8 | |
|
|
42bbdf3e43 | |
|
|
af8c068fce | |
|
|
6baea13c56 | |
|
|
aa28f64c4f |
|
|
@ -1,5 +1,126 @@
|
|||
package de.hs_mannheim.informatik.chess.gui;
|
||||
|
||||
public class Gui {
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Insets;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
public class Gui {
|
||||
|
||||
private JLabel[][] fields = new JLabel[8][8];
|
||||
|
||||
public Gui(){
|
||||
mainFrame();
|
||||
}
|
||||
|
||||
|
||||
public JFrame mainFrame() {
|
||||
JFrame frame = new JFrame();
|
||||
frame.setSize(1600, 1000);
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.add(mainPanel());
|
||||
|
||||
frame.setDefaultCloseOperation(2);
|
||||
frame.setVisible(true);
|
||||
return frame;
|
||||
}
|
||||
|
||||
public JPanel mainPanel() {
|
||||
JPanel mainPanel = new JPanel(new GridBagLayout());
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
mainPanel.setBackground(new Color(0xe0e1dd));
|
||||
// Links (Schach)
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 0;
|
||||
gbc.weightx = 0.6;
|
||||
gbc.weighty = 1.0;
|
||||
gbc.insets = new Insets(5, 5, 5, 0);
|
||||
//oben, links, unten, rechts
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
mainPanel.add(chessPanel(boardPanel()),gbc);
|
||||
|
||||
// Rechts (Stats)
|
||||
gbc.gridx = 1;
|
||||
gbc.gridy = 0;
|
||||
gbc.weightx = 0.4;
|
||||
gbc.weighty = 1.0;
|
||||
gbc.insets = new Insets(5, 0, 5, 5);
|
||||
//oben, links, unten, rechts
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
mainPanel.add(statsPanel(), gbc);
|
||||
|
||||
return mainPanel;
|
||||
}
|
||||
|
||||
public JPanel boardPanel() {
|
||||
JPanel boardPanel = new JPanel(new GridLayout(8, 8));
|
||||
boardPanel.setPreferredSize(new Dimension(800, 800));
|
||||
|
||||
for (int row = 0; row < 8; row++) {
|
||||
|
||||
for (int col = 0; col < 8; col++) {
|
||||
|
||||
JLabel label = new JLabel("", SwingConstants.CENTER);
|
||||
label.setOpaque(true);
|
||||
label.setFont(new Font("Serif", Font.BOLD, 40));
|
||||
if ((row + col) % 2 == 0) {
|
||||
label.setBackground(new Color(0x778da9));
|
||||
} else {
|
||||
label.setBackground(new Color(0xe0e1dd));
|
||||
}
|
||||
fields[row][col] = label; // <-- Save the label
|
||||
boardPanel.add(label);
|
||||
|
||||
}
|
||||
}
|
||||
boardPanel.setBackground(new Color(0x1b263b));
|
||||
return boardPanel;
|
||||
}
|
||||
|
||||
public JPanel chessPanel(JPanel panel) {
|
||||
JPanel chessPanel = new JPanel(new GridBagLayout());
|
||||
GridBagConstraints board = new GridBagConstraints();
|
||||
chessPanel.setBackground(new Color(0x1b263b));
|
||||
board.gridx = 0;
|
||||
board.gridy = 0;
|
||||
board.weightx = 0.7;
|
||||
board.weighty = 1.0;
|
||||
board.insets = new Insets(0, 0, 0, 0);
|
||||
//oben, links, unten, rechts
|
||||
board.fill = GridBagConstraints.BOTH;
|
||||
chessPanel.add(panel);
|
||||
return chessPanel;
|
||||
}
|
||||
|
||||
public JPanel statsPanel() {
|
||||
JPanel statsPanel = new JPanel();
|
||||
statsPanel.setBackground(new Color(0x0d1b2a));
|
||||
return statsPanel;
|
||||
}
|
||||
|
||||
public JLabel getField(int row, int col) {
|
||||
return fields[row][col];
|
||||
}
|
||||
|
||||
public void updateBoard(String[][] unicodeBoard) {
|
||||
for (int row = 0; row < 8; row++) {
|
||||
for (int col = 0; col < 8; col++) {
|
||||
fields[row][col].setText(unicodeBoard[row][col]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void displayMessage(String msg) {
|
||||
JOptionPane.showMessageDialog(null, msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,9 @@
|
|||
package de.hs_mannheim.informatik.chess.main;
|
||||
import de.hs_mannheim.informatik.chess.gui.Gui;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
public class Main
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
System.out.println( "Hello World!" );
|
||||
public class Main{
|
||||
|
||||
public static void main( String[] args ){
|
||||
new Gui();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue