The program given here will draw the Olympic logo. Modify the program as the following:
1.Change the class name to Test1OlympicYourFirstNameYourLastName
2.Change the OlympicRingPanel class name to OlympicRingPanelYourfirstNameYourLastName
3.Modify the program so that the first ring will be filled with
random color with a random alpha value. I have shown 3 sample
output here for your references.
4.Modify the paintComponent so your name will be displayed under
the Olympic rings.The color of your name should be random color as
well.
this is for Java.............
first one:
// OlympicRingPanel.java
// program source: https://gist.github.com/jimmykurian/1732923
import javax.swing.JComponent;
import java.awt.*;
public class OlympicRingPanel extends JComponent
{
public void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
g.drawOval (1,0,40,40);
g.setColor(Color.YELLOW);
g.drawOval (21,20,40,40);
g.setColor(Color.BLACK);
g.drawOval (41,0,40,40);
g.setColor(Color.GREEN);
g.drawOval (61,20,40,40);
g.setColor(Color.RED);
g.drawOval (81,0,40,40);
g.setColor(Color.BLUE);
}
}
second one:
//OlympicRingViewer.java
// program source: https://gist.github.com/jimmykurian/1732923
import javax.swing.*;
public class OlympicRingViewer
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
final int FRAME_WIDTH =
300;
final int FRAME_HEIGHT = 230;
frame.setSize(300, 230);
frame.setTitle("OlympicRingViewer");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
OlympicRingPanel component = new
OlympicRingPanel();
frame.add(component);
frame.setVisible(true);
}
}
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.Random;
import javax.swing.JComponent;
import javax.swing.JFrame;
class OlympicRingPanelYourName extends JComponent {
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D)
g;
Random r = new Random();
// filling the random color
g.setColor(new
Color(r.nextInt(255), r.nextInt(255), r.nextInt(255)));
g.fillOval(1, 0, 40, 40);
g.setColor(Color.YELLOW);
g.drawOval(21, 20, 40,
40);
g.setColor(Color.BLACK);
g.drawOval(41, 0, 40, 40);
g.setColor(Color.GREEN);
g.drawOval(61, 20, 40,
40);
g.setColor(Color.RED);
g.drawOval(81, 0, 40, 40);
g.setColor(Color.BLUE);
// displaying the name
g.drawString("Your Name", 80,
80);
}
}
// OlympicRingViewer.java
// program source: https://gist.github.com/jimmykurian/1732923
public class Test1OlympicYourName {
public static void main(String[] args) {
JFrame frame = new JFrame();
final int FRAME_WIDTH =
300;
final int FRAME_HEIGHT = 230;
frame.setSize(300, 230);
frame.setTitle("OlympicRingViewer");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
OlympicRingPanelYourName
component = new OlympicRingPanelYourName();
frame.add(component);
frame.setVisible(true);
}
}
Note: Replace the Test with Your Name with your actual name
The program given here will draw the Olympic logo. Modify the program as the following: 1.Change...
Ex: In relation to image painting in frame, the following code is the use of getImage() in toolkit. Modify the image() through ImageIcon and imageIO.read() of javax into a converted form using imageIO.read(). import java.awt.*; import javax.swing.*; public class FrameImage extends JPanel{ public void paint(Graphics g) { Toolkit toolkit = Toolkit.getDefaultToolkit(); Image image = toolkit.getImage("image/grapes.gif"); g.drawImage(image, 60, 40, this); } public static void main(String[] args) { JFrame frame = new JFrame(); FrameImage pannell = new FrameImage(); frame.add(pannell); frame.setTitle("image paint"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);...
A Java Problem. In this problem you are going write a class to
model a traffic light that can cycle through colors, red, green,
yellow. To do this, you will have to maintain the state of the
traffic light. Maintaining state is one of the design pattern
discussed in this week's lesson. The state of the
TrafficLight indicates which light is lit. It
changes every time the TrafficLight cycles.
Specification
TrafficLight will have a constructor that takes the x and...
tart from the following code, and add Action Listener to make it
functional to do the temperature conversion in the direction of the
arrow that is clicked.
. (Need about 10 lines)
Note:
import javax.swing.*;
import
java.awt.GridLayout;
import
java.awt.event.*;
import
java.text.DecimalFormat;
public class temperatureConverter extends JFrame {
public static void
main(String[] args) {
JFrame frame = new temperatureConverter();
frame.setTitle("Temp");
frame.setSize(200, 100);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public
temperatureConverter() {
JLabel lblC = new...
Keep the ball in bounds by adding conditional statements after the TODO comments in the paintComponent() method to check when the ball has hit the edge of the window. When the ball reaches an edge, you will need to reverse the corresponding delta direction and position the ball back in bounds. Make sure that your solution still works when you resize the window. Your bounds checking should not depend on a specific window size This is the java code that...
Re-write this program into a javafx program, using javafx components only. NO awt or swing. import java.awt.Button; import java.awt.Label; import java.awt.TextField; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; import javax.swing.JPanel; public class DecimalBinary { public static void main(String[] args) { JFrame frame=new JFrame(); //Create a frame frame.setTitle("Decimal-Binary Converter"); //Set its label frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 300); //Set size fo frame JPanel panel=new JPanel(); //Create a panel to contain controls frame.add(panel); //add panel to frame panel.setLayout(null); Label decimalLabel=new Label("Decimal"); //Create label for decimal decimalLabel.setBounds(10,...
Java Program
The goal of this assignment is to develop an event-based game.
You are going to develop a Pong Game.
The game board is a rectangle with a ball bouncing around. On
the right wall, you will have a rectangular paddle (1/3 of the wall
height). The paddle moves with up and down arrows. Next to the game
board, there will be a score board. It will show the count of
goals, and count of hits to the paddle....
Program #2 Write a program to simulate showing an NBA Team on a Basketball court Here is an example of the screenshot when running the program: Tony Parker T. Splitter T. Duncan M. Gineb Player Kame: M Ginobil Player Age 2 Add A Player Ce An example of the JFrame subclass with main method is as follows import java.awt. import java.awt.event." import javax.swing. public class NBA Playoff extends JFrame private JTextField txtName: private JTextField txtAge: private NBATeam spurs private NBAcourtPanel...
Hi! I'm working on building a GUI that makes cars race across the screen. So far my code produces three cars, and they each show up without error, but do not move across the screen. Can someone point me in the right direction? Thank you! CarComponent.java package p5; import java.awt.*; import java.util.*; import javax.swing.*; @SuppressWarnings("serial") public class CarComponent extends JComponent { private ArrayList<Car> cars; public CarComponent() { cars = new ArrayList<Car>(); } public void add(Car car) { cars.add(car); } public...
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...
I have to create a java graphics program which will draw 10 rectangles and 10 ellipses on the screen. These shapes are to be stored in an arrayList. I have to do this using 6 different class files. I am not sure whether I successfully created an ellipse in the Oval Class & also need help completing the print Class. I need someone to check whether my Oval Class is correct (it successfully creates an ellipse with x, y, width,...