Move (most) hardcoded defaults to MazeDefault
- harcoded values centralized - IntegerField for JTextField containing numbers - fix, can draw even if topleft position is not (0,0) ( ie if scrollbar were used )
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
package org.artisanlogiciel.games.maze.gui.component;
|
||||
|
||||
import org.artisanlogiciel.games.maze.gui.Display;
|
||||
import org.artisanlogiciel.games.maze.gui.MazeDefault;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class IntegerField
|
||||
{
|
||||
JLabel mLabel;
|
||||
JTextField mTextField;
|
||||
long mDefaultValue;
|
||||
|
||||
public IntegerField(String label, long defaultValue)
|
||||
{
|
||||
mDefaultValue = defaultValue;
|
||||
// DEPENDENCY
|
||||
mLabel = new JLabel(MazeDefault.labels.getString(label));
|
||||
mTextField = new JTextField("" + defaultValue);
|
||||
}
|
||||
|
||||
public IntegerField(int defaultValue)
|
||||
{
|
||||
mDefaultValue = defaultValue;
|
||||
mLabel = new JLabel("");
|
||||
mTextField = new JTextField("" + defaultValue);
|
||||
}
|
||||
|
||||
|
||||
public JLabel getLabel()
|
||||
{
|
||||
return mLabel;
|
||||
}
|
||||
|
||||
public JTextField getTextField()
|
||||
{
|
||||
return mTextField;
|
||||
}
|
||||
|
||||
public int getValue()
|
||||
{
|
||||
try {
|
||||
return Integer.parseInt(mTextField.getText());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
mTextField.setText("" + mDefaultValue);
|
||||
}
|
||||
return (int) mDefaultValue;
|
||||
}
|
||||
|
||||
public long getLongValue()
|
||||
{
|
||||
try {
|
||||
return Long.parseLong(mTextField.getText());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
mTextField.setText("" + mDefaultValue);
|
||||
}
|
||||
return (int) mDefaultValue;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
14
java/org/artisanlogiciel/games/maze/gui/component/Panel.java
Normal file
14
java/org/artisanlogiciel/games/maze/gui/component/Panel.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package org.artisanlogiciel.games.maze.gui.component;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class Panel
|
||||
extends JPanel {
|
||||
|
||||
protected void addField(IntegerField pField)
|
||||
{
|
||||
add(pField.getLabel());
|
||||
add(pField.getTextField());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user