Snake/Java: Difference between revisions
< Snake
Content added Content deleted
m (Fixed syntax highlighting.) |
No edit summary |
||
Line 1: | Line 1: | ||
package zug; |
|||
===Code=== |
|||
{{works with|Java|8}} |
|||
import javax.swing.*; |
|||
<syntaxhighlight lang="java"> |
|||
/***************************************************/ |
|||
/* Sourced By Samuel Dennis */ |
|||
/* */ |
|||
/* Created On (09/01/2019) */ |
|||
/* Last Editied (11/18/2019) */ |
|||
/***************************************************/ |
|||
import java.awt.*; |
import java.awt.*; |
||
import java.awt.event. |
import java.awt.event.KeyAdapter; |
||
import |
import java.awt.event.KeyEvent; |
||
import java. |
import java.awt.event.MouseAdapter; |
||
import java.awt.event.MouseEvent; |
|||
import java.util.ArrayList; |
|||
import java.util.LinkedList; |
|||
import java.util.List; |
import java.util.List; |
||
import |
import java.util.Random; |
||
public class TestCodeSnake extends JPanel implements Runnable { |
|||
enum Dir { |
|||
up(0, -1), right(1, 0), down(0, 1), left(-1, 0); |
|||
Dir(int x, int y) { |
|||
this.x = x; this.y = y; |
|||
} |
|||
final int x, y; |
|||
} |
|||
import static java.lang.String.format; |
|||
static final Random rand = new Random(); |
|||
static final int WALL = -1; |
|||
static final int MAX_ENERGY = 1500; |
|||
public class zug extends JPanel implements Runnable { |
|||
volatile boolean gameOver = true; |
|||
enum Dir { |
|||
up(0, -1), right(1, 0), down(0, 1), left(-1, 0); |
|||
Dir(int x, int y) { |
|||
Thread gameThread; |
|||
this.x = x; this.y = y; |
|||
int score, hiScore; |
|||
} |
|||
int nCols = 64; |
|||
Dir dir; |
|||
int energy; |
|||
int |
final int x, y; |
||
} |
|||
List<Point> snake, treats; |
|||
Font smallFont; |
|||
static final Random rand = new Random(); |
|||
public TestCodeSnake() { |
|||
static final int WAND = -1; |
|||
setPreferredSize(new Dimension(640, 440)); |
|||
setBackground(Color.WHITE); |
|||
volatile boolean gameOver = true; |
|||
setFont(new Font("TimesNewRoman", Font.BOLD, 48)); |
|||
setFocusable(true); |
|||
Thread gameThread; |
|||
int score, highScore; |
|||
smallFont = getFont().deriveFont(Font.BOLD, 18); |
|||
int nRows = 108; |
|||
int nCols = 192; |
|||
Dir dir; |
|||
new MouseAdapter() { |
|||
int[][] wand; |
|||
List<Point> zug, passagiere; |
|||
public void mousePressed(MouseEvent e) { |
|||
Font smallFont; |
|||
startNewGame(); |
|||
public zug() { |
|||
setPreferredSize(new Dimension(1920, 1080)); |
|||
setBackground(Color.darkGray); |
|||
setFont(new Font("Arial", Font.BOLD, 48)); |
|||
setFocusable(true); |
|||
addKeyListener( |
|||
smallFont = getFont().deriveFont(Font.BOLD, 18); |
|||
mauerErzeugen(); |
|||
@Override |
|||
addMouseListener( |
|||
new MouseAdapter() { |
|||
@Override |
|||
public void mousePressed(MouseEvent e) { |
|||
if (gameOver) { |
|||
starteNeuesSpiel(); |
|||
repaint(); |
|||
} |
|||
} |
|||
}); |
|||
addKeyListener( |
|||
new KeyAdapter() { |
|||
@Override |
|||
public void keyPressed(KeyEvent e) { |
|||
switch (e.getKeyCode()) { |
|||
case KeyEvent.VK_UP: |
|||
if (dir != Dir.down) |
|||
dir = Dir.up; |
|||
break; |
|||
case KeyEvent.VK_LEFT: |
|||
if (dir != Dir.right) |
|||
dir = Dir.left; |
|||
break; |
|||
case KeyEvent.VK_RIGHT: |
|||
if (dir != Dir.left) |
|||
dir = Dir.right; |
|||
break; |
|||
case KeyEvent.VK_DOWN: |
|||
if (dir != Dir.up) |
|||
dir = Dir.down; |
|||
break; |
|||
} |
|||
repaint(); |
|||
} |
|||
}); |
|||
} |
|||
public static void zeigeFenster(String text) { |
|||
JFrame fenster = new JFrame("Deutsche Bahn"); |
|||
JLabel label = new JLabel(text); |
|||
dir = Dir.up; |
|||
fenster.getContentPane().add(label); |
|||
case KeyEvent.VK_LEFT: |
|||
fenster.setSize(600, 200); |
|||
break; |
|||
fenster.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|||
case KeyEvent.VK_RIGHT: |
|||
if (dir != Dir.left) |
|||
fenster.setVisible(true); |
|||
} |
|||
case KeyEvent.VK_DOWN: |
|||
void starteNeuesSpiel() { |
|||
gameOver = false; |
|||
break; |
|||
stop(); |
|||
mauerErzeugen(); |
|||
passagiere = new LinkedList<>(); |
|||
dir = Dir.left; |
|||
if (score > highScore) |
|||
highScore = score; |
|||
score = 0; |
|||
zug = new ArrayList<>(); |
|||
for (int x = 0; x < 7; x++) |
|||
zug.add(new Point(nCols / 2 + x, nRows / 2)); |
|||
do |
|||
addPassagiere(); |
|||
while(passagiere.isEmpty()); |
|||
(gameThread = new Thread(this)).start(); |
|||
} |
|||
void stop() { |
|||
if (gameThread != null) { |
|||
Thread tmp = gameThread; |
|||
gameThread = null; |
|||
tmp.interrupt(); |
|||
} |
} |
||
} |
|||
} |
|||
void |
void mauerErzeugen() { |
||
wand = new int[nRows][nCols]; |
|||
for (int r = 0; r < nRows; r++) { |
|||
for (int c = 0; c < nCols; c++) { |
|||
stop(); |
|||
if (c == 0 || c == nCols - 1 || r == 0 || r == nRows - 1) |
|||
initGrid(); |
|||
wand[r][c] = WAND; |
|||
treats = new LinkedList<>(); |
|||
} |
|||
} |
|||
} |
|||
if (score > hiScore) |
|||
hiScore = score; |
|||
score = 0; |
|||
snake = new ArrayList<>(); |
|||
for (int x = 0; x < 7; x++) |
|||
snake.add(new Point(nCols / 2 + x, nRows / 2)); |
|||
do |
|||
addTreat(); |
|||
while(treats.isEmpty()); |
|||
(gameThread = new Thread(this)).start(); |
|||
} |
|||
@Override |
|||
void stop() { |
|||
public void run() { |
|||
Thread tmp = gameThread; |
|||
gameThread = null; |
|||
tmp.interrupt(); |
|||
} |
|||
} |
|||
while (Thread.currentThread() == gameThread) { |
|||
void initGrid() { |
|||
grid = new int[nRows][nCols]; |
|||
for (int r = 0; r < nRows; r++) { |
|||
for (int c = 0; c < nCols; c++) { |
|||
if (c == 0 || c == nCols - 1 || r == 0 || r == nRows - 1) |
|||
grid[r][c] = WALL; |
|||
} |
|||
} |
|||
} |
|||
try { |
|||
@Override |
|||
Thread.sleep(Math.max(75 - score, 25)); |
|||
public void run() { |
|||
} catch (InterruptedException e) { |
|||
return; |
|||
while (Thread.currentThread() == gameThread) { |
|||
} |
|||
try { |
|||
if (trifftWand() || trifftZug() || score == 15) { |
|||
gameOver(); |
|||
} else { |
|||
if (sammeltPassagiereEin()) { |
|||
} |
|||
score++; |
|||
verlängereZug(); |
|||
} |
|||
bewegeZug(); |
|||
addPassagiere(); |
|||
} |
|||
repaint(); |
|||
growSnake(); |
|||
} |
} |
||
} |
|||
addTreat(); |
|||
} |
|||
repaint(); |
|||
} |
|||
} |
|||
boolean |
boolean trifftWand() { |
||
Point head = zug.get(0); |
|||
int nextCol = head.x + dir.x; |
|||
int nextRow = head.y + dir.y; |
|||
} |
|||
return wand [nextRow][nextCol] == WAND; |
|||
} |
|||
boolean |
boolean trifftZug() { |
||
Point head = |
Point head = zug.get(0); |
||
int nextCol = head.x + dir.x; |
int nextCol = head.x + dir.x; |
||
int nextRow = head.y + dir.y; |
int nextRow = head.y + dir.y; |
||
for (Point p : zug) |
|||
return grid[nextRow][nextCol] == WALL; |
|||
if (p.x == nextCol && p.y == nextRow) |
|||
} |
|||
return true; |
|||
return false; |
|||
} |
|||
boolean |
boolean sammeltPassagiereEin() { |
||
Point head = |
Point head = zug.get(0); |
||
int nextCol = head.x + dir.x; |
int nextCol = head.x + dir.x; |
||
int nextRow = head.y + dir.y; |
int nextRow = head.y + dir.y; |
||
for (Point p : |
for (Point p : passagiere) |
||
if (p.x == nextCol && p.y == nextRow) |
if (p.x == nextCol && p.y == nextRow) { |
||
return |
return passagiere.remove(p); |
||
} |
|||
return false; |
|||
} |
|||
} |
|||
void gameOver() { |
|||
gameOver = true; |
|||
zeigeFenster("Gut gemacht ! Der Code für die Bombe ist dein Score: "+score+ " " + "Suche nun nach 2 weiteren NFC Tags !"); |
|||
int nextCol = head.x + dir.x; |
|||
stop(); |
|||
} |
|||
if (p.x == nextCol && p.y == nextRow) { |
|||
return treats.remove(p); |
|||
} |
|||
return false; |
|||
} |
|||
void |
void bewegeZug() { |
||
for (int i = zug.size() - 1; i > 0; i--) { |
|||
gameOver = true; |
|||
Point p1 = zug.get(i - 1); |
|||
Point p2 = zug.get(i); |
|||
} |
|||
p2.x = p1.x; |
|||
p2.y = p1.y; |
|||
} |
|||
Point head = zug.get(0); |
|||
head.x += dir.x; |
|||
head.y += dir.y; |
|||
} |
|||
void |
void verlängereZug() { |
||
Point tail = zug.get(zug.size() - 1); |
|||
int x = tail.x + dir.x; |
|||
int y = tail.y + dir.y; |
|||
zug.add(new Point(x, y)); |
|||
} |
|||
} |
|||
Point head = snake.get(0); |
|||
head.x += dir.x; |
|||
head.y += dir.y; |
|||
} |
|||
void |
void addPassagiere() { |
||
if (passagiere.size() < 10) { |
|||
int x = tail.x + dir.x; |
|||
int y = tail.y + dir.y; |
|||
snake.add(new Point(x, y)); |
|||
} |
|||
if (rand.nextInt(10) == 0) { // 1 in 10 |
|||
void addTreat() { |
|||
if (treats.size() < 3) { |
|||
if (rand.nextInt(10) == 0) { // 1 in 10 |
|||
if (rand.nextInt(4) != 0) { // 3 in 4 |
|||
int x, y; |
|||
while (true) { |
|||
x = rand.nextInt(nCols); |
|||
y = rand.nextInt(nRows); |
|||
if (grid[y][x] != 0) |
|||
continue; |
|||
Point p = new Point(x, y); |
|||
if (snake.contains(p) || treats.contains(p)) |
|||
continue; |
|||
treats.add(p); |
|||
break; |
|||
} |
|||
} else if (treats.size() > 1) |
|||
treats.remove(0); |
|||
} |
|||
} |
|||
} |
|||
if (rand.nextInt(4) != 0) { // 3 in 4 |
|||
void drawGrid(Graphics2D g) { |
|||
int x, y; |
|||
while (true) { |
|||
for (int c = 0; c < nCols; c++) { |
|||
if (grid[r][c] == WALL) |
|||
g.fillRect(c * 10, r * 10, 10, 10); |
|||
} |
|||
} |
|||
} |
|||
x = rand.nextInt(nCols); |
|||
void drawSnake(Graphics2D g) { |
|||
y = rand.nextInt(nRows); |
|||
g.setColor(Color.red); |
|||
if (wand[y][x] != 0) |
|||
for (Point p : snake) |
|||
continue; |
|||
Point p = new Point(x, y); |
|||
g.setColor(energy < 500 ? Color.red : Color.orange); |
|||
if (zug.contains(p) || passagiere.contains(p)) |
|||
Point head = snake.get(0); |
|||
continue; |
|||
g.fillRect(head.x * 10, head.y * 10, 10, 10); |
|||
} |
|||
passagiere.add(p); |
|||
break; |
|||
} |
|||
} else if (passagiere.size() > 1) |
|||
passagiere.remove(0); |
|||
} |
|||
} |
|||
} |
|||
void zeichneWand(Graphics2D g) { |
|||
g.setColor(Color.black); |
|||
for (int r = 0; r < nRows; r++) { |
|||
for (int c = 0; c < nCols; c++) { |
|||
if (wand[r][c] == WAND) |
|||
g.fillRect(c * 10, r * 10, 10, 10); |
|||
} |
|||
} |
|||
} |
|||
void zeichneZug(Graphics2D g) { |
|||
g.setColor(Color.red); |
|||
for (Point p : zug) |
|||
g.fillRect(p.x * 10, p.y * 10, 10, 10); |
|||
Point head = zug.get(0); |
|||
g.fillRect(head.x * 10, head.y * 10, 10, 10); |
|||
} |
|||
void zeichnePassagiere(Graphics2D g) { |
|||
g.setColor(Color.pink); |
|||
for (Point p : passagiere) |
|||
g.fillRect(p.x * 10, p.y * 10, 10, 10); |
|||
} |
|||
void zeichneStartbildschirm(Graphics2D g) { |
|||
g.setColor(Color.white); |
|||
g.setFont(getFont()); |
|||
g.drawString("Sammle die Passagiere ein",650, 250); |
|||
g.setColor(Color.white); |
|||
g.setFont(smallFont); |
|||
g.drawString("Beliebige Maustaste zum Starten drücken", 780, 300); |
|||
} |
|||
void zeichnePunktestand(Graphics2D g) { |
|||
int h = getHeight(); |
|||
g.setFont(smallFont); |
|||
g.setColor(Color.white); |
|||
String s = format("HighScore: %d Score: %d", highScore, score); |
|||
g.drawString(s, 30, h - 30); |
|||
} |
|||
public void paintComponent(Graphics gg) { |
|||
super.paintComponent(gg); |
|||
Graphics2D g = (Graphics2D) gg; |
|||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
|||
RenderingHints.VALUE_ANTIALIAS_ON); |
|||
zeichneWand(g); |
|||
if (gameOver) { |
|||
zeichneStartbildschirm(g); |
|||
} else { |
|||
zeichneZug(g); |
|||
zeichnePassagiere(g); |
|||
zeichnePunktestand(g); |
|||
} |
|||
} |
|||
} |
|||
void drawTreats(Graphics2D g) { |
|||
g.setColor(Color.green); |
|||
for (Point p : treats) |
|||
g.fillRect(p.x * 10, p.y * 10, 10, 10); |
|||
} |
|||
void drawStartScreen(Graphics2D g) { |
|||
g.setColor(Color.red); |
|||
g.setFont(getFont()); |
|||
g.drawString("SNAKE", 240, 190); |
|||
g.setColor(Color.orange); |
|||
g.setFont(smallFont); |
|||
g.drawString("(Click To START)", 250, 240); |
|||
} |
|||
void drawScore(Graphics2D g) { |
|||
int h = getHeight(); |
|||
g.setFont(smallFont); |
|||
g.setColor(getForeground()); |
|||
String s = format("Hi-Score: %d Score: %d", hiScore, score); |
|||
g.drawString(s, 30, h - 30); |
|||
g.drawString(format("Energy: %d", energy), getWidth() - 150, h - 30); |
|||
} |
|||
@Override |
|||
public void paintComponent(Graphics gg) { |
|||
super.paintComponent(gg); |
|||
Graphics2D g = (Graphics2D) gg; |
|||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
|||
RenderingHints.VALUE_ANTIALIAS_ON); |
|||
drawGrid(g); |
|||
if (gameOver) { |
|||
drawStartScreen(g); |
|||
} else { |
|||
drawSnake(g); |
|||
drawTreats(g); |
|||
drawScore(g); |
|||
} |
|||
} |
|||
public static void main(String[] args) { |
|||
SwingUtilities.invokeLater( |
SwingUtilities.invokeLater( |
||
() -> { |
() -> { |
||
JFrame mainFrame = new JFrame(); |
JFrame mainFrame = new JFrame(); |
||
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
||
mainFrame.setTitle(" |
mainFrame.setTitle("Deutsche Bahn"); |
||
mainFrame.setResizable(true); |
mainFrame.setResizable(true); |
||
mainFrame.add(new |
mainFrame.add(new zug(), BorderLayout.CENTER); |
||
mainFrame.pack(); |
mainFrame.pack(); |
||
mainFrame.setLocationRelativeTo(null); |
mainFrame.setLocationRelativeTo(null); |
||
mainFrame.setVisible(true); |
mainFrame.setVisible(true); |
||
}); |
}); |
||
} |
} |
||
} |
|||
}</syntaxhighlight> |
Revision as of 19:45, 21 May 2023
package zug;
import javax.swing.*; import java.awt.*; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Random;
import static java.lang.String.format;
public class zug extends JPanel implements Runnable { enum Dir { up(0, -1), right(1, 0), down(0, 1), left(-1, 0);
Dir(int x, int y) { this.x = x; this.y = y; }
final int x, y; }
static final Random rand = new Random(); static final int WAND = -1;
volatile boolean gameOver = true;
Thread gameThread; int score, highScore; int nRows = 108; int nCols = 192; Dir dir;
int[][] wand; List<Point> zug, passagiere; Font smallFont;
public zug() { setPreferredSize(new Dimension(1920, 1080)); setBackground(Color.darkGray); setFont(new Font("Arial", Font.BOLD, 48)); setFocusable(true);
smallFont = getFont().deriveFont(Font.BOLD, 18); mauerErzeugen();
addMouseListener( new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (gameOver) {
starteNeuesSpiel(); repaint(); } } });
addKeyListener( new KeyAdapter() {
@Override public void keyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_UP: if (dir != Dir.down) dir = Dir.up; break;
case KeyEvent.VK_LEFT: if (dir != Dir.right) dir = Dir.left; break;
case KeyEvent.VK_RIGHT: if (dir != Dir.left) dir = Dir.right; break;
case KeyEvent.VK_DOWN: if (dir != Dir.up) dir = Dir.down; break; } repaint(); } }); }
public static void zeigeFenster(String text) { JFrame fenster = new JFrame("Deutsche Bahn"); JLabel label = new JLabel(text); fenster.getContentPane().add(label); fenster.setSize(600, 200); fenster.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); fenster.setVisible(true); }
void starteNeuesSpiel() { gameOver = false;
stop(); mauerErzeugen(); passagiere = new LinkedList<>();
dir = Dir.left;
if (score > highScore) highScore = score; score = 0;
zug = new ArrayList<>(); for (int x = 0; x < 7; x++) zug.add(new Point(nCols / 2 + x, nRows / 2));
do addPassagiere(); while(passagiere.isEmpty());
(gameThread = new Thread(this)).start(); }
void stop() { if (gameThread != null) { Thread tmp = gameThread; gameThread = null; tmp.interrupt(); } }
void mauerErzeugen() { wand = new int[nRows][nCols]; for (int r = 0; r < nRows; r++) { for (int c = 0; c < nCols; c++) { if (c == 0 || c == nCols - 1 || r == 0 || r == nRows - 1) wand[r][c] = WAND; } } }
@Override public void run() {
while (Thread.currentThread() == gameThread) {
try { Thread.sleep(Math.max(75 - score, 25)); } catch (InterruptedException e) { return; }
if (trifftWand() || trifftZug() || score == 15) { gameOver(); } else { if (sammeltPassagiereEin()) { score++; verlängereZug(); } bewegeZug(); addPassagiere(); } repaint(); } }
boolean trifftWand() { Point head = zug.get(0); int nextCol = head.x + dir.x; int nextRow = head.y + dir.y; return wand [nextRow][nextCol] == WAND; }
boolean trifftZug() { Point head = zug.get(0); int nextCol = head.x + dir.x; int nextRow = head.y + dir.y; for (Point p : zug) if (p.x == nextCol && p.y == nextRow) return true; return false; }
boolean sammeltPassagiereEin() { Point head = zug.get(0); int nextCol = head.x + dir.x; int nextRow = head.y + dir.y; for (Point p : passagiere) if (p.x == nextCol && p.y == nextRow) { return passagiere.remove(p); } return false; }
void gameOver() { gameOver = true; zeigeFenster("Gut gemacht ! Der Code für die Bombe ist dein Score: "+score+ " " + "Suche nun nach 2 weiteren NFC Tags !"); stop(); }
void bewegeZug() { for (int i = zug.size() - 1; i > 0; i--) { Point p1 = zug.get(i - 1); Point p2 = zug.get(i); p2.x = p1.x; p2.y = p1.y; } Point head = zug.get(0); head.x += dir.x; head.y += dir.y; }
void verlängereZug() { Point tail = zug.get(zug.size() - 1); int x = tail.x + dir.x; int y = tail.y + dir.y; zug.add(new Point(x, y)); }
void addPassagiere() { if (passagiere.size() < 10) {
if (rand.nextInt(10) == 0) { // 1 in 10
if (rand.nextInt(4) != 0) { // 3 in 4 int x, y; while (true) {
x = rand.nextInt(nCols); y = rand.nextInt(nRows); if (wand[y][x] != 0) continue;
Point p = new Point(x, y); if (zug.contains(p) || passagiere.contains(p)) continue;
passagiere.add(p); break; } } else if (passagiere.size() > 1) passagiere.remove(0); } } }
void zeichneWand(Graphics2D g) { g.setColor(Color.black); for (int r = 0; r < nRows; r++) { for (int c = 0; c < nCols; c++) { if (wand[r][c] == WAND) g.fillRect(c * 10, r * 10, 10, 10); } } }
void zeichneZug(Graphics2D g) { g.setColor(Color.red); for (Point p : zug) g.fillRect(p.x * 10, p.y * 10, 10, 10);
Point head = zug.get(0); g.fillRect(head.x * 10, head.y * 10, 10, 10); }
void zeichnePassagiere(Graphics2D g) { g.setColor(Color.pink); for (Point p : passagiere) g.fillRect(p.x * 10, p.y * 10, 10, 10); }
void zeichneStartbildschirm(Graphics2D g) { g.setColor(Color.white); g.setFont(getFont()); g.drawString("Sammle die Passagiere ein",650, 250); g.setColor(Color.white); g.setFont(smallFont); g.drawString("Beliebige Maustaste zum Starten drücken", 780, 300); }
void zeichnePunktestand(Graphics2D g) { int h = getHeight(); g.setFont(smallFont); g.setColor(Color.white); String s = format("HighScore: %d Score: %d", highScore, score); g.drawString(s, 30, h - 30);
}
public void paintComponent(Graphics gg) { super.paintComponent(gg); Graphics2D g = (Graphics2D) gg; g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
zeichneWand(g);
if (gameOver) { zeichneStartbildschirm(g); } else { zeichneZug(g); zeichnePassagiere(g); zeichnePunktestand(g); } }
}
public static void main(String[] args) { SwingUtilities.invokeLater( () -> { JFrame mainFrame = new JFrame(); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainFrame.setTitle("Deutsche Bahn"); mainFrame.setResizable(true); mainFrame.add(new zug(), BorderLayout.CENTER); mainFrame.pack(); mainFrame.setLocationRelativeTo(null); mainFrame.setVisible(true); }); }
}