/Users/petercappello/NetBeansProjects/56-2014/56-2014-2-GraphicsVM/src/ControlPanel.java |
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JPanel;
@author
public class ControlPanel extends JPanel
{
private final View view;
private final GVM gvm;
private final JButton runButton = new JButton( "Run" );
private final JButton stepButton = new JButton( "Step" );
ControlPanel( View view, GVM gvm )
{
this.view = view;
this.gvm = gvm;
setLayout( new GridLayout( 1, 2 ) );
add( runButton );
add( stepButton );
initialize();
view.setImage( gvm.getImage() );
gvm.load();
}
private void initialize()
{
runButton.addActionListener( ( ActionEvent actionEvent ) ->
{
runButtonActionPerformed( actionEvent );
});
stepButton.addActionListener( ( ActionEvent actionEvent ) ->
{
stepButtonActionPerformed( actionEvent );
});
}
private void runButtonActionPerformed( ActionEvent actionEvent )
{
gvm.run();
view.repaint();
}
private void stepButtonActionPerformed( ActionEvent actionEvent )
{
gvm.step();
view.repaint();
}
}