public class Game extends JPanel{ private JPanel panel; //to show how much is missed and caught private JLabel caught, missed; //slider to allow speed adjustment private JSlider slider; private String catchString, missString; //icon which shows image private ImageIcon creature; //set timer private Timer run; //for randomizing location private Random xPoint, yPoint; //for other variables private int xCor, yCor, grabX, grabY, a, b, x, y, speed, speed2; //for coordinates private final int WIDTH, HEIGHT, IMAGE_SIZE, DOT; private int SPEED; //setters //sets up to display what is missed public void setMissedString(int x){ missString = "Missed: " + x; missed.setText(missString); } //speeds up the image randomization public void setCatchString(int x){ catchString = "Caught: " + x; caught.setText(catchString); } //getters public String getMissedString(){ return missString; } public String getCatchString(){ return catchString; } public Game(){ SPEED = 2500; speed2 = 0; //PROBLEM>> slider.addChangeListener(new ChangeListener(){ public void stateChanged(ChangeEvent ev){ JSlider slider1 = (JSlider) ev.getSource(); speed2 = slider1.getValue(); setSpeed(getSpeed() - (speed2 * 100)); run.setDelay(getSpeed()); } }); run = new Timer(SPEED, new ActionListener(){ public void actionPerformed(ActionEvent ev){ setXcor(xPoint.nextInt(WIDTH - IMAGE_SIZE)); setYcor(yPoint.nextInt(HEIGHT) + 50); outOfPanel(); } }); slider = new JSlider(JSlider.HORIZONTAL, 10, 2500, 50); slider.setMajorTickSpacing(10); slider.setPaintTicks(true); panel = new JPanel(); panel.setPreferredSize(new Dimension(WIDTH - 10,40)); panel.setLayout(new GridLayout(1,3)); panel.add(caught); panel.add(missed); panel.add(slider);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)