Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Why can't I call method with JButton? Hello, I'm making a small app that adds and subtracts integers using a visual method, here is what

Why can't I call method with JButton? 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!

image text in transcribed

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  public void actionPerformed(ActionEvent e) { //Here goes the action (method) you want to execute when clicked IntegerBathtubWindow(); } }); // create the mouseListeners and the corresponding mouse methods addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { // exit if already dragging something if (dragging) return; // get location of mouse int x = e.getX(); int y = e.getY()-25; // loop to check if user pressed on a positive counter 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 (totalCount   - 0 x JB Integer Bathtub ++++ + + Reset tt

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions

Question

Write the Roman numeral as a HinduArabic numeral. XXXIX

Answered: 1 week ago

Question

1. What is the difference between exempt and nonexempt jobs?pg 87

Answered: 1 week ago