Contol Windwo Update. Velocity Change implemented. FONT and some other Var and method needs to be implemented in the GUI class not in Menu Window
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
package gui;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class ControlWindow {
|
||||
|
||||
@@ -13,6 +14,12 @@ public class ControlWindow {
|
||||
private JFrame controlWindow;
|
||||
private JButton toggleGame;
|
||||
|
||||
private int maxVelocity = 1 , minVelocity = 10000;
|
||||
|
||||
private JSlider velocitySlider;
|
||||
private JLabel velocitySliderName;
|
||||
private JTextField velocitySliderLabel;
|
||||
|
||||
private GUI gui;
|
||||
|
||||
public ControlWindow(GameWindow gameWindow, GUI gui, int offset) {
|
||||
@@ -51,6 +58,7 @@ public class ControlWindow {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
gui.setRunning(!gui.isRunning());
|
||||
updateToggleButton();
|
||||
setVelocity(100);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -59,6 +67,71 @@ public class ControlWindow {
|
||||
|
||||
}
|
||||
|
||||
private void initVelocity(Font text){
|
||||
velocitySlider = new JSlider(minVelocity, maxVelocity);
|
||||
velocitySlider.setBounds(180, 110, 200, 20);
|
||||
velocitySlider.setFont(text);
|
||||
velocitySlider.setForeground(Color.decode("#121212"));
|
||||
velocitySlider.setValue(6);
|
||||
velocitySlider.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
if(!sliderLocked) {
|
||||
xAxisSize = velocitySlider.getValue();
|
||||
updateSliderLabels(0, xAxisSize);
|
||||
updateStartCells();
|
||||
}
|
||||
}
|
||||
});
|
||||
velocitySlider.setVisible(true);
|
||||
|
||||
|
||||
xAxisName = new JLabel("Breite in Zellen:");
|
||||
xAxisName.setBounds(50, 100, 200, 30);
|
||||
xAxisName.setFont(text);
|
||||
xAxisName.setForeground(Color.decode("#121212"));
|
||||
xAxisName.setVisible(true);
|
||||
|
||||
xAxisLabel = new JTextField("6");
|
||||
xAxisLabel.setBackground(null);
|
||||
xAxisLabel.setBorder(null);
|
||||
xAxisLabel.setBounds(180, 80, 200, 30);
|
||||
xAxisLabel.setFont(text);
|
||||
xAxisLabel.setForeground(Color.decode("#121212"));
|
||||
xAxisLabel.setVisible(true);
|
||||
xAxisLabel.addKeyListener(new KeyAdapter() {
|
||||
public void keyTyped(KeyEvent evt) {
|
||||
if (!Character.isDigit(evt.getKeyChar())) {
|
||||
evt.consume();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
xAxisLabel.getDocument().addDocumentListener(new DocumentListener() {
|
||||
@Override
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
|
||||
sliderLocked = true;
|
||||
String s = xAxisLabel.getText();
|
||||
velocitySlider.setValue(Integer.parseInt(s));
|
||||
xAxisSize = velocitySlider.getValue();
|
||||
updateStartCells();
|
||||
sliderLocked = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUpdate(DocumentEvent e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void setVisibility(boolean value) {
|
||||
controlWindow.setVisible(value);
|
||||
}
|
||||
@@ -75,4 +148,8 @@ public class ControlWindow {
|
||||
controlWindow.dispose();
|
||||
}
|
||||
|
||||
|
||||
public void setVelocity(int velocity){
|
||||
gui.setVelocity(velocity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,9 @@ public class GUI {
|
||||
return menuWindow;
|
||||
}
|
||||
|
||||
public void setVelocity(int velocity){
|
||||
control.setVelocity(velocity);
|
||||
}
|
||||
|
||||
//TODO: Delet this Methods. Those are shit.
|
||||
public void setVisibility(boolean value){
|
||||
|
||||
@@ -41,6 +41,7 @@ public class GameWindow {
|
||||
gui.getControlWindow().dispose();
|
||||
}
|
||||
gameWindow.dispose();
|
||||
gui.setRunning(false);
|
||||
gui.getMenuWindow().setVisibility(true);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user