Write a java applet that allows the user to draw his/her data in the form of a c
ID: 3601045 • Letter: W
Question
Write a java applet that allows the user to draw his/her data in the form of a chart. First, the user is prompted to enter his/her data (maximum of 64 integer values) and then he/she will be asked to choose the type of chart to draw (bar chart or line chart). The program will then execute the user's request. Additional Requirements 1. The chart should always occupy an area of (height 300 and width- 400) 2. The chart title should be displayed on top of the chart. 3. The bars in the bar chart should be displayed in different colors (e.g. randomly generated). The actual data should be displayed on top of each bar.(See Fig. 1) 4. The line chart should be displayed in a single color (e.g. red). The actual data and a character indicating the actual position of each point should be displayed on top of the point. Besides, the two axes showing the limits of the area occupied by the chart, should be displayed in different color (e.g. black). (See Fig.2) Note: Perform all the calculations in init0. Paint0 should be used only for drawing.Explanation / Answer
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.awt.Graphics.*;
abstract class H5_Applet extends Applet implements ActionListener
{
//declares variables
int width;
int height;
int x=0;
int y=0;
//construct components
Label shapeGenius = new Label("THE RECTABGLE DRAAW");
Label widthLabel = new Label("Enter the width:");
TextField widthField = new TextField(100);
Label heightLabel = new Label("Enter the height:");
TextField heightField = new TextField(100);
Button drawButton = new Button("Draw");
Label outputLabel = new Label("Click the Draw button to draw your rectangle.");
public void init()
{
setForeground(Color.blue);
add(shapeGenius);
add(widthLabel);
add(widthField);
add(heightLabel);
add(heightField);
add(drawButton);
drawButton.addActionListener(this);
add(outputLabel);
g.drawRect(0,0,400,400);
}
public int actionPerformed(ActionEvent e)
{
width = Integer.parseInt(widthField.getText());
height = Integer.parseInt(heightField.getText());
outputLabel.setText("YOU drew a rectangle " + width + " by " + height);
return width;
return height;
paint();
}
public int paint(Graphics g)
{
g.clearRect(getX(), getY(), getWidth(), getHeight());
g.setColor(Color.red);
g.drawRect(0, 0, int width, int height, this);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.