Kashub's Code Barn - "Rysowanie wykresów z jakichś laborek z j2me"

podświetlone jako java (dodał(a) Kashub @ 2007-07-12 23:35:16)

Twoja wyszukiwarka
Podświetl ten kod w:
Ostatnio dodane:
Losowe wpisy:
/*
 * Wykres.java
 *
 * Created on June 2, 2007, 2:38 PM
 */
 
package Midlety;
 
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Graphics;
 
/**
 *
 * @author  student
 * @version
 */
public class Wykres extends Canvas implements CommandListener {
 
    Form form;
    Display display;
 
    private Command backCommand = new Command("Wstecz", Command.SCREEN, 2);
 
    int ScreenWidth, ScreenHeight;
    int A, B, C;
 
    public Wykres(Form f, Display d, int a, int b, int c) {
        display = d;
        form = f;
        A = a;
        B = b;
        C = c;
 
        ScreenWidth = getWidth();
        ScreenHeight = getHeight();
 
        addCommand(backCommand);
        setCommandListener(this);
    }
 
    public void paint(Graphics g) {
        g.setColor(0xffffff);
        g.fillRect(0, 0, ScreenWidth, ScreenHeight);
        g.setColor(0x0);
        g.drawLine(0, ScreenHeight/2, ScreenWidth, ScreenHeight/2);
        g.drawLine(ScreenWidth/2, 0, ScreenWidth/2, ScreenHeight);
        g.setColor(0xff0000);
        int prevY = calcY(0 - ScreenWidth/2);
        int newY;
        for(int k=1; k<ScreenWidth; k++) {
            newY = calcY(0 - ScreenWidth/2+k);
            g.drawLine(k-1, prevY + ScreenHeight/2, k, newY+ScreenHeight/2);
            prevY = newY;
        }
    }
 
    private int calcY(int x) {
        return -(A*x*x+B*x+C);
    }
 
    public void commandAction(Command c, Displayable s) {
        if(c==backCommand) {
            display.setCurrent(form);
        }
    }
 
    public void startApp() {
    }
 
    public void pauseApp() {
    }
 
    public void destroyApp(boolean unconditional) {
    }
 
    //public void commandAction(Command command, Displayable displayable) {
    //}
 
//    public void commandAction(Command command, Displayable displayable) {
//    }
 
//    public void commandAction(Command command, Displayable displayable) {
//    }
}
| Sklepy internetowe | | Sklep z artykułami dla dzieci | | Wózki dla dzieci | | Kamery IP sklep | | karma dla psa - sklep | | Programista Trójmiasto | | Blog o książkach | | Załóż za darmo bloga | | Skracacz adresów |