Zdravím,
potřeboval bych poradit, co dělám blbě při propojení greenfootu se swingem.
Problém je v tom, že jak kliknu na actora, tak se mi pouze zastaví greenfoot, ale neobjeví se okno swingu.
class ZooActor extends Actor {
private Zoo zoo;
private ZooPanel zooPanel;
public ZooActor(Zoo zoo) {
this.zooPanel = new ZooPanel();
this.zoo = zoo;
this.zooPanel.setZoo(zoo);
setImage("images/zoo.png");
}
@Override
public void act() {
if (Greenfoot.mouseClicked(this)) {
Greenfoot.stop();
zooPanel.setZoo(zoo);
SwingUtilities.invokeLater(() -> zooPanel.setVisible(true));
}
}
}
public class ZooPanel extends javax.swing.JPanel {
private static final String MONEY_FORMAT = "%.2f";
public ZooPanel() {
initComponents();
}
Zoo zoo;
public void setZoo(Zoo zoo) {
this.zoo = zoo;
this.updateMoney();
this.zoo.getMoney().addPropertyChangeListener(evt -> updateMoney());
}
private void updateMoney() {
jTextField2.setText(String.format(MONEY_FORMAT, zoo.getMoney().getMoney())
);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jTextField2 = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
addComponentListener(new java.awt.event.ComponentAdapter() {
public void componentHidden(java.awt.event.ComponentEvent evt) {
formComponentHidden(evt);
}
});
jTextField2.setEditable(false);
jLabel1.setText("Money");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(319, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(21, 21, 21)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(138, Short.MAX_VALUE))
);
}// </editor-fold>
private void formComponentHidden(java.awt.event.ComponentEvent evt) {
Greenfoot.start();
}
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JTextField jTextField2;
// End of variables declaration
}
Děkuji.