Products
Study Documents
AI Grader
AI Answer
AI Code Checker
Plagiarism Checker
AI Paraphraser
AI Quiz
AI Detector
Pricing
Blog
About Us
Get 7 Days Free Trial
Login
Dartboard Applet in Java
Verified
Added on  2023/04/21
|
3
|
579
|
419
AI Summary
This tutorial teaches you how to create a dartboard applet in Java. It includes step-by-step instructions, code examples, and screenshots.
Contribute Materials
Your contribution can guide someone’s learning journey. Share your documents today.
Contribute Now
Part 1
import
java.awt.Graphics;
import
javax.swing.JApplet;
public
class
Dartboard
extends
JApplet
{
int
Diameter
;
int
NumberPoints
;
int
inputlines
;
double
angle
;
public
void
init()
{
final
int
input
= Integer.
parseInt
(getParameter(
"Width"
));
final
int
Lines
= Integer.
parseInt
(getParameter(
"Lines"
));
Diameter
=
input
;
inputlines
=
Lines
;
}
// draw
shapes
on
applet's
background
public
void
paint(Graphics
g
) {
super
.paint(
g
);
// call
paint
method
inherited
from
JApplet
g
.drawOval(0,
0,
Diameter
,
Diameter
);
g
.drawOval(((
Diameter
/ 2)
/ 3),
((
Diameter
/ 2)
/ 3),
((
Diameter
/ 3)
* 2),
((
Diameter
/ 3)
* 2));
// done
processing
case
g
.drawOval((((
Diameter
/ 2)
/ 3)
* 2),
(((
Diameter
/ 2)
/ 3)
* 2),
(
Diameter
/ 3),
(
Diameter
/ 3));
//check
if
the number
of
passed
lines
is
within
the bounds
of the
requirements
if
(
inputlines
< 2
||
inputlines
> 30)
{
NumberPoints
= 20;
}
else
{
NumberPoints
=
inputlines
;
}
//find
the
angle
that is
to be
used
for the
lines
angle
= 360
/ (
double
)
NumberPoints
;
int
i
;
//for
loop
statement
int
x
;
// X
coordinate
int
y
;
//y coordinate
for
(
i
= 0;
i
<
NumberPoints
;
i
++) {
// find
line
angle
in
radians
double
w
= (
angle
*
i
) * Math.
PI
/ 180;
x
= (
int
) ((
Diameter
/ 2)
* Math.
cos
(
w
));
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
💎 Get Pro
y
= (
int
) ((
Diameter
/ 2)
* Math.
sin
(
w
));
g
.drawLine(
x
+ (
Diameter
/ 2),
y
+ (
Diameter
/ 2),
(
Diameter
/
2), (
Diameter
/ 2));
}
}
}
Design
Smiley Tennis Ball at the Ireland v Georgia game.
Code:
import
java.awt.*;
import
java.awt.Event
.*;
import
javax.swing.*;
public
class
Flag
extends
JPanel
{
public
static
void
main(String[]
args
){
JFrame
f
=
new
JFrame(
"Flag"
);
f
.setDefaultCloseOperation(JFrame.
EXIT_ON_CLOSE
);
Flag
fl
=
new
Flag();
fl
.setBackground(Color.
WHITE
);
f
.add(
fl
);
f
.setSize(500,
270);
f
.setVisible(
true
);
}
public
void
paintComponent(Graphics
g
){
super
.paintComponent(
g
);
this
.setBackground(Color.
WHITE
);
g
.setColor(Color.
GREEN
);
g
.fill3DRect(10,
10,
100,
50,
true
);
g
.setColor(Color.
WHITE
);
g
.fill3DRect(110,
10, 100,
50,
true
);
g
.setColor(Color.
ORANGE
);
g
.fill3DRect(210,
10, 100,
50,
true
);
g
.setColor(Color.
YELLOW
);
g
.fillOval(100,100,100,100);
g
.setColor(Color.
BLACK
);
g
.fillOval(120,125,20,20);
g
.fillOval(160,125,20,20);
g
.drawLine(150,165,150,150);
g
.drawArc(110,106,80,90,-30,-120);
}
}
Screenshot
1 out of 3
Download
Related Documents
Diploma in Software Engineering.
|
8
|
1003
|
43
View Document
Object-Oriented Thinking
|
5
|
1704
|
173
View Document
Java Quadratic Equation Solver
|
12
|
980
|
92
View Document
Analysis/Design: Case Study
|
7
|
1161
|
12
View Document