30-10-2009 12:23 PM
ask:program java | Edited by
bad_samt 30-10-2009 12:34 PM
bad_samt Anbu
Posts: 269
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;
}
}
31-10-2009 07:55 PM
RE:
ask:program java
zeetaken Genin
Posts: 46
Joined: 10.01.09
Age: 36
om, izin copas yach,,.... ane mo belajar nich jg,...
thnks
06-11-2009 11:12 AM
RE:
ask:program java
insomniacz Genin
Posts: 50
Joined: 29.06.09
kesalahannya dimana om?? error dari segi syntax.., apa programnya gak running gak sesuai dengan keinginan...
Jump to Forum:
Peraturan Forum
Pengumuman
Absen Member baru
Bingung??? disini ajah...
Kritik & Saran
C/C++
Java
PHP
Visual Basic
Out Of Topic Programing
Windows
Networking
Mac & Apple Family
Open Source OS
Mobile Phone OS
Explore CMS PHP-Fusion
Post Your PHP-Fusion Site Here.
Info Security
Black & White Proof of Concept
E-Book
MP3 Album
Video
Software
Manga / Comic
Share Proof of Concept Your Design
Out Of Topic
Info Seminar, Event, Pameran, Etc
Can't Speak Indonesian? Post Here
Share Pengetahuan Umum