Komischer weisse liefern die JTextFields immer die "Startwerte" egal was ich in der GUI eingebe und auch Egal ob ich gleich beim instanzieren die Werte Setze oder nicht. Ansonsten funktioniert alles.
Java:
public class QuadraticColorWaveAdjustmentJPnl extends JPanel implements LandAdjustment
{
private JLabel statesJLbl = new JLabel("States");
private JTextField statesJTxtF = new JTextField();
private JLabel parkettWidthJLbl = new JLabel("Parkett Width");
private JTextField parkettWidthJTxtF = new JTextField();
private JLabel parkettHeightJLbl = new JLabel("Parkett Height");
private JTextField parkettHeightJTxtF = new JTextField();
public QuadraticColorWaveAdjustmentJPnl()
{
this.setLayout(new GridLayout(3,2));
add(statesJLbl);
add(statesJTxtF);
add(parkettWidthJLbl);
add(parkettWidthJTxtF);
add(parkettHeightJLbl);
add(parkettHeightJTxtF);
statesJTxtF.setText("20");
parkettWidthJTxtF.setText("30");
parkettHeightJTxtF.setText("30");
}
@Override
public HashMap<String, Integer> fetchData()
{
HashMap<String, Integer> data = new HashMap<String, Integer>();
int s = Integer.parseInt(statesJTxtF.getText());
data.put("States", s);
int w = Integer.parseInt(parkettWidthJTxtF.getText());
data.put("Parkett Width", w);
int h = Integer.parseInt(parkettHeightJTxtF.getText());
data.put("Parkett Height", h);
data.put("Graphx Space Width", MainJFrm.grphxSpace.width);
data.put("Graphx Space Height", MainJFrm.grphxSpace.height);
System.out.println("*** QCWAdjustmentJPnl ***");
System.out.println("States: " + statesJTxtF.getText());
System.out.println("Parkett Width: " + parkettWidthJTxtF.getText());
System.out.println("Parkett Height: " + parkettHeightJTxtF.getText());
return data;
}
}
public class MainJFrm extends JFrame implements Subjekt
{
private ButtonGroup LandDevelopmentBtnGrp;
private JRadioButton QuadraticGrowLandJRBtn;
private JRadioButton HexagonGrowLandJRBtn;
private JRadioButton QuadraticColorWaveJRBtn;
private JRadioButton HexagonColorWaveJRBtn;
private JPanel controllActionJPnl;
private LandViewJPnl landVJPnl;
private JPanel specificAdjustmentJPnl, chooser, action;
private JButton stopAndContinue, newLand;
private QuadraticColorWaveAdjustmentJPnl qCWAdjustmentJPnl;
private QuadraticGrowLandAdjustmentJPnl qGLAdjustmentJPnl;
private ArrayList<LandAdjustment> whatsup;
private ParkettProducerPrototype ppp;
private QuadraticColorWaveProducer qcwp;
private HashMap<String, Integer> adjustment;
public final static Dimension grphxSpace = new Dimension(800,800);
MainJFrm()
{
LandDevelopmentBtnGrp = new ButtonGroup();
QuadraticColorWaveJRBtn = new JRadioButton("QuadraticColorWave");
QuadraticGrowLandJRBtn = new JRadioButton("QuadraticGrowth");
HexagonColorWaveJRBtn = new JRadioButton("HexagonColorWave");
HexagonGrowLandJRBtn = new JRadioButton("HexagonGrowth");
controllActionJPnl = new JPanel();
landVJPnl = new LandViewJPnl();
this.setLayout(new GridLayout(1,2));
this.add(controllActionJPnl);
this.add(landVJPnl);
specificAdjustmentJPnl = new JPanel();
specificAdjustmentJPnl.setLayout(new GridLayout(1,1));
qCWAdjustmentJPnl = new QuadraticColorWaveAdjustmentJPnl();
specificAdjustmentJPnl.add(qCWAdjustmentJPnl);
chooser = new JPanel();
action = new JPanel();
controllActionJPnl.setLayout(new GridLayout(3,1));
controllActionJPnl.add(chooser);
controllActionJPnl.add(specificAdjustmentJPnl);
controllActionJPnl.add(action);
chooser.setLayout(new GridLayout(4,1));
chooser.add(QuadraticColorWaveJRBtn);
chooser.add(QuadraticGrowLandJRBtn);
chooser.add(HexagonColorWaveJRBtn);
chooser.add(HexagonGrowLandJRBtn);
newLand = new JButton("Neu");
stopAndContinue = new JButton("Stop");
action.setLayout(new GridLayout(1,2));
action.add(newLand);
action.add(stopAndContinue);
LandDevelopmentBtnGrp.add(QuadraticColorWaveJRBtn);
LandDevelopmentBtnGrp.add(QuadraticGrowLandJRBtn);
LandDevelopmentBtnGrp.add(HexagonColorWaveJRBtn);
LandDevelopmentBtnGrp.add(HexagonGrowLandJRBtn);
QuadraticColorWaveJRBtn.setSelected(true);
qCWAdjustmentJPnl = new QuadraticColorWaveAdjustmentJPnl();
qGLAdjustmentJPnl = new QuadraticGrowLandAdjustmentJPnl();
whatsup = new ArrayList<LandAdjustment>();
whatsup.add(qCWAdjustmentJPnl);
whatsup.add(qGLAdjustmentJPnl);
this.setSize(2*grphxSpace.width, grphxSpace.height);
addFunctionality();
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
}
public void addFunctionality()
{
ActionListener qCWAction = (event)->
{
specificAdjustmentJPnl.removeAll();
qCWAdjustmentJPnl = new QuadraticColorWaveAdjustmentJPnl();
specificAdjustmentJPnl.add(qCWAdjustmentJPnl);
validate();
};
QuadraticColorWaveJRBtn.addActionListener(qCWAction);
ActionListener qGLAction = (event)->
{
specificAdjustmentJPnl.removeAll();
qGLAdjustmentJPnl = new QuadraticGrowLandAdjustmentJPnl();
specificAdjustmentJPnl.add(qGLAdjustmentJPnl);//specificAdjustmentJPnl.add(new QuadraticGrowLandAdjustmentJPnl());
validate();
};
QuadraticGrowLandJRBtn.addActionListener(qGLAction);
ActionListener hCWAction = (event)->{};
HexagonColorWaveJRBtn.addActionListener(hCWAction);
ActionListener hGLAction = (event)->{};
HexagonGrowLandJRBtn.addActionListener(hGLAction);
ActionListener landEvent = (event)->
{
if(QuadraticGrowLandJRBtn.isSelected())ppp = null;
if(HexagonGrowLandJRBtn.isSelected())ppp = null;
if(QuadraticColorWaveJRBtn.isSelected())
{
if(ppp!=null)ppp.interrupt();
setAdjustment(0);
ppp = new QuadraticColorWaveProducer(adjustment);
ppp.addBeholders(landVJPnl);
ppp.start();
}
if(HexagonColorWaveJRBtn.isSelected())ppp = null;
};
newLand.addActionListener(landEvent);
}
public void setAdjustment(int adjustmentIndex)
{
adjustment = whatsup.get(adjustmentIndex).fetchData();
}
@Override
public void addBeholders(Beholder b)
{
// TODO Auto-generated method stub
}
@Override
public void removeBeholders(Beholder b)
{
// TODO Auto-generated method stub
}
@Override
public <G> void informBeholders(G g)
{
// TODO Auto-generated method stub
}
}