Menue Game Namen

This commit is contained in:
Jonas Dernedde 2021-12-20 09:36:58 +01:00
parent da39719fa4
commit 33edfa8215
4 changed files with 62 additions and 12 deletions

24
src/Tetris/Game.java Normal file
View File

@ -0,0 +1,24 @@
package Tetris;
import javax.swing.*;
public class Game {
public static void main(String[] args) {
Menue menue = new Menue();
menue.getButton().addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
String name = JOptionPane.showInputDialog(menue.getParent(),
"What is your name?", null);
if(name == null){
name = "anon";
}
menue.getParent().setVisible(false);
new GameGui(name);
}
});
//String playername = menue.getName();
//new GameGui(playername);
}
}

View File

@ -8,8 +8,8 @@ public class GameGui {
private JFrame frame;
//Zhe Wang-Holkenbrink
public GameGui(){
frame = new JFrame("Tetris");
public GameGui(String playername){
frame = new JFrame("Tetris " + playername);
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createMatteBorder(500, 10, 10, 50,Color.black));
@ -50,6 +50,6 @@ public class GameGui {
}
public static void main(String [] args)
{
new GameGui();
}
}

View File

@ -7,9 +7,42 @@ import java.awt.*;
public class Menue {
private String name;
private JFrame parent;
public JFrame getParent() {
return parent;
}
public void setParent(JFrame parent) {
this.parent = parent;
}
private JButton button;
public JButton getButton() {
return button;
}
public void setButton(JButton button) {
this.button = button;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Menue(){
JFrame parent = new JFrame("Tetris Menü");
JButton button = new JButton();
parent = new JFrame("Tetris Menü");
button = new JButton();
button.setText("Namen Eingeben");
button.setPreferredSize(new Dimension(400,500));
@ -18,13 +51,6 @@ public class Menue {
parent.pack();
parent.setVisible(true);
button.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
String name = JOptionPane.showInputDialog(parent,
"What is your name?", null);
}
});
}
public static void main(final String[] args) {
new Menue();