Question

In Java:

Squares iteratively rena Pevac Use constants SIZE = 500 and DIST = 20. Write application with methods • public void concentri

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Working java code:-

ConcentricSquareGraphics.java 1 import java.awt.Canvas; 2 import java.awt.Color; 3 import java.awt.Graphics; 5 import javax.sConcentricSquareGraphics.java 1 import java.awt.Canvas; 2 import java.awt.Color; 3 import java.awt.Graphics; 5 import javax.sOUTPUT:-

Squares iteratively Your Name - O X

Java code:-

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JFrame;

public class ConcentricSquareGraphics extends Canvas{
  
   static int SIZE=500;
   int DIST=10;
  
  
  
   public void paint(Graphics g) {
      
       int sz=SIZE;//temp variable for size
       int dis=0;//temp variable for distance
int i=0;
setBackground(Color.WHITE);
  
while(sz-dis>=DIST)
{
g.setColor(Color.GREEN);
g.fillRect(i, i,sz-dis,sz-dis);
  
i+=DIST;
dis=2*i;
  
  
g.setColor(Color.MAGENTA);
g.fillRect(i, i, sz-dis, sz-dis);
  
i+=DIST;
dis=2*i;
  

g.setColor(Color.RED);
g.fillRect(i, i, sz-dis, sz-dis);
  
i+=DIST;
dis=2*i;
  
  
  
g.setColor(Color.BLACK);
g.fillRect(i, i, sz-dis, sz-dis);
  
i+=DIST;
dis=2*i;
  

}
  
  
}
public static void main(String[] args) {
ConcentricSquareGraphics m=new ConcentricSquareGraphics();
JFrame f=new JFrame();
f.setTitle("Squares Iteratively "+"Your Name");
f.add(m);
f.setSize(SIZE,SIZE);
//f.setLayout(null);
f.setVisible(true);
}
}

Add a comment
Know the answer?
Add Answer to:
In Java: Squares iteratively rena Pevac Use constants SIZE = 500 and DIST = 20. Write...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA Objective : • Learning how to write a simple class. • Learning how to use...

    JAVA Objective : • Learning how to write a simple class. • Learning how to use a prewritten class. • Understanding how object oriented design can aid program design by making it easier to incorporate independently designed pieces of code together into a single application. Instructions: • Create a project called Lab13 that contains three Java file called Book.java , Bookstore.java and TempleBookstore.java • I’ve provided a screenshot of how your project should look like. • Be sure to document...

  • JAVA PROGRAM USING ECLIPSE. THE FIRST IMAGE IS THE INSTRUCTIONS, THE SECOND IS THE OUTPUT TEST...

    JAVA PROGRAM USING ECLIPSE. THE FIRST IMAGE IS THE INSTRUCTIONS, THE SECOND IS THE OUTPUT TEST CASES(WHAT IM TRYING TO PRODUCE) BELOW THOSE IMAGES ARE THE .JAVA FILES THAT I HAVE CREATED. THESE ARE GeometircObject.Java,Point.java, and Tester.Java. I just need help making the Rectangle.java and Rectangle2D.java classes. GeometricObject.Java: public abstract class GeometricObject { private String color = "white"; // shape color private boolean filled; // fill status protected GeometricObject() { // POST: default shape is unfilled blue this.color = "blue";...

  • I need help with these Java programming assignements. public class Die { //here you declare your...

    I need help with these Java programming assignements. public class Die { //here you declare your attributes private int faceValue; //operations //constructor - public Die() { //body of constructor faceValue=(int)(Math.random()*6)+1;//instead of 1, use random approach to generate it } //roll operation public void roll() { faceValue=(int)(Math.random()*6)+1; }    //add a getter method public int getFaceValue() { return faceValue; }    //add a setter method public void setFaceValue(int value) { faceValue=value; } //add a toString() method public String toString() { String...

  • In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are...

    In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are in the range 0 to 100 inclusive. The program will ask a user to re-enter an integer if the user inputs a number outside of that range. The inputted integers must then be stored in a single dimensional array of size 20. Please create 3 methods: 1. Write a method public static int countEven(int[] inputArray) The method counts how many even numbers are in...

  • Write a program that instantiates an array of integers named scores. Let the size of the...

    Write a program that instantiates an array of integers named scores. Let the size of the array be 10. The program then first invokes randomFill to fill the scores array with random numbers in the range of 0 -100. Once the array is filled with data, methods below are called such that the output resembles the expected output given. The program keeps prompting the user to see if they want to evaluate a new set of random data. Find below...

  • In Java write the following array- processing methods into the same application, Lab13.java. Use the main...

    In Java write the following array- processing methods into the same application, Lab13.java. Use the main method in this application to test your methods. 1) Write the void method, shiftLeft, which accepts an array of int and changes the elements of this array so that the index of each element is now less by one and the last element of the array is now zero. For example, if the parameter array is {7, 3, 2, 9, 5}, then when this...

  • Programming Language : JAVA Write a class named Ship. Its purpose is to model a ship...

    Programming Language : JAVA Write a class named Ship. Its purpose is to model a ship in the BattleShip game and its placement on the Battleship board. Ships exist on a 10 x 10 battleship board with ten rows labeled A through J and columns labeled 1 through 9 and the final column labeled 0 to indicate the tenth column. We will refer to the Ship placed on the board at the origin which the pair (r,c) where in the...

  • in java Write a class named Palindrome.java and Write a method isPalindrome that takes an IntQueue...

    in java Write a class named Palindrome.java and Write a method isPalindrome that takes an IntQueue as a parameter and that returns whether or not the numbers in the queue represent a palindrome (true if they do, false otherwise). A sequence of numbers is considered a palindrome if it is the same in reverse order. For example, suppose a Queue called q stores this sequence of values: front [3, 8, 17, 9, 17, 8, 3] back Then the following call:...

  • This is for a java lab, in class instruction we are not allowed to use "this"....

    This is for a java lab, in class instruction we are not allowed to use "this". if anyone can help, and explain the importance of "this" and as to why we should or should not use it. Thank you in advanced. Intarraybag.java: public class IntArrayBag implements Cloneable { // instance variables private int[ ] data; private int manyItems; // constructor : behavior #1 public IntArrayBag( ) { final int INITIAL_CAPACITY = 10; manyItems = 0; data = new int[INITIAL_CAPACITY]; }...

  • 1 Overview For this assignment you are required to write a Java program that plays (n,...

    1 Overview For this assignment you are required to write a Java program that plays (n, k)-tic-tac-toe; (n, k)-tic- tac-toe is played on a board of size n x n and to win the game a player needs to put k symbols on adjacent positions of the same row, column, or diagonal. The program will play against a human opponent. You will be given code for displaying the gameboard on the screen. 2 The Algorithm for Playing (n, k)-Tic-Tac-Toe The...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT