By: Paawan Chaudhary in Java Tutorials on 2012年09月19日 [フレーム]
This is a Java program to draw a bar chart for the table given below which shows annual result analysis of a school from period 2001-2005.these values may be placed in a HTML file as <param> attributes and then used in Applet for dislaying bar-chart.
Year 2001 2002 2003 2004 2005 Result % 80 90 100 100 98
import java.applet.*;
import java.awt.*;
/*
<applet code = "BarChart.class" width=400 height=400>
<param name="year0" value="2001">
<param name="year1" value="2002">
<param name="year2" value="2003">
<param name="year3" value="2004">
<param name="year4" value="2005">
<param name="result0" value="80">
<param name="result1" value="90">
<param name="result2" value="100">
<param name="result3" value="100">
<param name="result4" value="98">
</applet>
*/
public class BarChart extends Applet
{
int n;
String year[];
int value[];
public void init()
{
n = 5;
year = new String[n];
value = new int[n];
year[0] = getParameter("year0");
year[1] = getParameter("year1");
year[2] = getParameter("year2");
year[3] = getParameter("year3");
year[4] = getParameter("year4");
value[0] = Integer.parseInt(getParameter("result0"));
value[1] = Integer.parseInt(getParameter("result1"));
value[2] = Integer.parseInt(getParameter("result2"));
value[3] = Integer.parseInt(getParameter("result3"));
value[4] = Integer.parseInt(getParameter("result4"));
}
public void paint(Graphics g)
{
Font font = new Font("Arial",Font.BOLD,15);
g.setFont(font);
for(int i = 0; i < n; i ++)
{
g.setColor(Color.BLUE);
g.drawString(year[i], 20, i * 50 + 30);
g.setColor(Color.RED);
g.fillRect(70, i * 50 + 10, value[i], 40);
g.drawString(String.valueOf(value[i]) + "%", 180, i * 50 + 35);
}
String msg = "Bar Chart from Year 2001 - 2005";
g.setColor(Color.darkGray);
font = new Font("Arial",Font.BOLD,20);
g.setFont(font);
g.drawString(msg, 50, 300);
}
}
(追記) (追記ここまで)
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
Most Viewed Articles (in Java )
Step by Step guide to setup freetts for Java
Open a .docx file and show content in a TextArea using Java
concurrent.Flow instead of Observable class in Java
DateFormat sample program in Java
Simple Port Scanner application using Java
Using the AWS SDK for Java in Eclipse
Read a file having a list of telnet commands and execute them one by one using Java
Calculator application in Java
Latest Articles (in Java)
Read a file having a list of telnet commands and execute them one by one using Java
Open a .docx file and show content in a TextArea using Java
Step by Step guide to setup freetts for Java
Of Object, equals (), == and hashCode ()
Using the AWS SDK for Java in Eclipse
DateFormat sample program in Java
concurrent.Flow instead of Observable class in Java
Calculator application in Java
Sending Email from Java application (using gmail)
Read a file having a list of telnet commands and execute them one by one using Java
Open a .docx file and show content in a TextArea using Java
Step by Step guide to setup freetts for Java
Of Object, equals (), == and hashCode ()
Using the AWS SDK for Java in Eclipse
DateFormat sample program in Java
concurrent.Flow instead of Observable class in Java
Calculator application in Java
Sending Email from Java application (using gmail)
© 2023 Java-samples.com
Tutorial Archive: Data Science React Native Android AJAX ASP.net C C++ C# Cocoa Cloud Computing EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Trends WebServices XML Office 365 Hibernate
Latest Tutorials on: Data Science React Native Android AJAX ASP.net C Cocoa C++ C# EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Cloud Computing WebServices XML Office 365 Hibernate