1.23.2009

Animation

Membuat sedikit animasi mugkin akan menambah indah hasil program yang dihasulkan kode berikut adalah salah satu contoh yang mungkin bisa jadi gambaran :

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

public class Animation extends MIDlet
{
private Display display; // The display
private AnimationCanvas canvas; // Canvas
private Timer tm; // Timer
private AnimateTimerTask tt; // Task

public Animation()
{
display = Display.getDisplay(this);
canvas = new AnimationCanvas(this);

// Create task that fires off every 1/10 second
tm = new Timer();
tt = new AnimateTimerTask(canvas);
tm.schedule(tt, 0, 100);
}

protected void startApp()
{
display.setCurrent(canvas);
}

protected void pauseApp()
{ }

protected void destroyApp(boolean unconditional)
{ }

public void exitMIDlet()
{
destroyApp(true);
notifyDestroyed();
}
}
class AnimateTimerTask extends TimerTask
{
private AnimationCanvas canvas;

public AnimateTimerTask(AnimationCanvas canvas)
{
this.canvas = canvas;
}

public final void run()
{
// ****************************************************
if ((canvas.x_loc + canvas.radius + canvas.x_dir > canvas.getWidth()) ||
(canvas.x_loc - canvas.radius + canvas.x_dir < 0))
{
canvas.x_dir = -canvas.x_dir;
canvas.changeColor();
canvas.directionChanged++;
}

// **************************************************
if ((canvas.y_loc + canvas.radius + canvas.y_dir > canvas.getHeight()) ||
(canvas.y_loc - canvas.radius + canvas.y_dir < 0))
{
canvas.y_dir = -canvas.y_dir;
canvas.changeColor();
canvas.directionChanged++;
}

//*********************************
canvas.x_loc += canvas.x_dir;
canvas.y_loc += canvas.y_dir;

canvas.repaint();
}
}

class AnimationCanvas extends Canvas implements CommandListener
{
private Animation midlet; // Main midlet
private Command cmExit; // Exit midlet
private int keyFire, // Reset ball
keyRight, // Increase ball radius
keyLeft; // Decrease ball radius
private boolean clearBackground = false; // Clear background
private Random random; // Random number
int x_loc, // Current x & y locations
y_loc,
radius, // Ball radius
red, // rgb colors
green,
blue,
x_dir, // Next x & y positions of ball
y_dir,
start_x, // Where ball starts
start_y,
directionChanged = 0; // How many times we've hit a wall
private static final int MAX_CHANGES = 50;

/*--------------------------------------------------
* Constructor
*-------------------------------------------------*/
public AnimationCanvas(Animation midlet)
{
// ****************************
this.midlet = midlet;

random = new java.util.Random();

// Determine starting location and direction of ball
init();
radius = 7;

// ******************************************
cmExit = new Command("Exit", Command.EXIT, 1);

keyFire = getKeyCode(FIRE);
keyRight = getKeyCode(RIGHT);
keyLeft = getKeyCode(LEFT);

addCommand(cmExit);
setCommandListener(this);
}


protected void paint(Graphics g)
{
// ********************************
if (directionChanged > MAX_CHANGES)
init();

// the background
if (clearBackground)
{
g.setColor(255, 255, 255);
g.fillRect(0, 0, getWidth(), getHeight());
clearBackground = !clearBackground;
}

// Set warna dan gambar
g.setColor(red, green, blue);
g.fillArc( x_loc, y_loc, radius, radius, 0, 360);
}

/*--------------------------------------------------
* Ini Lokasi ball
*-------------------------------------------------*/
private void init()
{
// Start close to the middle
x_loc = getWidth() / 2;
y_loc = getHeight() / 2;

// The direction the ball is heading
x_dir = (random.nextInt() % 10);
if (x_dir == 0) x_dir = 1;

y_dir = (random.nextInt() % 10);
if (y_dir == 0) y_dir = 1;

directionChanged = 0;
clearBackground = true;
changeColor();
}


protected void changeColor()
{
// The shift is to remove any sign (negative) bit
red = (random.nextInt() >>> 1) % 256;
green = (random.nextInt() >>> 1) % 256;
blue = (random.nextInt() >>> 1) % 256;
}

/*--------------------------------------------------
* Event handling
*-------------------------------------------------*/
public void commandAction(Command c, Displayable d)
{
if (c == cmExit)
midlet.exitMIDlet();
}


protected void keyPressed(int keyCode)
{
// Restart
if (keyCode == keyFire)
init();
// Decrease ball size
else if (keyCode == keyLeft)
radius = Math.max(1, --radius);
else if (keyCode == keyRight)
// Increase ball size
radius = Math.min(getWidth() / 4, ++radius);
}
}

Baca Selengkapnya......

Contoh Text-Box Midlet

Lansung pada pokoknya hehe.. kita akan buat contoh program text Box Midlet... ketikan aja kode dibawah ini ya....!

import java.io.*;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;

import javax.microedition.lcdui.*;

import javax.microedition.midlet.MIDlet;

public class TextBoxMIDlet extends TextBoxMIDlet implements CommandListener {

// Exit command
private static final Command EXIT_COMMAND =
new Command("Exit", Command.EXIT, 0);

// OK command
private static final Command OK_COMMAND =
new Command("OK", Command.OK, 0);

// Clear text box content
private static final Command CLEAR_COMMAND =
new Command("Clear", Command.SCREEN, 1);

// Reverse the content of the text box
private static final Command REVERSE_COMMAND =
new Command("Reverse", Command.SCREEN, 1);

protected void startApp() {
boolean firstTime = !started;
super.startApp();

// If this is the first execution
// of startApp, install commands
if (firstTime) {
textBox.addCommand(OK_COMMAND);
textBox.addCommand(EXIT_COMMAND);
textBox.addCommand(CLEAR_COMMAND);
textBox.addCommand(REVERSE_COMMAND);
textBox.setCommandListener(this);
}
}

// Command implementations.
public void commandAction(Command c, Displayable d) {
if (c == EXIT_COMMAND) {
destroyApp(true);
notifyDestroyed();
} else if (c == OK_COMMAND) {
System.out.println("OK pressed");
} else if (c == CLEAR_COMMAND) {
textBox.setString(null);
} else if (c == REVERSE_COMMAND) {
String str = textBox.getString();
if (str != null) {
StringBuffer sb = new StringBuffer(str);
textBox.setString(sb.reverse().toString());
}
}
}
}

class TextBoxMIDlet extends MIDlet {

// Maximum size of the text in the TextBox
private static final int MAX_TEXT_SIZE = 64;

// The TextBox
protected TextBox textBox;

// The MIDlet's Display object
protected Display display;

// Flag indicating first call of startApp
protected boolean started;

protected void startApp() {
if (!started) {
// First time through - initialize
// Get the text to be displayed
String str = null;
try {
InputStream is = getClass().getResourceAsStream("test.txt");
InputStreamReader r = new InputStreamReader(is);
char[] buffer = new char[32];
StringBuffer sb = new StringBuffer();
int count;
while ((count = r.read(buffer, 0, buffer.length)) > -1) {
sb.append(buffer, 0, count);
}
str = sb.toString();
} catch (IOException ex) {
str = "Failed to load text";
}

// Create the TextBox
textBox = new TextBox("TextBox Example", str,
MAX_TEXT_SIZE, TextField.ANY);

// Create a ticker and install it
Ticker ticker = new Ticker("This is a ticker...");
textBox.setTicker(ticker);

// Install the TextBox as the current screen
display = Display.getDisplay(this);
display.setCurrent(textBox);

started = true;
}
}

protected void pauseApp() {
}

protected void destroyApp(boolean unconditional) {
}
}

Baca Selengkapnya......

WindowClosingExample

Kala Kita membuat program di dekstop kadang tanda silang yang berada pada jendela hasil eksekusi program tidak bisa ditutup, mungkin karena ada beberapa komponen yang belum dimasukan, sebagai contoh program mungkin kode dibawah ini bisa jadi rujukan buat pembaca sekalian.


package org.kodejava.example.swing;

import java.awt.Button;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;

public class WindowClosingExample extends JFrame {
public static void main(String[] args) {
WindowClosingExample frame = new WindowClosingExample();
frame.setSize(new Dimension(200, 200));
frame.add(new Button("Hello World"));

//
// Add window listener by implementing WindowAdapter class to the
// frame instance. To handle the close event we just need to implement
// the windowClosing() method.
//
frame.addWindowListener(new WindowAdapter() {

@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});

//
// Show the frame
//
frame.setVisible(true);
}
}

Baca Selengkapnya......

Tool Tips dengan Swing

Kalau kita menggerakan mouse melewati suatu objek di dekstop, kadang kita akan melihat
tulisan muncul dengan tiba-tibaatau dengan kata lain adalah Tool Tips yang berfungsi untuk memberikan keterangan tentang funsi suatu objek yang terlewati oleh mouse, pada contoh kali ini kita akan membuat tool tips dengan mengunakan java swing.

kode ini bisa di jalankan pada semua IDE nya java...
ketikan kode berikut ini :

package org.kodejava.example.swing;

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

public class MultilinesToolTip {
public static void main(String[] args) {
JFrame frame = new JFrame("Tool Tip Demo");
frame.setSize(200, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JLabel label = new JLabel("Tool Tips");

//
// Setting tool tip for our Swing JLabel component using an html
// formatted string so that we can create a multi lines tool tip.
//
label.setToolTipText(
"Coba ToolTips");
frame.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER));
frame.getContentPane().add(label);

frame.setVisible(true);}}

Baca Selengkapnya......

FormattedTextFieldExample JFrame

Langsung saja deh kali ini kita membuat contoh aplikasi Format TextField di dekstop,
ketikan kode yang ada disini :

package org.kodejava.example.swing;

import javax.swing.*;
import javax.swing.text.MaskFormatter;
import javax.swing.text.DateFormatter;
import java.awt.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Date;

public class FormattedTextFieldExample extends JFrame {
public FormattedTextFieldExample() {
initComponents();
}

private void initComponents() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(new Dimension(200, 200));
getContentPane().setLayout(new FlowLayout(FlowLayout.LEFT));

MaskFormatter mask = null;
try {
//
// Create a MaskFormatter for accepting phone number, the # symbol accept
// only a number. We can also set the empty value with a place holder
// character.
//
mask = new MaskFormatter("(###) ###-####");
mask.setPlaceholderCharacter('_');
} catch (ParseException e) {
e.printStackTrace();
}

//
// Create a formatted text field that accept a valid phone number.
//
JFormattedTextField phoneField = new JFormattedTextField(mask);
phoneField.setPreferredSize(new Dimension(100, 20));

//
// Here we create a formatted text field that accept a date value. We
// create an instance of SimpleDateFormat and use it to create a
// DateFormatter instance which will be passed to the JFormattedTextField.
//
DateFormat format = new SimpleDateFormat("dd-MMMM-yyyy");
DateFormatter df = new DateFormatter(format);
JFormattedTextField dateField = new JFormattedTextField(df);
dateField.setPreferredSize(new Dimension(100, 20));
dateField.setValue(new Date());

getContentPane().add(phoneField);
getContentPane().add(dateField);
}

public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new FormattedTextFieldExample().setVisible(true);
}
});
}
}

Baca Selengkapnya......

GameActions


Kali ini kita akan membuat Gambe actions, dengan menggunakan menginport Midletnya sekalian. IDE yang digunakan dalam contoh ini adalah Net-Beans 5.5 dengan mobility-nya...!
lansung saja buat project baru di Net_Beansnya dengan nama file GameAction, lalu ketikan kode dibawah ini :

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class GameActions extends MIDlet
{
private Display display; // The display
private GameActionCanvas canvas; // Canvas

public GameActions()
{
display = Display.getDisplay(this);
canvas = new GameActionCanvas(this);
}

protected void startApp()
{
display.setCurrent( canvas );
}

protected void pauseApp()
{ }

protected void destroyApp( boolean unconditional )
{ }

public void exitMIDlet()
{
destroyApp(true);
notifyDestroyed();
}
}

/*--------------------------------------------------
* GameActionCanvas.java
*
* Game action event handling
*-------------------------------------------------*/
class GameActionCanvas extends Canvas implements CommandListener
{
private Command cmExit; // Exit midlet
private String keyText = null; // Key code text
private GameActions midlet;

/*--------------------------------------------------
* Constructor
*-------------------------------------------------*/
public GameActionCanvas(GameActions midlet)
{
this.midlet = midlet;

// Create exit command & listen for events
cmExit = new Command("Exit", Command.EXIT, 1);
addCommand(cmExit);
setCommandListener(this);
}

/*--------------------------------------------------
* Paint the text representing the key code
*-------------------------------------------------*/
protected void paint(Graphics g)
{
// Clear the background (to white)
g.setColor(255, 255, 255);
g.fillRect(0, 0, getWidth(), getHeight());

// Set color and draw text
if (keyText != null)
{
// Draw with black pen
g.setColor(0, 0, 0);
// Center the text
g.drawString(keyText, getWidth()/2, getHeight()/2, Graphics.TOP | Graphics.HCENTER);
}
}

/*--------------------------------------------------
* Command event handling
*-------------------------------------------------*/
public void commandAction(Command c, Displayable d)
{
if (c == cmExit)
midlet.exitMIDlet();
}

/*--------------------------------------------------
* Game action event handling
* A game action will be converted into a key code
* and handed off to this method
*-------------------------------------------------*/
protected void keyPressed(int keyCode)
{
switch (getGameAction(keyCode))
{
// Place logic of each action inside the case
case FIRE:
case UP:
case DOWN:
case LEFT:
case RIGHT:
case GAME_A:
case GAME_B:
case GAME_C:
case GAME_D:
default:
// Print the text of the game action
keyText = getKeyName(keyCode);
}
repaint();
}
}

Baca Selengkapnya......

1.16.2009

Membuat Kalkulator dengan J Creator

MEmbuat Kalkulator dengan Menggunakan J Creator
Tidak terlalu sulit, yang penting di PC Mu sudah ada minimal J2SDK lalu J Creator, Lalu Copy kan Kode Dibawah ini :

import java.awt.*;
import java.awt.event.*;

public class CalculatorH2_DIIITKJ
{

Font Bold=new Font("Helvetica", Font.BOLD, 20);
Label TampilanLayar = new Label("MULAI",Label.RIGHT);
Label TampilanLayarkiri = new Label("",Label.RIGHT);
Label TampilanLayarkanan = new Label("",Label.CENTER);
Button Panggil_Simpanan=new Button("MR");
Button Bersihkan_Simpanan=new Button("MC");


public void map_KalkulOgut()
{
event_handler e1=new event_handler ( );
Frame KalkulOgut=new Frame(" ................................... ");
KalkulOgut.setResizable(true);
KalkulOgut.setSize(520,400);
KalkulOgut.setBackground(Color.blue);
KalkulOgut.setLayout(null);


//Tampilan Display. bisa di edit menggunakan Label
TampilanLayar.setBounds(70,50,360,40);
TampilanLayar.setFont(new Font("Helvetica", Font.BOLD, 25));
TampilanLayar.setForeground(Color.white);
TampilanLayar.setBackground(Color.red);
KalkulOgut.add(TampilanLayar);

TampilanLayarkanan.setBounds(68,48,364,44);
TampilanLayarkanan.setFont(new Font("Algerian", Font.BOLD, 40));
TampilanLayarkanan.setForeground(Color.red);
TampilanLayarkanan.setBackground(Color.green);
KalkulOgut.add(TampilanLayarkanan);

//Menambah Tombol 1 sampai dengan 0
Button simpanan=new Button("M+");
simpanan.setBounds(72,96,60,34);
simpanan.setBackground(Color.white);
simpanan.setForeground(Color.red);
simpanan.setFont(Bold);
simpanan.addActionListener(e1);
KalkulOgut.add(simpanan);

Bersihkan_Simpanan.setEnabled(false);
Bersihkan_Simpanan.setBounds(136,96,60,34);
Bersihkan_Simpanan.setBackground(Color.black);
Bersihkan_Simpanan.setForeground(Color.red);
Bersihkan_Simpanan.setFont(Bold);
Bersihkan_Simpanan.addActionListener(e1);
KalkulOgut.add(Bersihkan_Simpanan);

Panggil_Simpanan.setBounds(200,96,60,34);
Panggil_Simpanan.setBackground(Color.yellow);
Panggil_Simpanan.setForeground(Color.red);
Panggil_Simpanan.setFont(Bold);
Panggil_Simpanan.addActionListener(e1);
Panggil_Simpanan.setEnabled(false);
KalkulOgut.add(Panggil_Simpanan);

Button satu=new Button("1");
satu.setBounds(72,134,60,34);
satu.setBackground(Color.orange);
satu.setFont(Bold);
satu.addActionListener(e1);
KalkulOgut.add(satu);

Button dua=new Button("2");
dua.addActionListener(e1);
dua.setBackground(Color.orange);
dua.setBounds(136,134,60,34);
dua.setFont(Bold);
KalkulOgut.add(dua);

Button tiga=new Button("3");
tiga.addActionListener(e1);
tiga.setBackground(Color.orange);
tiga.setBounds(200,134,60,34);
tiga.setFont(Bold);
KalkulOgut.add(tiga);

Button empat=new Button("4");
empat.setBackground(Color.orange);
empat.addActionListener(e1);
empat.setFont(Bold);
empat.setBounds(72,172,60,34);
KalkulOgut.add(empat);

Button lima=new Button("5");
lima.setBackground(Color.orange);
lima.addActionListener(e1);
lima.setFont(Bold);
lima.setBounds(136,172,60,34);
KalkulOgut.add(lima);

Button enam=new Button("6");
enam.setBackground(Color.orange);
enam.addActionListener(e1);
enam.setFont(Bold);
enam.setBounds(200,172,60,34);
KalkulOgut.add(enam);

Button tujuh=new Button("7");
tujuh.setBackground(Color.orange);
tujuh.addActionListener(e1);
tujuh.setFont(Bold);
tujuh.setBounds(72,210,60,34);
KalkulOgut.add(tujuh);

Button delapan=new Button("8");
delapan.setBackground(Color.orange);
delapan.addActionListener(e1);
delapan.setFont(Bold);
delapan.setBounds(136,210,60,34);
KalkulOgut.add(delapan);

Button sembilan=new Button("9");
sembilan.setBackground(Color.orange);
sembilan.addActionListener(e1);
sembilan.setFont(Bold);
sembilan.setBounds(200,210,60,34);
KalkulOgut.add(sembilan);

Button kosong=new Button("0");
kosong.setBackground(Color.orange);
kosong.addActionListener(e1);
kosong.setFont(Bold);
kosong.setBounds(136,248,60,34);
KalkulOgut.add(kosong);

Button nanin =new Button("STIMIK - IKMI CIREBON");
nanin.setForeground(Color.red);
nanin.setBackground(Color.green);
nanin.addActionListener(e1);
nanin.setFont(Bold);
nanin.setBounds(72,290,358,50);
KalkulOgut.add(nanin);

Label simbol =new Label("BRAVO MAHASISWA DIII TKJ KELAS H2 STIMIK ",Label.LEFT);
simbol.setForeground(Color.white);
simbol.setFont(Bold);
simbol.setBounds(33,350,550,50);
KalkulOgut.add(simbol);

//Tombol operasi
Button TombolBagi = new Button("BAGI");
TombolBagi.setBackground(Color.gray);
TombolBagi.addActionListener(e1);
TombolBagi.setBounds(264,134,100,34);
TombolBagi.setForeground(Color.green);
TombolBagi.setFont(Bold);
KalkulOgut.add(TombolBagi);

Button TombolKali = new Button("KALI");
TombolKali.setBackground(Color.gray);
TombolKali.addActionListener(e1);
TombolKali.setBounds(264,172,100,34);
TombolKali.setForeground(Color.green);
TombolKali.setFont(Bold);
KalkulOgut.add(TombolKali);

Button TombolPengurangan = new Button("KIRANG");
TombolPengurangan.setBackground(Color.gray);
TombolPengurangan.addActionListener(e1);
TombolPengurangan.setBounds(264,210,100,34);
TombolPengurangan.setForeground(Color.green);
TombolPengurangan.setFont(Bold);
KalkulOgut.add(TombolPengurangan);

Button TombolTambah= new Button("TAMBIH");
TombolTambah.setBackground(Color.gray);
TombolTambah.addActionListener(e1);
TombolTambah.setBounds(264,248,100,34);
TombolTambah.setForeground(Color.green);
TombolTambah.setFont(Bold);
KalkulOgut.add(TombolTambah);

Button titik= new Button(".");
titik.setBackground(Color.gray);
titik.addActionListener(e1);
titik.setBounds(200,248,60,34);
titik.setForeground(Color.green);
titik.setFont(Bold);
KalkulOgut.add(titik);

Button TombolTambahKurang = new Button("+/-");
TombolTambahKurang.setBackground(Color.gray);
TombolTambahKurang.addActionListener(e1);
TombolTambahKurang.setBounds(72,248,60,34);
TombolTambahKurang.setForeground(Color.green);
TombolTambahKurang.setFont(Bold);
KalkulOgut.add(TombolTambahKurang);

Button Pembersih = new Button("C");
Pembersih.setBackground(Color.red);
Pembersih.addActionListener(e1);
Pembersih.setBounds(370,134,60,34);
Pembersih.setForeground(Color.white);
Pembersih.setFont(Bold);
KalkulOgut.add(Pembersih);

Button persenBae = new Button("%");
persenBae.setBackground(Color.gray);
persenBae.addActionListener(e1);
persenBae.setBounds(370,172,60,34);
persenBae.setForeground(Color.green);
persenBae.setFont(Bold);
KalkulOgut.add(persenBae);

Button satu_Dibagi_X = new Button("1/x");
satu_Dibagi_X.setBackground(Color.gray);
satu_Dibagi_X.addActionListener(e1);
satu_Dibagi_X.setBounds(370,210,60,34);
satu_Dibagi_X.setForeground(Color.green);
satu_Dibagi_X.setFont(Bold);
KalkulOgut.add(satu_Dibagi_X);

Button SamiSareng = new Button("=");
SamiSareng.setBackground(Color.gray);
SamiSareng.addActionListener(e1);
SamiSareng.setBounds(370,248,60,34);
SamiSareng.setForeground(Color.green);
SamiSareng.setFont(Bold);
KalkulOgut.add(SamiSareng);
KalkulOgut.setVisible(true);
}
public static void main(String args[])
{

CalculatorH2_DIIITKJ m1=new CalculatorH2_DIIITKJ();
m1.map_KalkulOgut();
}
String temp="";
String sign="";
double result=0;

//Membuat perubahan Hasil = sebelum 0

double temp_minus=0;
boolean flag_minus_first=true;
boolean mul_flag=true;
double mul_temp=1;
double memory;
boolean memory_flag=false;
boolean divide_flag=true;
double divide_temp=1;
boolean mr_flag=false;

///Penggunaan mekanisme untuk penggunaan memori;
boolean point_flag=true;

//boolean tambah_bagi_kurang_flag=true;
private class event_handler
implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String cmd=e.getActionCommand();
System.out.println(cmd);

//****************************************************************************

if(cmd=="+/-")
{
//Tambah_bagi_pengurangan_flag=true
//apabila pemakai telah menekan tombol +/- maka nilai dari temp akan ditampikan di layar
//tampilan tidak menyaring hasil dari variabel

if(temp!="" )
//&& plus_slash_minus_flag==true && )
{
if(Double.parseDouble(temp)>0)
{
temp=("KIRANG"+ temp);
System.out.println("temp="+temp);
TampilanLayar.setText(temp);
}
else if(Double.parseDouble(temp)<0)
{
temp=temp.substring(1,temp.length());
System.out.println("temp="+temp);

TampilanLayar.setText(temp);
}

//tambah_slash_kurang_flag=false;
}

//enters when user press +/- and value from result variable is showing
//on screen in that case temp is always empty conditionly
if(temp==" " )

//&& plus_slash_minus_flag==false)
{
String pm="";
pm=String.valueOf(result);
if(result>0)
{
pm="KIRANG"+pm;
result=Double.parseDouble(pm);
TampilanLayar.setText(String.valueOf(result));
pm="";
}
else if(result<0)
{
pm=pm.substring(1,pm.length());
result=Double.parseDouble(pm);
TampilanLayar.setText(String.valueOf(result));
pm="";
}
System.out.println("result="+result);
}
}

//****************************************************************************
//******************

if(cmd=="%")
{
point_flag=true;
if(temp!="")
{
result=result/Double.parseDouble(temp);
result=result*100;
TampilanLayar.setText(String.valueOf(result));
}
// kontruksi ada dibawah ini
}
//****************************************************************************
// kemandirian operasi

if(cmd=="1/x")
{
point_flag=true;
if(temp!="")
{
double byx=0;
byx=Double.parseDouble(temp);
byx=1/byx;
temp=String.valueOf(byx);
TampilanLayar.setText(temp);
}
if(temp=="")
{
result=1/result;
TampilanLayar.setText(String.valueOf(result));
}

//kontruksi dibawah ini juga coy...!
}
//****************************************************************************
//if(cmd=="+/-")
//{
//poin_flag=true;
//}
//****************************************************************************

if(cmd=="MC")
{
point_flag=true;
//Harus menambahkan flag comaon dalam semua operasi
//dan harus dicatat bila ada penambahan oprasi baru setelah di bawah ini
memory_flag=false;

//mempunyai makna tidak ada nilai yang di simpan dalam M+
memory=0;
Panggil_Simpanan.setEnabled(false);
Bersihkan_Simpanan.setEnabled(false);
}

//****************************************************************************
//******************

if(cmd=="M+")
{
point_flag=true;
if(mr_flag==false)

//yang di gunakan untuk menyimpan dari suatu hasil
if(temp!="")
{
memory_flag=true;
temp=TampilanLayar.getText();
memory=Double.parseDouble(temp);
mul_flag=false;
flag_minus_first=false;
divide_flag=false;
Panggil_Simpanan.setEnabled(true);
Bersihkan_Simpanan.setEnabled(true);
}
if(mr_flag==true)
{
System.out.println("ENTERED IN M+ where mr_flad=false");

memory_flag=true;
result=Double.parseDouble(TampilanLayar.getText());
memory=result;
mul_flag=false;
flag_minus_first=false;
divide_flag=false;
mr_flag=false;
Panggil_Simpanan.setEnabled(true);
Bersihkan_Simpanan.setEnabled(true);
}
}
//****************************************************************************
if(cmd=="MR")
{
point_flag=true;
if(memory_flag==true)
//pemeriksaan nomor berapa saja yang disimpan dengan penggunaan M+
{
temp=String.valueOf(memory);
TampilanLayar.setText(temp);
}
}
//****************************************************************************
if(cmd=="BAGI")
{
point_flag=true;
if(sign=="KIRANG" && temp!="")
{
result=result-
Double.parseDouble(temp);
TampilanLayar.setText(String.valueOf(result));
temp="";
divide_flag=false;
}
if(sign=="TAMBIH" && temp!="")
{
result=Double.parseDouble(temp)+result;
TampilanLayar.setText(String.valueOf(result));
temp="";
divide_flag=false;
}
if(sign=="KALI" && temp!="")
{
result=result*Double.parseDouble(temp);
TampilanLayar.setText(String.valueOf(result));
temp="";
divide_flag=false;
}
sign="BAGI";
if(temp!="")
{
if(divide_flag==true)
{
divide_temp=Double.parseDouble(temp)/divide_temp;
System.out.println("Divide_temp="+divide_temp);
TampilanLayar.setText(String.valueOf(divide_temp));
temp="";
divide_flag=false;
result=divide_temp;
System.out.println("result="+result);
}
if(divide_flag==false && temp!="")
{
result=result/Double.parseDouble(temp);
TampilanLayar.setText(String.valueOf(result));
System.out.println("result="+result);
temp="";
}
}
}
//****************************************************************************
//******************
if(cmd=="KALI")
{
point_flag=true;
if(sign=="BAGI" && temp!="")
{
result=result/Double.parseDouble(temp);
TampilanLayar.setText(String.valueOf(result));
System.out.println("result="+result);
temp="";
mul_flag=false;
}
if(sign=="TAMBIH" && temp!="")
{
result=Double.parseDouble(temp)+result;
TampilanLayar.setText(String.valueOf(result));
temp="";
mul_flag=false;

//pengujian statemen beta
}
if(sign=="KIRANG" && temp!="")
{
result=result-Double.parseDouble(temp);
TampilanLayar.setText(String.valueOf(result));
temp="";
mul_flag=false;

/// pengujian statemen beta ;
}
sign="KALI";
if(temp!="")
{
if(mul_flag==true)
{
System.out.println("Entered in X where temp!=empty");
mul_temp=mul_temp*Double.parseDouble(temp);
TampilanLayar.setText(String.valueOf(mul_temp));
temp="";
result=mul_temp;
System.out.println("result="+result);
mul_flag=false;
}
else
{
System.out.println("Entered in cmd=X and where mul_flag=false");
result=result*Double.parseDouble(temp);
TampilanLayar.setText(String.valueOf(result));////////////////
temp="";
}
}
}

//****************************************************************************
//******************
if(cmd=="TAMBIH")
{
point_flag=true;
if(sign=="BAGI" && temp!="")
{
result=result/Double.parseDouble(temp);
TampilanLayar.setText(String.valueOf(result));
System.out.println("result="+result);
temp="";
}
if(sign=="KALI" && temp!="")
{
result=result*Double.parseDouble(temp);
TampilanLayar.setText(String.valueOf(result));
temp="";
}
if(sign=="KIRANG" && temp!="")

//e.g 2-2+4 for this like operation
{
result=result-Double.parseDouble(temp);
TampilanLayar.setText(String.valueOf(result));
temp="";
}
sign="TAMBIH";
if(temp!="")
{
mul_flag=false;
System.out.println("Entered in + temp!=empty ");
result=Double.parseDouble(temp)+result;
TampilanLayar.setText(String.valueOf(result));
temp="";
System.out.println("result="+result);
System.out.println(String.valueOf(temp));
}
else
{
}
}

//****************************************************************************
//******************
if(cmd=="KIRANG")
{
point_flag=true;
if(sign=="BAGI" && temp!="")
{
result=result/Double.parseDouble(temp);
TampilanLayar.setText(String.valueOf(result));
System.out.println("result="+result);
temp="";
flag_minus_first=false;
}
if(sign=="KALI" && temp!="")
{
result=result*Double.parseDouble(temp);
TampilanLayar.setText(String.valueOf(result));
temp="";
flag_minus_first=false;
}
if(sign=="TAMBIH" && temp!="")

//jika pengguna memasukan 2-2+ atau nomer manapun
{
result=Double.parseDouble(temp)+result;
TampilanLayar.setText(String.valueOf(result));
temp="";
flag_minus_first=false;
}
sign="KIRANG";
if(temp!="")
{
mul_flag=false;
System.out.println(" Entered in - where temp!=empty ");
if(flag_minus_first==true)

//kapan pertama kali pemakai melaksanakan-operasi setelah mulai program
{
result=Double.parseDouble(temp)-result;
flag_minus_first=false;
System.out.println(result);
}
else
{
result=result-Double.parseDouble(temp);
System.out.println(result);
}
TampilanLayar.setText(String.valueOf(result));
temp="";
}
}

//****************************************************************************
if(cmd=="=")
{
point_flag=true;
if(sign=="TAMBIH")
if(temp!="")
{
mul_flag=false;
divide_flag=false;
flag_minus_first=false;

//pengujian kemungkinan pemindahan
result=Double.parseDouble(temp)+result;
TampilanLayar.setText(String.valueOf(result));
sign="";
temp="";
System.out.println("Hasil="+result);
mr_flag=true;

///penggunaan memori untuk pemanggilan mekanisme
}
if(sign=="KIRANG")
if(temp!="")
{
mul_flag=false;
divide_flag=false;
flag_minus_first=false;

//pengujian kemungkinan pemindahan
result=result-Double.parseDouble(temp);
TampilanLayar.setText(String.valueOf(result));
sign="";
temp="";
System.out.println("result="+result);
mr_flag=true;

///penggunaan memori untuk pemanggilan mekanisme
}
if(sign=="KALI")
if(temp!="")
{
mul_flag=false;
divide_flag=false;
flag_minus_first=false;

//pengujian kemungkinan pemindahan
result=result*Double.parseDouble(temp);
TampilanLayar.setText(String.valueOf(result));
sign="";
temp="";
mr_flag=true;

///penggunaan memori untuk pemanggilan mekanisme
//mul_temp=1;
}
if(sign=="BAGI")
if(temp!="")
{
mul_flag=false;
divide_flag=false;
flag_minus_first=false;

//pengujian kemungkinan pemindahan
result=result/Double.parseDouble(temp);
TampilanLayar.setText(String.valueOf(result));
sign="";
temp="";
mr_flag=true;

///penggunaan memori untuk pemanggilan mekanisme
}
if(sign=="")
if(temp!="")
//pengujian kemungkinan pemindahan
{
result=Double.parseDouble(TampilanLayar.getText());
System.out.println("result="+TampilanLayar.getText());
mul_flag=false;
mr_flag=true;
///penggunaan memori untuk pemanggilan mekanisme (tkj tea pikirkeunuen.just kidul..he.he.)
}
temp="";
}
//****************************************************************************
//******************

if(cmd=="."||cmd=="0" || cmd=="1" ||
cmd=="2" || cmd=="3" || cmd=="4" || cmd=="5" || cmd=="6" || cmd=="7" ||
cmd=="8" || cmd=="9")
{
if(cmd=="." && temp=="" && point_flag==true)
{
temp="0";
temp=temp+cmd;
point_flag=false;
}
else if(cmd=="." && temp!="" && point_flag==true)
{
temp=temp+cmd;
point_flag=false;
}
//temp=temp+cmd;
else if(cmd!=".")
temp=temp+cmd;
TampilanLayar.setText(temp);
System.out.println("temp"+temp);
mr_flag=false;
}

//****************************************************************************
//******************
if(cmd=="C")
{
//tambah_slash_minus_flag=true;
point_flag=true;
mr_flag=false;
divide_temp=1;
divide_flag=true;
mul_flag=true;
temp="";
TampilanLayar.setText("SALAM HANGAT MHS TKJ H2");
result=0;
sign="";
flag_minus_first=true;
mul_temp=1;
System.out.println("result="+result);
System.out.println("temp="+temp);
}

//****************************************************************************


}
}

}

Baca Selengkapnya......
Template by : kendhin x-template.blogspot.com