Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hello, I am trying to find a way to update the sliders by getting the updated information from the model class. Class with sliders: public
Hello, I am trying to find a way to update the sliders by getting the updated information from the model class.
Class with sliders: public class GoneFishingView extends JFrame
private JLabel labelTry;
private JLabel labelFish;
private JPanel fishingPanel;
private JPanel fishingSliderPanel;
private JSlider fishingSlideTry;
private JSlider fishingSlideFish;
private JPanel instructionsPanel;
private JLabel instructionLabel;
private GoneFishingModel model;
public GoneFishingViewGoneFishingModel model
this.model model;
updateUI;
setTitleFishing Game";
setDefaultCloseOperationJFrameEXITONCLOSE;
this.setLayoutnew BorderLayout;
instructionsPanel new JPanel;
instructionLabel new JLabelClick on the buttons to fish";
instructionsPanel.addinstructionLabel;
addinstructionsPanel BorderLayout.WEST;
fishingPanel new JPanel;
fishingPanel.setLayoutnew GridLayoutmodelDIMENSION, model.DIMENSION;
for int row ; row model.DIMENSION; row
for int col ; col model.DIMENSION; col
FishingButton button new FishingButtonrow col;
button.addActionListenernew FishingButtonListenermodel this button;
button.setSize;
fishingPanel.addbutton;
addfishingPanel BorderLayout.CENTER;
fishingPanel.setPreferredSizenew Dimension;
fishingSliderPanel new JPanel;
fishingSliderPanel.setLayoutnew GridLayout;
JPanel fishingSliderTryPanel new JPanel;
fishingSlideTry new JSliderJSliderVERTICAL, model.getTriesRemaining model.getTriesRemaining; fishingSlideTry.setMajorTickSpacing;
fishingSlideTry.setPaintLabelstrue;
fishingSlideTry.setPaintTickstrue;
labelTry new JLabelTries;
fishingSliderTryPanel.addfishingSlideTry;
fishingSliderTryPanel.addlabelTry;
fishingSliderPanel.addfishingSliderTryPanel;
JPanel fishingSliderFishPanel new JPanel;
fishingSlideFish new JSliderJSliderVERTICAL, model.getFishRemaining model.getFishRemaining;
fishingSlideFish.setMajorTickSpacing;
fishingSlideFish.setPaintLabelstrue;
fishingSlideFish.setPaintTickstrue;
labelFish new JLabelFish;
fishingSliderFishPanel.addfishingSlideFish;
fishingSliderFishPanel.addlabelFish;
fishingSliderPanel.addfishingSliderFishPanel;
addfishingSliderPanel BorderLayout.EAST;
JPanel Bottom new JPanel;
JLabel bottomLabel new JLabelProgrammed by: Marko Yovanovich";
Bottom.addbottomLabel;
addBottom BorderLayout.SOUTH;
pack;
setVisibletrue;
public static void mainString args
new GoneFishingViewnew GoneFishingModel;
public void updateUI
Model Class:
public class GoneFishingModel
public static final int DIMENSION ;
private boolean grid new booleanDIMENSIONDIMENSION;
private int triesRemaining ;
private int fishRemaining ;
TODO
public GoneFishingModel
Random randomNumberGenerator new Random;
for int fishCounter ; fishCounter fishRemaining; fishCounter
int row, column;
do
row randomNumberGenerator.nextIntDIMENSION;
column randomNumberGenerator.nextIntDIMENSION;
while gridrowcolumn;
gridrowcolumn true;
TODO
@param row
@param column
@return
public boolean fishAtint row, int column
triesRemaining;
boolean foundFish gridrowcolumn;
if foundFish
fishRemaining;
return foundFish;
TODO
@return
public int getTriesRemaining
return triesRemaining;
TODO
@return
public int getFishRemaining
return fishRemaining;
TODO
@return
public boolean fishWin
return triesRemaining && fishRemaining ;
TODO
@return
public boolean playerWins
return fishRemaining ;
Listener Class:
public class FishingButtonListener implements ActionListener
private GoneFishingModel goneFishingModel;
private GoneFishingView goneFishingView;
private FishingButton fishingButton;
public FishingButtonListenerGoneFishingModel goneFishingModel, GoneFishingView goneFishingView,
FishingButton fishingButton
this.goneFishingModel goneFishingModel;
this.goneFishingView goneFishingView;
this.fishingButton fishingButton;
@Override
public void actionPerformedActionEvent e
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started