Username Password

Register Here || Lost Password
View Thread
Explore Your Brain Pemrograman Java
ask:program java
Username
Password
Register FAQ Members List Today's Posts Search

Print Thread

30-10-2009 07:23 PM ask:program java | Edited by bad_samt 30-10-2009 07:34 PM
User Avatar

bad_samt
Anbu


Posts: 270
Joined: 23.04.09
Location: Searcing........
mo nanya nech,qw lg bikin program tentng grafik penjualan barang gtuh....
tp mash ada keslahan tolong diperiksa dunX kk......

ne program nya...

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
import java.util.Random;

//
//Definisi class Gambar
//
class Gambar extends Canvas
{
private int[] data;
private int model;

private String[] namaBulan =
{"Jan","Feb","Mar","Apr","Mei","Jun",
"Jul","Agt","Sep","Okt","Nop","Des"};

public void setData(int[] x)
{
data = x;
}

public void setModel(int m)
{
model = m;
}

public void paint(Graphics g)
{
g.setColor(255,255,255);
g.fillRect(0,0,getWidth(),getHeight() );

int gap = 5;
int len = (getWidth() - gap*13) / 12;
int yBottom = getHeight() - 30;
int max = data[0];
int xx = 0;
int yy = 0;
for (int i=1; i<12; i++)
if (max < data[i])
max = data[i];

double yScale = (yBottom - 10.0) / max;
Font font = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_SMALL);
g.setColor(0,0,0);
g.drawLine(0,yBottom,getWidth(),yBottom);

for (int i=0; i<12; i++)
{
int w = len;
int h = (int)(data[i]*yScale);
int x = i*len+(i+1)*gap;
int y = yBottom-h;

if(model==0)
{
g.setColor(0,150,0);
g.fillRect(x, y, w, h);

g.setColor(0,0,0);
g.drawRect(x, y, w, h);
}
else
if(model==1)
{
int x1=x + len/2 - 2;
int x2=x +len/2 + 2;
int y1=y - 2;
int y2=y +2;

g.setColor(0,0,0);
g.drawLine(x1,y,x2,y);
g.drawLine(x1+2,y1,x1+2,y2);

if(i>0)
g.drawLine(xx,yy,x1+2,y);

xx=x1+2;
yy=y;
}
else
if(model==2)
{
int x1=x + len/2 - 2;
int x2=x + len/2 + 2;
int y1=y - 2;
int y2=y + 2;

g.setColor(0,0,0);
g.drawLine(x1,y,x2,y);
g.drawLine(x1+2,y1,x1+2,y2);
}

g.setFont(font);
g.drawString(namaBulan[i],x,yBottom+5,Graphics.LEFT,Graphics.TOP);
}
}
}

public class GrafikPenjualanBarang
extends MIDlet
implements CommandListener
{
private Display layar;
private Form formEntry;
private List listModel;
private TextField[] txtPenjualan=new TextField[12];
private Command cmdAcak;
private Command cmdGrafik;
private Command cmdModel;
private Command cmdBack;
private Command cmdPilih;
private Command cmdEXIT;
private Gambar gambar;

private int nomorUrutModel;

private String[] namaBulan=
{"Januari", "Februari", "Maret",
"April", "Mei", "Juni",
"Juli", "Agustus", "September",
"Oktober", "November", "Desember"};

private String[] pilihanModel=
{"Grafik batang", "Grafik garis", "Grafik titik"};

private static Random rnd=new Random();

public GrafikPenjualanBarang()
{
layar=Display.getDisplay(this);

cmdAcak=new Command("Acak", Command.BACK,1);
cmdGrafik=new Command("Grafik", Command.OK,1);
cmdBack=new Command("Back", Command.BACK,1);
cmdModel=new Command("Model grafik", Command.OK,1);
cmdPilih=new Command("Pilih", Command.OK,1);
cmdEXIT=new Command("EXIT", Command.OK,2);
nomorUrutModel=0;

for(int i=0; i<12; i++)
txtPenjualan[i]=new TextField(namaBulan[i]+":", "10", 4, TextField.NUMERIC);

formEntry=new Form("Entry data penjualan" ) ;
for(int i=0; i<12; i++)
formEntry.append(txtPenjualan[i]);

formEntry.addCommand(cmdAcak);
formEntry.addCommand(cmdGrafik);
formEntry.addCommand(cmdEXIT);
formEntry.setCommandListener(this);

listModel=new List("Pilihan model grafik",Choice.IMPLICIT, pilihanModel, null);
listModel.addCommand(cmdBack);
listModel.addCommand(cmdPilih);
listModel.setCommandListener(this);
listModel.setSelectCommand(cmdPilih);

gambar=new Gambar();
gambar.addCommand(cmdBack);
gambar.addCommand(cmdModel);
gambar.setCommandListener(this);
}

public void startApp()
{
layar.setCurrent(formEntry);
}

public void pauseApp()
{
}

public void destroyApp(boolean unconditional)
{
}

//
//respon terhadap penekanan keypad
//
public void commandAction(Command c, Displayable d)
{
if(c==cmdAcak)
{
for(int i=0; i<12; i++)
{
int acak = rnd.next int (991) + 10;
txtPenjualan[i].setString(Integer.toString(cmdAcak));
}
}
else
if(c==cmdGrafik)
displayGraph();
else
if(c==cmdModel)
{
listModel.setSelectedIndex(nomorUrutModel,true);
layar.setCurrent(listModel);
}
else
if(c==cmdBack)
{
if(d==listModel)
displayGraph();
else
layar.setCurrent(formEntry);
}
else
if(c==cmdPilih)
{
nomorUrutModel=listModel.getSelectedIndex();
gambar.setModel(nomorUrutModel);
layar.setCurrent(gambar);
}
else if(c==cmdEXIT)
{
destroyApp(true);
notifyDestroyed();
}
}

//
//menampilkan data gambar
//
private void displayGraph()
{
int[]nums=new int[12];

for(int i=0; i<12; i++)
nums[i]=Integer.parseInt(txtPenjualan[i].getString());
gambar.setData(nums);
layar.setCurrent(gambar);

return;
}
}
 
Offline
01-11-2009 02:55 AM RE: ask:program java
User Avatar

zeetaken
Genin


Posts: 46
Joined: 10.01.09
Age: 30
om, izin copas yach,,.... ane mo belajar nich jg,...

thnksAshamed
 
Offline
06-11-2009 06:12 PM RE: ask:program java
User Avatar

insomniacz
Genin


Posts: 50
Joined: 29.06.09
kesalahannya dimana om?? error dari segi syntax.., apa programnya gak running gak sesuai dengan keinginan...
 
Offline
Jump to Forum:
Forum powered by fusionBoard
Share this Thread
URL:
BBcode:
HTML:
Similar Threads
Thread Forum Replies Last Post
eBook Java Bahasa Indonesia Aplikasi POS Berarsitektur Three Tier Menggunakan Swing, Hibernate, da E-Book 12 03-02-2014 22:21
Dasar Pemrograman Java - Chapter02 x Input Proses Output Java 2 01-05-2012 06:23
Dasar Pemrograman Java - Chapter01 x Requirement, Compile, Error & Run Java 3 01-04-2012 10:33
(Ask) Melihat Program Yang Dibuka Pada Komputer Client Networking 7 25-06-2011 19:30
program developer yang menurut gw bagus dan lengkap Java 3 14-05-2011 04:19
Copyright © 2007-2016