Question

import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow...

import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow for simple graphical drawing on a canvas. * This is a modification of the general purpose Canvas, specially made for * the BlueJ "shapes" example. * * @author: Bruce Quig * @author: Michael Kolling (mik) * Minor changes to canvas dimensions by William Smith 6/4/2012 * * @version: 1.6 (shapes) */ public class Canvas { // Note: The implementation of this class (specifically the handling of // shape identity and colors) is slightly more complex than necessary. This // is done on purpose to keep the interface and instance fields of the // shape objects in this project clean and simple for educational purposes. private static Canvas canvasSingleton; /** * Factory method to get the canvas singleton object. */ public static Canvas getCanvas() { if(canvasSingleton == null) { canvasSingleton = new Canvas("BlueJ Shapes Demo", 400, 200, Color.white); } canvasSingleton.setVisible(true); return canvasSingleton; } // ----- instance part ----- private JFrame frame; private CanvasPane canvas; private Graphics2D graphic; private Color backgroundColour; private Image canvasImage; private ArrayList objects; private HashMap shapes; /** * Create a Canvas. * @param title title to appear in Canvas Frame * @param width the desired width for the canvas * @param height the desired height for the canvas * @param bgClour the desired background colour of the canvas */ private Canvas(String title, int width, int height, Color bgColour) { frame = new JFrame(); canvas = new CanvasPane(); frame.setContentPane(canvas); frame.setTitle(title); canvas.setPreferredSize(new Dimension(width, height)); backgroundColour = bgColour; frame.pack(); objects = new ArrayList(); shapes = new HashMap(); } /** * Set the canvas visibility and brings canvas to the front of screen * when made visible. This method can also be used to bring an already * visible canvas to the front of other windows. * @param visible boolean value representing the desired visibility of * the canvas (true or false) */ public void setVisible(boolean visible) { if(graphic == null) { // first time: instantiate the offscreen image and fill it with // the background colour Dimension size = canvas.getSize(); canvasImage = canvas.createImage(size.width, size.height); graphic = (Graphics2D)canvasImage.getGraphics(); graphic.setColor(backgroundColour); graphic.fillRect(0, 0, size.width, size.height); graphic.setColor(Color.black); } frame.setVisible(visible); } /** * Draw a given shape onto the canvas. * @param referenceObject an object to define identity for this shape * @param color the color of the shape * @param shape the shape object to be drawn on the canvas */ // Note: this is a slightly backwards way of maintaining the shape // objects. It is carefully designed to keep the visible shape interfaces // in this project clean and simple for educational purposes. public void draw(Object referenceObject, String color, Shape shape) { objects.remove(referenceObject); // just in case it was already there objects.add(referenceObject); // add at the end shapes.put(referenceObject, new ShapeDescription(shape, color)); redraw(); } /** * Erase a given shape's from the screen. * @param referenceObject the shape object to be erased */ public void erase(Object referenceObject) { objects.remove(referenceObject); // just in case it was already there shapes.remove(referenceObject); redraw(); } /** * Set the foreground colour of the Canvas. * @param newColour the new colour for the foreground of the Canvas */ public void setForegroundColor(String colorString) { if(colorString.equals("red")) graphic.setColor(Color.red); else if(colorString.equals("black")) graphic.setColor(Color.black); else if(colorString.equals("blue")) graphic.setColor(Color.blue); else if(colorString.equals("yellow")) graphic.setColor(Color.yellow); else if(colorString.equals("green")) graphic.setColor(Color.green); else if(colorString.equals("magenta")) graphic.setColor(Color.magenta); else if(colorString.equals("white")) graphic.setColor(Color.white); else graphic.setColor(Color.black); } /** * Wait for a specified number of milliseconds before finishing. * This provides an easy way to specify a small delay which can be * used when producing animations. * @param milliseconds the number */ public void wait(int milliseconds) { try { Thread.sleep(milliseconds); } catch (Exception e) { // ignoring exception at the moment } } /** * Redraw ell shapes currently on the Canvas. */ private void redraw() { erase(); for(Iterator i=objects.iterator(); i.hasNext(); ) { ((ShapeDescription)shapes.get(i.next())).draw(graphic); } canvas.repaint(); } /** * Erase the whole canvas. (Does not repaint.) */ private void erase() { Color original = graphic.getColor(); graphic.setColor(backgroundColour); Dimension size = canvas.getSize(); graphic.fill(new Rectangle(0, 0, size.width, size.height)); graphic.setColor(original); } /************************************************************************ * Inner class CanvasPane - the actual canvas component contained in the * Canvas frame. This is essentially a JPanel with added capability to * refresh the image drawn on it. */ private class CanvasPane extends JPanel { public void paint(Graphics g) { g.drawImage(canvasImage, 0, 0, null); } } /************************************************************************ * Inner class CanvasPane - the actual canvas component contained in the * Canvas frame. This is essentially a JPanel with added capability to * refresh the image drawn on it. */ private class ShapeDescription { private Shape shape; private String colorString; public ShapeDescription(Shape shape, String color) { this.shape = shape; colorString = color; } public void draw(Graphics2D graphic) { setForegroundColor(colorString); graphic.fill(shape); } } } import java.awt.*; import java.awt.geom.*; /** * A circle that can be manipulated and that draws itself on a canvas. * * @author Michael Kolling and David J. Barnes * @version 1.0 (15 July 2000) */ public class Circle { private int diameter; private int xPosition; private int yPosition; private String color; private boolean isVisible; /** * Create a new circle at given position with given diameter and default color. */ public Circle(int diameter, int xPosition, int yPosition, String color) { this.diameter = diameter; this.xPosition = xPosition; this.yPosition = yPosition; this.color = color; isVisible = false; } /** * Make this circle visible. If it was already visible, do nothing. */ public void makeVisible() { isVisible = true; draw(); } /** * Make this circle invisible. If it was already invisible, do nothing. */ public void makeInvisible() { erase(); isVisible = false; } /* * Draw the circle with current specifications on screen. */ private void draw() { if(isVisible) { Canvas canvas = Canvas.getCanvas(); canvas.draw(this, color, new Ellipse2D.Double(xPosition, yPosition, diameter, diameter)); canvas.wait(10); } } /* * Erase the circle on screen. */ private void erase() { if(isVisible) { Canvas canvas = Canvas.getCanvas(); canvas.erase(this); } } } /** * Demonstrates a two-dimensional array. * * @author Derek Green * @version November 6, 06 * modified by William Smith 6/7/2012 */ public class TestTwoDimArray { private final int rows = 10; private final int cols = 20; private final int diameter = 20; /* Add a two-dimensional Circle array field to hold your circles. */ /** * Creates an empty 2-dimensional Circle array. */ /* Write a constructor method that initializes the array. The first dimension should be given size rows, and the second dimension should be given size cols. */ /** * Fill the array with circles. */ /* Write a method called "fillArray" that fills the entire array with blue circles. Give all circles the same diameter using the field defined above. Circles in the same row should have the same yPosition. Circles in the same column should have the same xPosition. The yPosition for row 0 should be 0. The yPosition for row 1 should be diameter. The yPosition for row 2 should be 2*diameter... Continue this pattern for all rows. Use a similar pattern to set the xPosition of each circle in a given column. If you do this correctly, no circle will overlap another circle. Once you get this working, then fix your code so that it does not add circles to positions in the array that are already occupied by a circle. You can tell whether a position is empty by checking if it contains null. */ /** * Add a random number of circles (between 1 and rows * cols). * Only need one loop here; */ /* Write a method called "addSomeCircles" that tries to add a random number of red circles to the array in a random fashion. The number of circles it tries to add should be between 1 and rows*cols, inclusive. For each circle choose a random row number and a random column number. The x and y positions of the circle should follow the plan used in the "fillArray" method. If the array has no circle at that position, add one, otherwise move on. Your method should return the number of collisions you had while adding circles. Remember, an empty element in the array will be equal (i.e., ==) to null. */ /** * Add a single circle at (row,col). * Make sure you account for arrays having positions from 0 to n and test for entering an invalid position */ /* Write a method called "addSingleCircle" that takes an integer parameter for the row and an integer parameter for the column. If the coordinates specify a valid position in the array, and the array has no circle at that position, then add a green one, otherwise do nothing. The x and y position of the circle should follow the plan used in the "fillArray" method. */ /** * Makes all circles in the array visible. */ /* Write a method called "makeAllCirclesVisible" that makes all circles in the array visible. */ /** * Makes all circles in the array invisible. */ /* Write a method called "makeAllCirclesInvisible" that makes all circles in the array invisible. */ /** * Remove all circles from the array. */ /* Write a method called "emptyArray" that removes all circles from the array (i.e. make them all null.) (Don't forget to make them all invisible first.) */ } please finish coding!

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

CODE::::


import java.awt.*;
import java.awt.geom.Ellipse2D;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JPanel;
/** * Canvas is a class to allow for simple graphical drawing on a canvas. * This is a modification of the general purpose Canvas, specially made for * the BlueJ "shapes" example. * * @author: Bruce Quig * @author: Michael Kolling (mik) * Minor changes to canvas dimensions by William Smith 6/4/2012 * * @version: 1.6 (shapes) */
public class Canvas
{ // Note: The implementation of this class (specifically the handling of // shape identity and colors) is slightly more complex than necessary. This // is done on purpose to keep the interface and instance fields of the
// shape objects in this project clean and simple for educational purposes.
private static Canvas canvasSingleton;
/** * Factory method to get the canvas singleton object. */
public static Canvas getCanvas() {
if(canvasSingleton == null) {
canvasSingleton = new Canvas("BlueJ Shapes Demo", 400, 200, Color.white);
}
canvasSingleton.setVisible(true);
return canvasSingleton;
}

// ----- instance part -----
private JFrame frame;
private CanvasPane canvas;
private Graphics2D graphic;
private Color backgroundColour;
private Image canvasImage;
private ArrayList objects;
private HashMap shapes;
/** * Create a Canvas. * @param title title to appear in Canvas Frame * @param width the desired width for the canvas * @param height the desired height for the canvas * @param bgClour the desired background colour of the canvas */
private Canvas(String title, int width, int height, Color bgColour) {
frame = new JFrame();
canvas = new CanvasPane();
frame.setContentPane(canvas);
frame.setTitle(title);
canvas.setPreferredSize(new Dimension(width, height));
backgroundColour = bgColour;
frame.pack();
objects = new ArrayList();
shapes = new HashMap();
}
/** * Set the canvas visibility and brings canvas to the front of screen * when made visible. This method can also be used to bring an already * visible canvas to the front of other windows. * @param visible boolean value representing the desired visibility of * the canvas (true or false) */
public void setVisible(boolean visible) {
if(graphic == null) { // first time: instantiate the offscreen image and fill it with // the background colour
Dimension size = canvas.getSize();
canvasImage = canvas.createImage(size.width, size.height);
graphic = (Graphics2D)canvasImage.getGraphics();
graphic.setColor(backgroundColour);
graphic.fillRect(0, 0, size.width, size.height);
graphic.setColor(Color.black);
}
frame.setVisible(visible);
}
/** * Draw a given shape onto the canvas. * @param referenceObject an object to define identity for this shape * @param color the color of the shape * @param shape the shape object to be drawn on the canvas */ // Note: this is a slightly backwards way of maintaining the shape // objects. It is carefully designed to keep the visible shape interfaces // in this project clean and simple for educational purposes.
public void draw(Object referenceObject, String color, Shape shape) {
objects.remove(referenceObject);
// just in case it was already there objects.add(referenceObject); // add at the end
shapes.put(referenceObject, new ShapeDescription(shape, color));
redraw();
} /** * Erase a given shape's from the screen. * @param referenceObject the shape object to be erased */
public void erase(Object referenceObject) {
objects.remove(referenceObject);
// just in case it was already there
shapes.remove(referenceObject);
redraw();
} /** * Set the foreground colour of the Canvas. * @param newColour the new colour for the foreground of the Canvas */
public void setForegroundColor(String colorString) {
if(colorString.equals("red")) graphic.setColor(Color.red);
else if(colorString.equals("black")) graphic.setColor(Color.black);
else if(colorString.equals("blue")) graphic.setColor(Color.blue);
else if(colorString.equals("yellow")) graphic.setColor(Color.yellow);
else if(colorString.equals("green")) graphic.setColor(Color.green);
else if(colorString.equals("magenta")) graphic.setColor(Color.magenta);
else if(colorString.equals("white")) graphic.setColor(Color.white);
else graphic.setColor(Color.black);
} /** * Wait for a specified number of milliseconds before finishing. * This provides an easy way to specify a small delay which can be * used when producing animations. * @param milliseconds the number */
public void wait(int milliseconds) {
try { Thread.sleep(milliseconds);
} catch (Exception e) { // ignoring exception at the moment
} } /** * Redraw ell shapes currently on the Canvas. */
private void redraw() {
erase();
for(Iterator i=objects.iterator(); i.hasNext(); ) {
((ShapeDescription)shapes.get(i.next())).draw(graphic);
}
canvas.repaint();
} /** * Erase the whole canvas. (Does not repaint.) */
private void erase() {
Color original = graphic.getColor();
graphic.setColor(backgroundColour);
Dimension size = canvas.getSize();
graphic.fill(new Rectangle(0, 0, size.width, size.height));
graphic.setColor(original);
} /************************************************************************ * Inner class CanvasPane - the actual canvas component contained in the * Canvas frame. This is essentially a JPanel with added capability to * refresh the image drawn on it. */
private class CanvasPane extends JPanel {
public void paint(Graphics g) {
g.drawImage(canvasImage, 0, 0, null);
}
} /************************************************************************ * Inner class CanvasPane - the actual canvas component contained in the * Canvas frame. This is essentially a JPanel with added capability to * refresh the image drawn on it. */
private class ShapeDescription {
private Shape shape;
private String colorString;
public ShapeDescription(Shape shape, String color) {
this.shape = shape; colorString = color;
} public void draw(Graphics2D graphic) {
setForegroundColor(colorString); graphic.fill(shape);
} }
}

/** * A circle that can be manipulated and that draws itself on a canvas. * * @author Michael Kolling and David J. Barnes * @version 1.0 (15 July 2000) */
class Circle {
private int diameter;
private int xPosition;
private int yPosition;
private String color;
private boolean isVisible;
/** * Create a new circle at given position with given diameter and default color. */
public Circle(int diameter, int xPosition, int yPosition, String color) {
this.diameter = diameter;
this.xPosition = xPosition;
this.yPosition = yPosition;
this.color = color;
isVisible = false;
} /** * Make this circle visible. If it was already visible, do nothing. */
public void makeVisible() {
isVisible = true; draw();
} /** * Make this circle invisible. If it was already invisible, do nothing. */
public void makeInvisible() {
erase(); isVisible = false;
} /* * Draw the circle with current specifications on screen. */
private void draw() {
if(isVisible) {
Canvas canvas = Canvas.getCanvas();
canvas.draw(this, color, new Ellipse2D.Double(xPosition, yPosition, diameter, diameter));
canvas.wait(10);
}
} /* * Erase the circle on screen. */
  
private void erase() {
if(isVisible) {
Canvas canvas = Canvas.getCanvas();
canvas.erase(this);
}
}
}

/** * Demonstrates a two-dimensional array. * * @author Derek Green * @version November 6, 06 * modified by William Smith 6/7/2012 */

class TestTwoDimArray {
private final int rows = 10;
private final int cols = 20;
private final int diameter = 20;
  
/* Add a two-dimensional Circle array field to hold your circles. */
/** * Creates an empty 2-dimensional Circle array. */
Circle c1[][];
/* Write a constructor method that initializes the array. The first dimension should be given size rows, and the second dimension should be given size cols. */
public TestTwoDimArray()
{
c1=new Circle[rows][cols];
}
/** * Fill the array with circles. */
/* Write a method called "fillArray" that fills the entire array with blue circles.
Give all circles the same diameter using the field defined above. circles in the same row should have the same yPosition.
Circles in the same column should have the same xPosition. The yPosition for row 0 should be 0.
The yPosition for row 1 should be diameter. The yPosition for row 2 should be 2*diameter...
Continue this pattern for all rows. Use a similar pattern to set the xPosition of each circle in a given column.
If you do this correctly, no circle will overlap another circle.
Once you get this working, then fix your code so that it does not add circles to positions in the array that are
already occupied by a circle. You can tell whether a position is empty by checking if it contains null. */
public void fillArray()
{
int xpos,ypos;
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
xpos=j*diameter;
ypos=i*diameter;
c1[i][j]=new Circle(diameter,xpos,ypos,"Blue");
}
  
}
}
/** * Add a random number of circles (between 1 and rows * cols). * Only need one loop here; */

/* Write a method called "addSomeCircles" that tries to add a random number of red circles to the array in a random fashion.
The number of circles it tries to add should be between 1 and rows*cols, inclusive.
For each circle choose a random row number and a random column number.
The x and y positions of the circle should follow the plan used in the "fillArray" method.
If the array has no circle at that position, add one, otherwise move on. Your method should return the number of collisions
you had while adding circles. Remember, an empty element in the array will be equal (i.e., ==) to null. */
public int addSomeCircles()
{
int noColl=0;
Random rand=new Random();
for(int i=0;i<rows*cols;i++)
{
int row=rand.nextInt(rows);
int col=rand.nextInt(cols);
if(c1[row][col]!=null)
c1[row][col]=new Circle(diameter,col*diameter,row*diameter,"Red");
else
noColl++;
}
return noColl;
}
/** * Add a single circle at (row,col). * Make sure you account for arrays having positions from 0 to n and test for entering an invalid position */
/* Write a method called "addSingleCircle" that takes an integer parameter for the row and an integer parameter for the column.
If the coordinatesspecify a valid position in the array, and the array has no circle at that position, then add a green one,
otherwise do nothing.
The x and y position of the circle should follow the plan used in the "fillArray" method. */
public void addSingleCircle(int row,int col)
{
if(row<rows && col<cols && c1[row][col]!=null)
{
c1[row][col]=new Circle(diameter,col*diameter,row*diameter,"Green");
}
}
/** * Makes all circles in the array visible. */
/* Write a method called "makeAllCirclesVisible" that makes all circles in the array visible. */
public void makeAllCirclesVisible()
{
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
c1[i][j].makeVisible();
}
}
}
/** * Makes all circles in the array invisible. */
/* Write a method called "makeAllCirclesInvisible" that makes all circles in the array invisible. */
public void makeAllCirclesInvisible()
{
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
c1[i][j].makeInvisible();
}
}
}
/** * Remove all circles from the array. */
/* Write a method called "emptyArray" that removes all circles from the array (i.e. make them all null.)
(Don't forget to make them all invisible first.) */
public void emptyArray()
{
makeAllCirclesInvisible();
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
c1[i][j]=null;
}
}
}


}

Add a comment
Know the answer?
Add Answer to:
import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow...
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
  • import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow...

    import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow for simple graphical drawing on a canvas. * This is a modification of the general purpose Canvas, specially made for * the BlueJ "shapes" example. * * @author: Bruce Quig * @author: Michael Kolling (mik) * Minor changes to canvas dimensions by William Smith 6/4/2012 * * @version: 1.6 (shapes) */ public class Canvas { // Note: The implementation of this class (specifically the...

  • Add another changeColor() method (i.e. you will now have 2 methods called "changeColor"). This one accepts...

    Add another changeColor() method (i.e. you will now have 2 methods called "changeColor"). This one accepts an int parameter and changes the color based on that int. The valid colors are "red", "yellow", "green", "blue", "magenta" and "black". In your code, map each color to an integer (e.g. in my code 3 means green.) If the number passed to the method is not valid, change the color to red. In the bounceTheBall() method, where you test for collisions with top...

  • JAVA problem: Upgrade and extend the previous programs Draw.java and DrawCanvas.java used in the class to...

    JAVA problem: Upgrade and extend the previous programs Draw.java and DrawCanvas.java used in the class to maintain a list of shapes drawn as follows: Replace and upgrade all the AWT components used in the programs to the corresponding Swing components, including Frame, Button, Label, Choice, and Panel. Add a JList to the left of the canvas to record and display the list of shapes that have been drawn on the canvas. Each entry in the list should contain the name...

  • Pacman

    For this project, you will be working in on the Pacman game you created for Lab 6. See the solution to Lab 6 for starting files to this project. You should be working in a group of 3 or fewer students. Part 1: InheritanceCreate a new class called GameCharacter. Make GameCharacter a parent class of Pacman and Ghost. Make sure to move all common fields and methods from Pacman and Ghost to GameCharacter.   Part 2: GameplayBegin the game with the...

  • Modify the NervousShapes program so that it displays equilateral triangles as well as circles and rectangles....

    Modify the NervousShapes program so that it displays equilateral triangles as well as circles and rectangles. You will need to define a Triangle class containing a single instance variable, representing the length of one of the triangle’s sides. Have the program create circles, rectangles, and triangles with equal probability. Circle and Rectangle is done, please comment on your methods so i can understand */ package NervousShapes; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import javax.swing.*; import javax.swing.event.*; public class...

  • ***This is a JAVA question*** ------------------------------------------------------------------------------------------------ import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import javax.swing.*;...

    ***This is a JAVA question*** ------------------------------------------------------------------------------------------------ import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import javax.swing.*; import javax.swing.event.*; public class DrawingPanel implements ActionListener { public static final int DELAY = 50; // delay between repaints in millis private static final String DUMP_IMAGE_PROPERTY_NAME = "drawingpanel.save"; private static String TARGET_IMAGE_FILE_NAME = null; private static final boolean PRETTY = true; // true to anti-alias private static boolean DUMP_IMAGE = true; // true to write DrawingPanel to file private int width, height; // dimensions...

  • GUI in java: Run the below code before doing the actionlistener: import java.awt.*; import javax.swing.*; public...

    GUI in java: Run the below code before doing the actionlistener: import java.awt.*; import javax.swing.*; public class DrawingFrame extends JFrame {    JButton loadButton, saveButton, drawButton;    JComboBox colorList, shapesList;    JTextField parametersTextField;       DrawingFrame() {        super("Drawing Application");        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        JToolBar toolbar = new JToolBar();        toolbar.setRollover(true);        toolbar.add(loadButton=new JButton("Load"));        toolbar.add(saveButton=new JButton("Save"));        toolbar.addSeparator();        toolbar.add(drawButton=new JButton("Draw"));               toolbar.addSeparator();        toolbar.addSeparator();        toolbar.add(new...

  • Simple java GUI language translator. English to Spanish, French, or German import javax.swing.*; import java.awt.*; import...

    Simple java GUI language translator. English to Spanish, French, or German import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class translatorApp extends JFrame implements ActionListener {    public static final int width = 500;    public static final int height = 300;    public static final int no_of_lines = 10;    public static final int chars_per_line = 20;    private JTextArea lan1;    private JTextArea lan2;    public static void main(String[] args){        translatorApp gui = new translatorApp();...

  • import javax.swing.*; import java.awt.event.*; import java.awt.*; public class BookReview extends JFrame implements ActionListener {       private JLabel...

    import javax.swing.*; import java.awt.event.*; import java.awt.*; public class BookReview extends JFrame implements ActionListener {       private JLabel titleLabel;       private JTextField titleTxtFd;       private JComboBox typeCmb;       private ButtonGroup ratingGP;       private JButton processBnt;       private JButton endBnt;       private JButton clearBnt;       private JTextArea entriesTxtAr;       private JRadioButton excellentRdBnt;       private JRadioButton veryGoodRdBnt;       private JRadioButton fairRdBnt;       private JRadioButton poorRdBnt;       private String ratingString;       private final String EXCELLENT = "Excellent";       private final String VERYGOOD = "Very Good";       private final String FAIR = "Fair";       private final String POOR = "Poor";       String...

  • There 2 parts to complete: import javax.swing.*; import java.awt.event.*; import java.awt.*; public class Q4 extends JFrame...

    There 2 parts to complete: import javax.swing.*; import java.awt.event.*; import java.awt.*; public class Q4 extends JFrame { private int xPos, yPos; public Q4() { JPanel drawPanel = new JPanel() { @Override public void paintComponent(Graphics g) { super.paintComponent(g); // paint parent's background //complete this: } }; drawPanel.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { //complete this :- set the xPos, yPos }    }); setContentPane(drawPanel); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("Mouse-Click Demo"); setSize(400, 250); setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() {...

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