Generic JComboBox

This commit is contained in:
Noah
2021-09-29 14:42:13 +02:00
parent e06f61f7eb
commit c7fa4c8e91
7 changed files with 34 additions and 26 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
package v5.draw; package v5.draw;
import v4.gui.GUI; import v5.gui.GUI;
import v5.game.Control; import v5.game.Control;
import javax.swing.*; import javax.swing.*;
+1 -1
View File
@@ -19,7 +19,7 @@ public class Clock extends Thread{
} }
}; };
t.scheduleAtFixedRate(tt, 1, 1); t.scheduleAtFixedRate(tt, 1, 1000);
} }
+3 -1
View File
@@ -3,9 +3,11 @@ package v5.gui;
import v5.draw.Draw; import v5.draw.Draw;
import v5.game.Control; import v5.game.Control;
import javax.swing.*;
import java.awt.*;
public class GUI { public class GUI extends JFrame {
JFrame jf; JFrame jf;
+1 -1
View File
@@ -19,7 +19,7 @@ public class Clock extends Thread{
} }
}; };
t.scheduleAtFixedRate(tt, 1, 1); t.scheduleAtFixedRate(tt, 1, 1000);
} }
+1 -2
View File
@@ -41,16 +41,15 @@ public class Control {
case Task1 -> { case Task1 -> {
generateTask1(); generateTask1();
System.out.println("Taks1");
} }
case Randomized -> { case Randomized -> {
generateRandomized(); generateRandomized();
System.out.println("Random");
} }
case Manuel -> { case Manuel -> {
buildManuelGame(); buildManuelGame();
} }
} }
} }
+1 -1
View File
@@ -2,6 +2,6 @@ package game;
public enum StartMode { public enum StartMode {
Task1, Randomized, Manuel Manuel, Task1, Randomized, Hallo
} }
+26 -19
View File
@@ -35,7 +35,7 @@ public class GUI {
private MouseListener hover; private MouseListener hover;
private JButton randomStart; private JButton startButton;
private JButton manuelStart; private JButton manuelStart;
private ImageIcon preview; private ImageIcon preview;
@@ -195,32 +195,39 @@ public class GUI {
}; };
modeName = new JLabel("Select Figure: "); modeName = new JLabel("Select Figure: ");
modeName.setBounds(50, 270, 200, 30); modeName.setBounds(50, 250, 200, 30);
modeName.setFont(text); modeName.setFont(text);
modeName.setForeground(Color.decode("#121212")); modeName.setForeground(Color.decode("#121212"));
modeName.setVisible(true); modeName.setVisible(true);
modeBox = new JComboBox<String>(); modeBox = new JComboBox<String>();
modeBox.setBounds(180, 270, 100, 20); modeBox.setBounds(180, 257, 100, 20);
addComboBoxEntry(modeBox, "CTTask1"); addComboBoxEntry(modeBox, "CTTask1");
addComboBoxEntry(modeBox, "Randomized"); addComboBoxEntry(modeBox, "Randomized");
randomStart = new JButton(); startButton = new JButton();
randomStart.setText("Start Game"); startButton.setText("Start Game");
randomStart.setFont(text); startButton.setFont(text);
randomStart.setForeground(Color.decode("#121212")); startButton.setForeground(Color.decode("#121212"));
randomStart.setBorderPainted(true); startButton.setBorderPainted(true);
randomStart.setFocusPainted(false); startButton.setFocusPainted(false);
randomStart.setContentAreaFilled(false); startButton.setContentAreaFilled(false);
randomStart.setBounds(50, 320, 150, 50); startButton.setBounds(50, 310, 150, 50);
randomStart.setVisible(true); startButton.setVisible(true);
randomStart.addMouseListener(hover); startButton.addMouseListener(hover);
randomStart.setBorder(new RoundedBorder(25)); startButton.setBorder(new RoundedBorder(25));
randomStart.addActionListener(new ActionListener() { startButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
control.buildGameWindow(xAxisSize, yAxisSize, cellCount, StartMode.Randomized);
StartMode startMethod = StartMode.Task1;
int index = modeBox.getSelectedIndex();
startMethod = StartMode.values()[index + 1]; // + 1 BECAUSE MANUEL HAS THE FIRST INDEX IN ENUM
control.buildGameWindow(xAxisSize, yAxisSize, cellCount, startMethod);
} }
}); });
@@ -231,7 +238,7 @@ public class GUI {
manuelStart.setBorderPainted(true); manuelStart.setBorderPainted(true);
manuelStart.setFocusPainted(false); manuelStart.setFocusPainted(false);
manuelStart.setContentAreaFilled(false); manuelStart.setContentAreaFilled(false);
manuelStart.setBounds(225, 320, 150, 50); manuelStart.setBounds(225, 310, 150, 50);
manuelStart.setVisible(true); manuelStart.setVisible(true);
manuelStart.addMouseListener(hover); manuelStart.addMouseListener(hover);
manuelStart.setBorder(new RoundedBorder(25)); manuelStart.setBorder(new RoundedBorder(25));
@@ -278,7 +285,7 @@ public class GUI {
jf.add(startCells); jf.add(startCells);
jf.add(startCellsName); jf.add(startCellsName);
jf.add(startCellsLabel); jf.add(startCellsLabel);
jf.add(randomStart); jf.add(startButton);
jf.add(manuelStart); jf.add(manuelStart);
jf.add(previewLabel); jf.add(previewLabel);
jf.add(modeName); jf.add(modeName);
@@ -286,7 +293,7 @@ public class GUI {
} }
private void addComboBoxEntry(JComboBox<String> comboBox, String entry){ private void addComboBoxEntry(JComboBox<String> comboBox, String entry) {
comboBox.addItem(entry); comboBox.addItem(entry);
} }