Note that there are some explanatory texts on larger screens.

plurals
  1. POJava Methods to rotate, increase size, and clear Box image in Java
    primarykey
    data
    text
    <p>I'm creating a java program to draw an image of a box. I have most of my code finished. But, I'm having trouble figuring out a method to rotate the box by a specific number of degrees. I'm also trying to create a method to increase the size of the box by percentage and to clear my canvas of all images drawn.</p> <p>This is the code I have thus far: // My Box class import java.awt.Rectangle;</p> <pre><code>public class Box { public Box(Shapes canvasRef, int leftSide, int topLeft, int theWidth, int theHeight) { left = leftSide; top= topLeft; width = theWidth; height = theHeight; canvas = canvasRef; theBox = new Rectangle(left, top, width, height); canvas.addToDisplayList(this); show = false; } public void draw() { show = true; theBox = new Rectangle(left, top, width, height); canvas.boxDraw(); } public void unDraw() { show = false; theBox = new Rectangle(left, top, width, height); canvas.boxDraw(); } public Rectangle getBox() { return theBox; } public void moveTo(int newX, int newY) { left = newX; top = newY; draw(); } // This is the method that I tried but doesn't do anything public void turn(int degrees) { int newAngle = angle + degrees; angle = newAngle % 60; } clearWorld() { // Clears the "canvas" upon which boxes are drawn } public void grow(int percentage) { //The box grows the specified percentage, about the center, i.e. increase each side of the box the percentage indicated, with the center unchanged } // My Driver Program import javax.swing.JFrame; public class DisplayList { public static void main(String[] args) { JFrame frame = new JFrame("Joe The Box"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(250, 250); Shapes component = new Shapes(); frame.add(component); frame.setVisible(true); Box b1 = new Box(component, 150, 100, 30, 50); Box b2 = new Box(component, 100, 100, 40, 60); b1.draw(); b2.draw(); b1.turn(90); b2.grow(100); b1.clearWorld(); Delay.sleep(2); b2.moveTo(10,10); } } public boolean showBox() { return show; } private int left; private int top; private int width; private int height; private int angle = 0; private Shapes canvas; private Rectangle theBox; private boolean show; } </code></pre> <p>Can anyone please help me with the last three methods of my Box class? I'm really struck on what to add? I'm open to any suggestions. Thanks for your time!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload