Question
Hello, I'm making a small app that adds and subtracts integers using a visual method, here is what it looks like (below), dragging counters into
Hello, I'm making a small app that adds and subtracts integers using a visual method, here is what it looks like (below), dragging counters into the bathtub will make it change red (+) or blue (-) the more counters in the tub the darker the alpha, and soon the thermometer to the right will also change colours (WIP). The "Reset" button at the top is meant to reset the counters to their original positions at the top, I tried to call a method that initially paints the counters how ever I get the error: can't find symbol. Check out my code down below, please lend me the code to make this reset button as this needs to be finished by tomorrow!
Here is my code:
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.event.MouseEvent; import java.awt.event.MouseAdapter; import javax.swing.JButton; class IntegerBathtubWindow extends JFrame{ private JPanel drawSurface; // the surface that the counters will be drawn on // mouse offset from counters private int offsetX; private int offsetY; private int numberCounters = 8; // number of each type of counter to display // top left coordinate of positive counters private int[] positiveX = new int[numberCounters]; private int[] positiveY = new int[numberCounters]; // top left coordinate of negative counters private int[] negativeX = new int[numberCounters]; private int[] negativeY = new int[numberCounters]; private boolean[] draggingPositive = new boolean[numberCounters]; // true when dragging a positive counter private boolean[] draggingNegative = new boolean[numberCounters]; // true when dragging a positive counter private boolean[] inRectPositive = new boolean [numberCounters]; // true when positive counter in bathtub private boolean[] inRectNegative = new boolean[numberCounters]; // ture when negative counter in bathtub private boolean dragging = false; // true when dragging any positive or negative counter private Color ovalColor; //colour of interior shower head private Color rectColor; // colour of interior of bathtub private int redCounters = 0; // number of positive counters in bathtub private int blueCounters = 0; // number of negative counters in bathtub private int totalCount = 0; // sum of the positive and negative coutners in bathtub private int alphaRect = 100; // alpha for the bathtub colour private int i; // counter for the for loops private JButton resetBut; //reset button IntegerBathtubWindow() { super("Integer Bathtub"); // set up initial position of positive counters for (i = 0; i = positiveX[i] && x = positiveY[i] && y = negativeX[i] && x = negativeY[i] && y = 150 && x = 200 && y 0) { alphaRect = (150*totalCount)umberCounters; rectColor = new Color(255,0,0,alphaRect); } else if (totalCount = 150 && x = 200 && y 0) { alphaRect = (150*totalCount)umberCounters; rectColor = new Color(255,0,0,alphaRect); } else if (totalCountJB Integer Bathtub Reset JB Integer Bathtub Reset
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