*15.7 (Change color using a mouse) Write a program that displays the color of a circle as red when the mouse button is pressed and as blue when the mouse button is released. Please complete using Java language
ChangeColor.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
// implement mouselistener for work with mouse events
public class ChangeColor extends JFrame implements
MouseListener
{
boolean flag=false;
public ChangeColor() // constructor
{
setTitle("Change Circle Color On Mouse Action"); // set title to
the jframe
setSize(500,500); // set size of the jframe
// when user clicks X button then jframe will be close
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true); // setting jframe visible
addMouseListener(this); // add mouse listener
}
public void paint(Graphics g)
{
super.paint(g);
if(flag) // if mouse button is pressed then
g.setColor(Color.BLACK);
else // if mouse button is released then
g.setColor(Color.WHITE);
g.fillOval(100,100,300,300); // draws filled oval
}
// overriding all mouse listener methods
@Override
public void mousePressed(MouseEvent e)
{
flag=true;
repaint();
}
@Override
public void mouseReleased(MouseEvent e)
{
flag=false;
repaint();
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
}
public static void main(String args[])
{
new ChangeColor(); // creating anonymous object of ChangeColor
class
}
}
Output
C:\Users\AKSHAY\Desktop>javac ChangeColor.java
C:\Users\AKSHAY\Desktop>java ChangeColor
Mouse Button is Pressed
Mouse Button is Released
*15.7 (Change color using a mouse) Write a program that displays the color of a circle...
Write a program that changes the color of a circle based on whether the mouse cursor is in the top half of the display or the bottom half. Here are the specific requirements. a. Set the display size to 600x400 pixels b. Using the line function, draw a horizontal line that is centered vertically from the left side to the right side of the display c. Using the ellipse function, draw a circle of size 100x100 anywhere on the display...
In java Write a program that creates a polyline shape dynamically using mouse clicks. Each mouse click adds a new line segment from the previous point. Include a button below the drawing area to clear the current polyline and begin another.
I mainly need help with the “Mouse Events” & “Command Buttons” sections Sqrt xA2 Cir CircleButton Clas:s The graphic circular buttons are created by drawing a filled Circle on a StackPane. So, the pictured GUI uses 9 different StackPanes tor displaying the 9 qraphic buttons. Of course, these CircleButton objects can then be placed on a single GridPane lo achieve the 3x3 layoul (see SimpleCalc class below). Creale a class narned CircleBullon thal exlends the StackPane class. The class should...
Write a program that displays two radio buttons in a horizontal box. The first radio button should be label White while the second is labeled Yellow. Selecting White will change the color of the horizontal box to white, selecting Yellow will change the pane's color to yellow. Please use the JavaFX components.
This task is a program framework that you should complete. The program should allow the user to move a circular figure with the mouse over a drawing area. The current position of the figure is displayed continuously: Given is the main program: import javafx.scene.Scene; import javafx.application.Application; import javafx.beans.value.*; import javafx.scene.*; import javafx.scene.paint.Color; import javafx.scene.text.Text; import javafx.stage.Stage; public class Main extends Application { private DraggableCircle dc; private Text text; private void updateText() { text.setText("("+dc.getCenterX()+", "+dc.getCenterY()+")"); } @Override public void start(final Stage...
Using Java and a mouse or keyboard listener, create an image containing some object whose color can be changed when some input is received from the keyboard or mouse. If you are adventurous, you can try inputting a color name from the keyboard and change the color to the one named in that input.
Write a program that receives a character and displays its Unicode. using java please
Write two functions, one that displays a circle and one that displays a rectangle. Use these functions to write a complete C program from the following outline: int main() { /* Draw circle */ /* Draw rectangle */ } Do NOT use #include<graphics.h>
USING PYTHON LANGUAGE. QUESTION I: Write a program that displays the following table: a a^2 a 3 a14 1 1 1 1 2 4 8 16 3 9 27 81 4 16 64 256 QUESTION II: An approximate value of a number can be computed using the following formula: 7 ) Write a program that displays the result of 4 X + 7 • H) and 4 X - 를 7 tis). 9 QUESTION III: Write a program that prompts...
Q2 Write a JavaFX program that displays a rectangle with upper-left corner point at (40, 40), width 40, and height 60. Display a circle with radius 30 centered at the mouse point when the mouse is clicked. Display a text to indicate whether the circle contains, intersects, or is outside of the rectangle, as shown in Figure 3. Create the GUI programmatically. DO not use FXML.