File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Applets and the fly likes Virtual Graphing Calculator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Virtual Graphing Calculator" Watch "Virtual Graphing Calculator" New topic

Virtual Graphing Calculator

Justin Porter
Ranch Hand

Joined: Nov 20, 2004
Posts: 34
Hey, I need some ideas on how to start this. I want an applet that will allow me to write a function in the code (probably just cycle through it in a "for" loop) and output the results onto a graph, similar to that of a graphing calculator. All I need to do is plot the points as pixels, it doesn't need to be any more complicated than that.
Where I am stuck on this is on how to actually plot each pixel on the applet interface. I've done just regular java programming before this, I haven't worked on an applet yet, so mentioning basics and how things work is essential. Thanks ahead of time for any help you can give!

Want a free iPod, digital camera, or $300 cash? Completely legit offer at <a href="" target="_blank" rel="nofollow"></a> . I am looking for referrals which is why I need YOU!
Joe Ess

Joined: Oct 29, 2001
Posts: 9189

The great thing about object-oriented design is that once you've learned how to manipulate one object, you automatically know how to manipulate all the related objects. Displaying pixels on an applet works pretty much the same as an application. What have you tried and what are you having trouble with?

[How To Ask Questions On JavaRanch]
Justin Porter
Ranch Hand

Joined: Nov 20, 2004
Posts: 34
For testing purposes, I was just attempting to draw 100 random pixels, so here is my code for that.

Then I have a JavaGraphUser that actually uses the class.
Ben Fischer

Joined: Feb 22, 2005
Posts: 7
For applets you don't create a panel, the applet is a panel. Also, the applet size is determined by the html that calls it. So the applet itself is pretty simple something like:

import java.awt.*;
import javax.swing.*;
import java.util.Random;

public class JavaGraphApp extends JApplet {
private final int Width=640;
private final int Height=480;
private int x=0,y=0;
Random rnd;

public void init() {
rnd=new Random();

public void paint (Graphics g) {
for (int i=0;i<100;i++) {
x=(int) (rnd.nextFloat()*Width);
y=(int) (rnd.nextFloat()*Height);

will do what you're looking for. Instead of defining the width and height probably you should use the getSize().width and getSize().height methods in case you specifiy different dimensions in the html.
Consider Paul's rocket mass heater.
subject: Virtual Graphing Calculator
It's not a secret anymore!