logo

Dartboard Applet in Java

Draw a dartboard using Java applet

3 Pages579 Words419 Views
   

Added on  2023-04-21

About This Document

This tutorial teaches you how to create a dartboard applet in Java. It includes step-by-step instructions, code examples, and screenshots.

Dartboard Applet in Java

Draw a dartboard using Java applet

   Added on 2023-04-21

ShareRelated Documents
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));
Dartboard Applet in Java_1

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Diploma in Software Engineering.
|8
|1003
|43

Using Graphical Objects in Java: Splat Program Example
|5
|1704
|173

ITECH7410 Software Engineering Methodologies
|12
|980
|92

Analysis/Design: Case Study
|7
|1161
|12