Sabtu, 10 Oktober 2009

Seputar Safari

Safari merupakan penjelajah web (web browser) buatan Apple inc. Yang dijadikan browser khusus bawaan bagi sistem operasi Mac OS. Web browser ini dijadikan penjelajah web bawaan sejak sistem operasi Mac OS X v10.3. Sebelum mengggunakan penjelajah web ini, Mac OS versi sebelumnya manggunakan Internet Explorer for Mac sebagai penjelajah bawaan dari tahun 1997 hingga 2003. Namun sekarang safari uga bisa digunakan di sistem operasi Windows, karena pada 11 Juni 207, versi pertama Safari for Windows diperkenalkan pada Konferensi Apple di San Fransisco.

Versi terbaru Safari yang baru saja diluncurkan Apple inc. adalah Safari 4 beta yang memiliki featre baru dan bug fixes, termasuk fitur Cover Flow, full History search, engine JavaScript yang lebih cepat, dan berbagai fitur lainnya.

Dari segi tampilan, Safari versi empat mengalami perbaikan penampilan dan style, semakin nyaman dipandang. Selain itu, di versi terbarunya, Safari juga menyertakan Nitro Engine, yang diklaim menjadikan Safari jauh leih cepat dari web browser lainnya. Bahkan katanya Safari diklaim tiga kali lebih cepat dibandingkan FireFox dan 30 kali lebih cepat dibandingkan Internet Explorer 7.

Beberapa feature baru Safari lainnya lebih merupakan tambahan efek untuk keindahan dan kemudahan pemakaian. Sebagai contoh, feature Top Sites mirip dengan model homepage di Google Chrome yang menampilkan link ke berbagai website favorit dalam 1x klik.

Namun, karena versi 4 ini masih Beta, jadi masih memiliki kekurangan. Yaitu proxy-nya tidak bisa dirubah. Namun, ternyata proxy browser Safar imengikuti setting proxy pada Internet Explorer (setting proxy Windows), itu (mungkin) sebabnya setting proxynya tidak bisa diubah langsung dari menu Preferences.

Jumat, 19 Juni 2009

Animasi J2ME Kapal Laut

import javax.microedition.lcdui.*;
import java.io.IOException;

public class MainCanvas extends Canvas implements Runnable, CommandListener{

private Display display;
private KapalLaut midlet;

private Image image;

int x = 0;
int y = 0;

int xKotak;
int yKotak;

Command cmdNewGame = new Command("New game", Command.SCREEN, 1);
Command cmdExit = new Command("Exit", Command.SCREEN, 1);

String keterangan = "";
String c = "";

private boolean kiri = false;
private boolean kanan = true;

public MainCanvas(KapalLaut midlet, Display display){

this.midlet = midlet;
this.display = display;

xKotak = getWidth()/2 - 5;
yKotak = getHeight() - 10;

addCommand(cmdNewGame);
addCommand(cmdExit);

setCommandListener(this);

try{
image = Image.createImage("/pyg.jpg");
}
catch(IOException ioe){
}

}

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

g.drawImage(image, x, y, Graphics.TOP | Graphics.LEFT);

g.setColor(255,0,0);
g.fillRect(xKotak, yKotak, 10, 10);

g.setColor(0,0,0);
g.drawString(keterangan, getWidth()/2-20, getHeight()/2, Graphics.TOP | Graphics.LEFT);
g.drawString(c, 0, 0, Graphics.TOP|Graphics.LEFT);

}

public void commandAction(Command c, Displayable d){

if (c == cmdNewGame){
midlet.startApp();
}
if (c == cmdExit){
midlet.exitMIDlet();
}

}
public void keyPressed(int keyCode){

if (keyCode == KEY_NUM1){
kiri = true;
kanan = false;
}

if (keyCode == KEY_NUM3){
kiri = false;
kanan = true;
}

}


public void run(){

while(y <= (getHeight() - 60)){ try{ Thread.sleep(100); } catch(InterruptedException ie){ } if ((kiri) && (x > 0)){
x = x - 10;
}
else if ((kanan) && (x < (getWidth() - 60))){ x = x + 10; } y = y + 5; repaint(); } if (((x+23) >= xKotak) && (x+23 <= xKotak+13)){ keterangan = "Kapal Laut Aman"; c = "kapal laut"; } else{ keterangan = "Kapal Laut Karam"; try{ Thread.sleep(100); } catch(InterruptedException ie){ } y = y + 5; } repaint(); } } Program J2ME Kapal Laut

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

public class KapalLaut extends MIDlet{

private Display display;
private MainCanvas mainCanvas;

public KapalLaut(){

display = Display.getDisplay(this);

}

public void startApp(){

mainCanvas = new MainCanvas(this, display);
display.setCurrent(mainCanvas);

new Thread(mainCanvas).start();

}

public void pauseApp(){
}

public void destroyApp(boolean unconditional){
}

public void exitMIDlet(){

destroyApp(false);
notifyDestroyed();

}

}

Program I/O

/**
* Title : Program Arus
* Deskripsi : Membuat masukan(input) melalui tampilan GUI Sebagai interface
*/

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

public class ProgArusIo extends JFrame {
// Mendeklarasikan Tiga text Field dan atau button jumlah
private JTextField jTFInput1, jTFInput2, jTFHasil;
private JButton btnJumlah,btnSave,btnLoad,btnRefresh;
String namaBerkas1 ="Tarea.out";
String namaBerkas2 ="Tarea1.out";
String namaBerkas3 ="Tarea2.out";

/** Main method */
public static void main(String args [])
{
ProgArusIo frame = new ProgArusIo();
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

/** Konstruktor Default */
public ProgArusIo()
{
setTitle("Menghitung Arus (Ampere)");
setBackground(Color.blue);
setForeground(Color.black);

// Menggunakan panel P1 untuk mengelompokan komponen text Field

JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(0,1,0,2));
p1.add(new JLabel("Tegangan"));
p1.add(jTFInput1 = new JTextField(15));
p1.add(new JLabel("Hambatan"));
p1.add(jTFInput2 = new JTextField(15));
p1.add(new JLabel("Arus"));
p1.add(jTFHasil = new JTextField(15));
jTFHasil.setEditable(false); // Set jTFHasil menjadi non editable

// Menggunakan panel p2 untuk button penjumlahan

JPanel p2 = new JPanel();
p2.setLayout(new GridLayout(3,1,0,10));
p2.add(btnSave = new JButton("Save"));
p2.add(btnLoad = new JButton("Load"));
p2.add(btnRefresh = new JButton("Refresh"));

// Mengeset Flow Layout untuk Frame dan Menambahkan
// panel panel ke frame
JPanel p3=new JPanel();
p3.setLayout(new FlowLayout());
p3.add(btnJumlah=new JButton("Hitung Arus"));
getContentPane().setLayout(new BorderLayout());
getContentPane().add(p1, BorderLayout.CENTER);
getContentPane().add(p2, BorderLayout.EAST);
getContentPane().add(p3, BorderLayout.SOUTH);

// Me-register listener
btnJumlah.addActionListener(new ProgArusIo.PenanganTombol());
btnSave.addActionListener(new ProgArusIo.PenanganTombol());
btnLoad.addActionListener(new ProgArusIo.PenanganTombol());
btnRefresh.addActionListener(new ProgArusIo.PenanganTombol());
show();
}

/** Menangani operasi penjumlahan */

class PenanganTombol implements ActionListener {
public void actionPerformed(ActionEvent e)
{
String s = e.getActionCommand();
if (e.getSource()==btnJumlah)
{
// Mengambil nilai int dari text field dan menggunakan trim()
// untuk membuang spasi yang tidak perlu dalam text field

int volt = (Integer.parseInt(jTFInput1. getText().trim()));
int ohm = (Integer.parseInt(jTFInput2. getText() .trim()));
int hasil = volt/ohm;

// Mengeset hasil pada TextField jTFHasil
jTFHasil.setText(String.valueOf(hasil));
}
else if (s.equals("Save")) {
try {
FileWriter berkasKeluaran1= new FileWriter(namaBerkas1);
FileWriter berkasKeluaran2= new FileWriter(namaBerkas2);
FileWriter berkasKeluaran3= new FileWriter(namaBerkas3);

String isiTextArea = jTFInput1.getText();
String isi1TextArea = jTFInput2.getText();
String isiHasil = jTFHasil.getText();

berkasKeluaran1.write(isiTextArea);
berkasKeluaran2.write(isi1TextArea);
berkasKeluaran3.write(isiHasil);
berkasKeluaran1.close();
berkasKeluaran2.close();
berkasKeluaran3.close();
}
catch (IOException i) {
System.err.println("Gagal menyimpan berkas");
System.exit(1);
}
jTFInput1.setText(" Data Telah Disimpan \n");
jTFInput2.setText(" Data Telah Disimpan \n");
jTFHasil.setText(" Data Telah Disimpan \n");
}
else if (s.equals("Load")) {
try {
FileReader berkasMasukan1= new FileReader(namaBerkas1);
BufferedReader streamMasukan1=new BufferedReader(berkasMasukan1);

FileReader berkasMasukan2= new FileReader(namaBerkas2);
BufferedReader streamMasukan2= new BufferedReader(berkasMasukan2);

FileReader berkasMasukan3= new FileReader(namaBerkas3);
BufferedReader streamMasukan3= new BufferedReader(berkasMasukan3);

String teks1="";
String teks2="";
String teks3="";

while (true) {
String barisData1 = streamMasukan1.readLine();
if (barisData1 == null)
break;
teks1=teks1+barisData1 + '\n';

while (true) {
String barisData2 = streamMasukan2.readLine();
if (barisData2 == null)
break;
teks2=teks2+barisData2 + '\n';

while (true) {
String barisData3= streamMasukan3.readLine();
if (barisData3 == null)
break;
teks3=teks3+barisData3 + '\n';
}
}
}
berkasMasukan1.close();
jTFInput1.setText(teks1);
berkasMasukan2.close();
jTFInput2.setText(teks2);
berkasMasukan3.close();
jTFHasil.setText(teks3);
}

catch (IOException i) {
jTFInput1.setText("Data Error");
jTFInput2.setText("Data Error");
jTFHasil.setText("Data Error");
}
}
else if (s.equals("Refresh")) {
jTFInput1.setText("");
jTFInput2.setText("");
jTFHasil.setText("");
}
}
}
}



Gambar Input:





Gambar Setelah Disimpan:

Program Kalkulator Swing

import java.awt.*;
import java.awt.event.*;
import javax.swing.* ;
import javax.swing.JOptionPane ;
import java.io.*;

public class BasicCalc extends JFrame
implements ActionListener {

private JButton bOne, bTwo, bThree, bFour, bFive,
bSix, bSeven, bEight, bNine, bZero, bExit,
bMult, bDiv, bSub, bPlus, bEquals, bHelp,
bAbout, bDecPt, bClear ;
private JTextField enterBox ;
private JPanel textPanel, exitPanel, buttonPanel, functionPanel ;
private Container c ;
private Font font;
private String firstNum = new String(""), secondNum = new String(""), tempNum, tempStr ;
private boolean myDiag = false, result = false ,
tempfirstNumSet = false, firstNumSet = false, secondNumSet = false,
pendingOp = false ;
private double aNum, dNum1 = 0.0, dNum2 = 0.0 , answer = 0.0,
tempD = 0.0 , minusOne = -1.0 ;
private double dArray[] = new double[ 10 ] ;
private int opCode = -1, tempInt = 0, tempInt2 = 0,
dArrayPtr = 0, pendingOpCode = -1 ;


public BasicCalc() {

super( "Basic Calculator" );
setup() ;

setSize( 350, 300 ); /** sets the size of the frame */
setLocation( 200, 200 ) ; /** sets the location of the frame on the screen*/
show(); /** makes the frame visible */
}

public void setup() {
c = getContentPane() ;

/** setup the text field used on the calculator frame */
setUpTextField() ;


/** setup button Panel and the number buttons */
setUpButtons() ;

/** setup function panel and its buttons*/
setUpFunctionPanel() ;

/** setup exit panel and its buttons */
setUpExitPanel() ;

/** setup Action Listeners */
setUpActionListener() ;
}


public void setUpTextField() {
/** setup text field and panel */
enterBox = new JTextField( 15 ) ;
enterBox.setText( "0" );
firstNumSet = true ;
enterBox.setEditable( false );
enterBox.setBackground( Color.white );
enterBox.setHorizontalAlignment( JTextField.RIGHT );
enterBox.addKeyListener(
/** this code reprimes the enterbox and avoids exceptions */
new KeyAdapter() {
public void keyPressed ( KeyEvent e ) {
/* if ( result ) {
MyPrint( "The value of result is " + result +
"this is from the enterbox keylistener." );
result = false ;
enterBox.setText( "0" );
} */
}
}
);
textPanel = new JPanel() ;
textPanel.add(enterBox ) ;

c.add( textPanel , BorderLayout.NORTH ) ;
}

public void setUpButtons() {
buttonPanel = new JPanel() ;
c.add( buttonPanel , BorderLayout.CENTER ) ;

bZero = new JButton( "0" ) ;
bZero.setFont( new Font("Sanserif", Font.BOLD, 16 ) );
bOne = new JButton( "1" ) ;
bTwo = new JButton( "2" ) ;
bThree = new JButton( "3" ) ;
bFour = new JButton( "4" ) ;
bFive = new JButton( "5" ) ;
bSix = new JButton( "6" ) ;
bSeven = new JButton( "7" ) ;
bEight = new JButton( "8" ) ;
bNine = new JButton( "9" ) ;
bExit = new JButton( "Exit" ) ;
bClear = new JButton( "Clear" ) ;
bClear.setBackground( Color.blue ) ;
bClear.setForeground( Color.white );
bMult = new JButton( "*" ) ;
bMult.setFont( new Font("Sanserif", Font.BOLD, 20 ) );
bMult.setBackground( Color.blue ) ;
bMult.setForeground( Color.white );
bDiv = new JButton( "/" ) ;
bDiv.setFont( new Font("Sanserif", Font.BOLD, 20 ) );
bDiv.setBackground( Color.blue ) ;
bDiv.setForeground( Color.white );
bSub = new JButton( "-" ) ;
bSub.setFont( new Font("Sanserif", Font.BOLD, 24 ) );
bSub.setBackground( Color.blue ) ;
bSub.setForeground( Color.white );
bPlus = new JButton( "+" ) ;
bPlus.setBackground( Color.blue ) ;
bPlus.setForeground( Color.white );

bEquals = new JButton( "=" ) ;
bEquals.setFont( new Font("Sanserif", Font.BOLD, 16 ) );
bEquals.setBackground( Color.red ) ;
bEquals.setForeground( Color.white );
bDecPt = new JButton( "." ) ;
bDecPt.setFont( new Font("Sanserif", Font.BOLD, 22 ) );


/** add the following buttons to the buttonPanel panel. */
buttonPanel.add( bSeven ) ;
buttonPanel.add( bEight ) ;
buttonPanel.add( bNine ) ;

buttonPanel.add( bFour ) ;
buttonPanel.add( bFive ) ;
buttonPanel.add( bSix ) ;
buttonPanel.add( bOne ) ;
buttonPanel.add( bTwo ) ;
buttonPanel.add( bThree ) ;


buttonPanel.add( bZero ) ;
buttonPanel.add( bDecPt ) ;
buttonPanel.add( bEquals ) ;

buttonPanel.setLayout( new GridLayout( 5, 3, 5, 5 ) );
}


public void setUpActionListener() {
bDecPt.addActionListener( this );
bZero.addActionListener( this );
bOne.addActionListener( this );
bTwo.addActionListener( this );
bThree.addActionListener( this );
bFour.addActionListener( this );
bFive.addActionListener( this );
bSix.addActionListener( this );
bSeven.addActionListener( this );
bEight.addActionListener( this );
bNine.addActionListener( this );
bExit.addActionListener( this );
bMult.addActionListener( this );
bDiv.addActionListener( this );
bSub.addActionListener( this );
bPlus.addActionListener( this );
bEquals.addActionListener( this );
bClear.addActionListener( this );

bExit.addActionListener( this );
bHelp.addActionListener( this );
bAbout.addActionListener( this );
}

public void setUpFunctionPanel() {

functionPanel = new JPanel() ;
c.add( functionPanel , BorderLayout.EAST ) ;
functionPanel.setLayout( new GridLayout( 6, 1, 5, 3 ) );

functionPanel.add( bMult ) ;
functionPanel.add( bDiv ) ;
functionPanel.add( bSub ) ;
functionPanel.add( bPlus ) ;
functionPanel.add( bClear ) ;
}

public void setUpExitPanel() {
exitPanel = new JPanel() ;
c.add( exitPanel , BorderLayout.SOUTH ) ;
bExit = new JButton( "Exit" ) ;
bExit.setFont( new Font("Sanserif", Font.BOLD, 16 ) );
bExit.setBackground( Color.red ) ;
bExit.setForeground( Color.white );
bHelp = new JButton( "Help" ) ;
bHelp.setFont( new Font("Sanserif", Font.BOLD, 16 ) );
bHelp.setBackground( Color.blue ) ;
bHelp.setForeground( Color.white );
bAbout = new JButton( "About" ) ;
bAbout.setFont( new Font("Sanserif", Font.BOLD, 14 ) );
bAbout.setBackground( Color.darkGray ) ;
bAbout.setForeground( Color.white );

/** add the following buttons to the exitPanel panel. */
exitPanel.add( bExit ) ;
exitPanel.add( bHelp ) ;
exitPanel.add( bAbout ) ;

}

public void actionPerformed( ActionEvent e ) {

tempNum = "" + answer ;

if ( e.getSource() == bPlus || e.getSource() == bSub ||
e.getSource() == bMult || e.getSource() == bDiv ) {
tempNum = "" + answer ;

MyPrint( "actionPerformed() 1a: The value of result is " + result +
" The value of tempNum is " + enterBox.getText() +
" The value of opCode is " + opCode ) ;
}

if ( result ) {
/** If result =s true, set the text field to blank */
MyPrint( "actionPerformed() 1b: The value of result is " + result +
"The value of tempNum is " + enterBox.getText()
);
result = false ;
enterBox.setText( "" );
}

if ( !pendingOp && opCode == 99 ) {
/** If opCode =s 99, then the =s button was pressed */
MyPrint( "actionPerformed() 1c: The value of opCode is " + opCode +
" The value of firstNum is " + firstNum +
" The value of tempNum is " + tempNum );
pendingOpCode = -1 ;
//opCode = -1 ;
firstNumSet = true ;
firstNum = tempNum ;
enterBox.setText( "" );
}

if ( e.getSource() == bDecPt ) {
MyPrint( "The decimal point button was pressed." );
enterBox.setText( enterBox.getText() + "." ) ;
}
else if ( e.getSource() == bZero ) {
MyPrint( "The zero button was pressed. And pendingOp is " + pendingOp );
enterBox.setText( enterBox.getText() + "0" ) ;
}
else if ( e.getSource() == bOne ) {
MyPrint( "The one button was pressed. And pendingOp is " + pendingOp );
enterBox.setText( enterBox.getText() + "1" ) ;
}
else if ( e.getSource() == bTwo ) {
MyPrint( "The two button was pressed. And pendingOp is " + pendingOp );
enterBox.setText( enterBox.getText() + "2" ) ;
}
else if ( e.getSource() == bThree ) {
MyPrint( "The Three button was pressed. And pendingOp is " + pendingOp);
enterBox.setText( enterBox.getText() + "3" ) ;
}
else if ( e.getSource() == bFour ) {
MyPrint( "The Four button was pressed. And pendingOp is " + pendingOp );
enterBox.setText( enterBox.getText() + "4" ) ;
}
else if ( e.getSource() == bFive ) {
MyPrint( "The Five button was pressed. And pendingOp is " + pendingOp );
enterBox.setText( enterBox.getText() + "5" ) ;
}
else if ( e.getSource() == bSix ) {
MyPrint( "The Six button was pressed. And pendingOp is " + pendingOp );
enterBox.setText( enterBox.getText() + "6" ) ;
}
else if ( e.getSource() == bSeven ) {
MyPrint( "The Seven button was pressed. And pendingOp is " + pendingOp );
enterBox.setText( enterBox.getText() + "7" ) ;
}
else if ( e.getSource() == bEight ) {
MyPrint( "The Eight button was pressed. And pendingOp is " + pendingOp );
enterBox.setText( enterBox.getText() + "8" ) ;
}
else if ( e.getSource() == bNine ) {
MyPrint( "The Nine button was pressed. And pendingOp is " + pendingOp );
enterBox.setText( enterBox.getText() + "9" ) ;
}
else if ( e.getSource() == bExit ) {
MyPrint( "The Exit button was pressed." );
sysExit() ;
}
else if ( e.getSource() == bMult ) {
MyPrint( "The Mult button was pressed. And pendingOp is " + pendingOp );
multOp() ;
}
else if ( e.getSource() == bDiv ) {
MyPrint( "The Div button was pressed. And pendingOp is " + pendingOp );
divOp() ;
}
else if ( e.getSource() == bSub ) {
MyPrint( "The Sub button was pressed. And pendingOp is " + pendingOp );
subOp() ;
}
else if ( e.getSource() == bPlus ) {
MyPrint( "The Plus button was pressed. And pendingOp is " + pendingOp );
plusOp() ;
}
else if ( e.getSource() == bClear ) {
MyPrint( "The bClear button was pressed." );
enterBox.setText( "" ) ;
firstNum = "" ;
firstNumSet = true ;
secondNum = "" ;
answer = 0.0 ;
dNum1 = 0.0 ;
dNum2 = 0.0 ;
opCode = -1 ;
pendingOpCode = -1 ;
pendingOp = false ;
}
else if ( e.getSource() == bEquals ) {
MyPrint( "bEquals 1: The Equals button was pressed. And pendingOp is " + pendingOp +
" The opCode value is " + opCode );
if ( pendingOpCode >= 0 || pendingOpCode <= 3 ) {
MyPrint( "bEquals 2: In pendingOpCode =s " + pendingOpCode ) ;
pendingOp = true ;
opCodeMethod() ;
}
}
else if ( e.getSource() == bHelp ) {
MyPrint( "The Help button was pressed." );
File hd = new File("BasicCalc_help_doc.html");
//File net = new File("Netscp.exe");
String helpStr = hd.getAbsolutePath() ;
Runtime rt = Runtime.getRuntime();
/* String[] callAndArgs = { "c:\\Program Files\\Internet Explorer\\IExplore.exe" ,
"" +
E:\MyExamples\SimpleCalc\Calc\help_doc.html }; */
String[] callAndArgs = { "c:\\Program Files\\Internet Explorer\\IExplore.exe" ,
"" + helpStr };

try {

Process child = rt.exec( callAndArgs );
child.waitFor();
MyPrint ("Process exit code is: " +
child.exitValue());
}
catch(IOException e2) {
MyPrint (
"IOException starting process!");
}
catch(InterruptedException e3) {
System.err.println(
"Interrupted waiting for process!");
}
}
else if ( e.getSource() == bAbout ) {
MyPrint( "The About button was pressed." );
Runtime rt = Runtime.getRuntime();
String[] callAndArgs = { "c:\\Program Files\\Internet Explorer\\IExplore.exe" ,
"http://sumtotalz.com/TotalAppsWorks/index.html " };
try {
Process child = rt.exec(callAndArgs);
child.waitFor();
MyPrint ("Process exit code is: " +
child.exitValue());
}
catch(IOException e2) {
MyPrint( "IOException starting process!");
}
catch(InterruptedException e3) {
MyPrint( "Interrupted waiting for process!");
}
}

}

public void setResults() {
MyPrint( "setResults() 1: answer is " + answer + " dNum1 is " + dNum1 );

enterBox.setText( "" + answer );
firstNum = "" + answer ;
dNum1 = answer;
firstNumSet = true ;
result = true ;
pendingOp = false ;
}


public void opCodeMethod() {
int currentOpCode = -1 , tempOpCode = opCode ;
boolean temppendingOp = pendingOp ;

MyPrint( "opCodeMethod() 1: with an opCode of " + opCode );

/** Check if there is a pending operation that must
* be performed before the current operation is
* performed. */
if ( pendingOp ) {
MyPrint( "opCodeMethod() 2: with an opCode of " + opCode +
" and a pendingOpCode =s " + pendingOpCode );
currentOpCode = pendingOpCode ;
pendingOp = false ;
}
else {
currentOpCode = opCode ;
MyPrint( "opCodeMethod() 2b: with an opCode of " + opCode ) ;
}

switch ( currentOpCode ) {
case 0 :
multOp() ;
break ;
case 1 :
divOp() ;
break ;
case 2 :
MyPrint( "opCodeMethod() 3: opCode =s " + currentOpCode ) ;
subOp() ;
break ;
case 3 :
MyPrint( "opCodeMethod() 4: opCode =s " + currentOpCode ) ;
plusOp() ;
break ;
case 5 :
//powerOp() ;
break ;
default :
MyPrint( "opCodeMethod() 7: default case is " + currentOpCode );
setResults() ;
firstNumSet = true ;
secondNum = "0.0" ;
dNum2 = 0.0 ;
pendingOp = false ;
opCode = 99 ;
MyPrint( "opCodeMethod() 8: Case default: firstNum =s " + firstNum);
break ;
}

MyPrint( "opCodeMethod() 9: pendingOpCode =s " + pendingOpCode +
" pendingOp " + pendingOp );

pendingOpCode = tempOpCode ;
pendingOp = temppendingOp ;

if ( !( opCode == 99 ) )
opCode = -1 ;

}

public void multOp() {
opCode = 0 ;

MyPrint( "multOp() 1a: The opcode value is " + opCode +
" The value of firstNum is " + firstNum +
" The value of answer is " + answer ) ;

if ( pendingOpCode == 0 ) {
secondNum = enterBox.getText() ;
if ( secondNum.equals( "" ) ) {
secondNum = "0.0" ;
}
convertNumsToDouble() ;
answer = dNum1 * dNum2 ;
pendingOp = false ;
setResults() ;
MyPrint( "multOp() 2: opCode is " + opCode + " The value of answer is " + answer );
secondNum = "0.0" ;
opCode = -1 ;

}
else if ( pendingOpCode >= 1 ) {
MyPrint( "multOp() 2a: In pendingOpCode =s " + pendingOpCode ) ;
pendingOp = true ;
opCodeMethod() ;
}
else if ( opCode == 0 ) {
MyPrint( "multOp() 3: In pendingOp code. The opcode value is " + opCode ) ;
firstNum = enterBox.getText() ;
if ( secondNum.equals( "" ) ) {
secondNum = "0.0" ;
}
opCode = 0 ;
pendingOp = false ;
pendingOpCode = 0 ;
MyPrint( "multOp() 5: opCode is " + opCode + " The value of answer is " + answer );
opCode = -1 ;
result = true ;
MyPrint( "multOp() 4: pendingOpCode is " + pendingOpCode + " The value of answer is " + answer );
}

}

public void divOp() {
MyPrint( "divOp() 1a: opCode is " + opCode + " firstNumSet =s " + firstNumSet +
" pendingOpCode =s " + pendingOpCode );
opCode = 1 ;

MyPrint( "divOp() 1b: The opcode value is " + opCode +
" The value of firstNum is " + firstNum +
" The value of answer is " + answer ) ;

if ( pendingOpCode == 1 ) {
secondNum = enterBox.getText() ;
if ( secondNum.equals( "" ) ) {
secondNum = "0.0" ;
}
convertNumsToDouble() ;
if ( dNum1 == 0.0 ) {
answer = dNum1 ;
}
else if ( dNum2 == 0.0 ) {
answer = dNum1 ;
setResults() ;
JOptionPane.showMessageDialog( this, "The number " +
dNum2 + " cannot be used as a denometer.\n" +
"You cannot divide by zero.",
"Attempted to Divide by Zero",
JOptionPane.ERROR_MESSAGE );
}
else {
answer = dNum1 / dNum2 ;
}
pendingOp = false ;
setResults() ;
MyPrint( "divOp() 2: opCode is " + opCode + " The value of answer is " + answer );
secondNum = "0.0" ;
opCode = -1 ;
}
else if ( pendingOpCode == 0 || pendingOpCode == 2 || pendingOpCode == 3 ) {
MyPrint( "divOp() 2a: In pendingOpCode =s " + pendingOpCode ) ;
pendingOp = true ;
opCodeMethod() ;
}
else if ( opCode == 1 ) {
MyPrint( "divOp() 3: In pendingOp code. The opcode value is " + opCode ) ;
firstNum = enterBox.getText() ;
if ( secondNum.equals( "" ) ) {
secondNum = "0.0" ;
}
opCode = 1 ;
pendingOp = false ;
pendingOpCode = 1 ;
opCode = -1 ;
result = true ;
MyPrint( "divOp() 4: pendingOpCode is " + pendingOpCode +
" The value of answer is " + answer );
}

}

public void subOp() {
opCode = 2 ;

MyPrint( "subOp() 1a: The opcode value is " + opCode +
" The value of firstNum is " + firstNum +
" The value of answer is " + answer +
" pendingOpCode =s " + pendingOpCode ) ;

if ( pendingOpCode == 2 ) {
secondNum = enterBox.getText() ;
if ( secondNum.equals( "" ) ) {
secondNum = "0.0" ;
}
convertNumsToDouble() ;
answer = dNum1 - dNum2 ;
pendingOp = false ;
setResults() ;
MyPrint( "subOp() 2: opCode is " + opCode + " The value of answer is " + answer );
secondNum = "0.0" ;
opCode = -1 ;

}
else if ( pendingOpCode == 0 || pendingOpCode == 1 || pendingOpCode == 3 ) {
MyPrint( "subOp() 2a: In pendingOpCode =s " + pendingOpCode ) ;
pendingOp = true ;
opCodeMethod() ;
}
else if ( opCode == 2 ) {
MyPrint( "subOp() 3: In pendingOp code. The opcode value is " + opCode ) ;
firstNum = enterBox.getText() ;
if ( secondNum.equals( "" ) ) {
secondNum = "0.0" ;
}
// convertNumsToDouble() ;
// answer = dNum1 - dNum2 ;
pendingOp = true ;
pendingOpCode = 2 ;
opCode = 2 ;
result = true ;
MyPrint( "subOp() 4: pendingOpCode is " + pendingOpCode +
" The value of answer is " + answer );
}
}

ublic void plusOp() {
opCode = 3 ;

MyPrint( "plusOp() 1a: The opcode value is " + opCode +
" The value of firstNum is " + firstNum +
" The value of answer is " + answer ) ;

if ( pendingOpCode == 3 ) {
secondNum = enterBox.getText() ;
if ( secondNum.equals( "" ) ) {
secondNum = "0.0" ;
}
convertNumsToDouble() ;
answer = dNum1 + dNum2 ;
pendingOp = false ;
setResults() ;
MyPrint( "plusOp() 2: opCode is " + opCode + " The value of answer is " + answer );
secondNum = "0.0" ;
opCode = -1 ;

}
else if ( pendingOpCode == 0 || pendingOpCode == 1 || pendingOpCode == 2 ) {
MyPrint( "plusOp() 3: In pendingOpCode =s " + pendingOpCode ) ;
pendingOp = true ;
opCodeMethod() ;
}
else if ( opCode == 3 ) {
MyPrint( "plusOp() 4: In pendingOp code. The opcode value is " + opCode ) ;
firstNum = enterBox.getText() ;
if ( secondNum.equals( "" ) ) {
secondNum = "0.0" ;
}
opCode = 3 ;
pendingOp = false ;
pendingOpCode = 3 ;
MyPrint( "plusOp() 5: opCode is " + opCode + " The value of answer is " + answer );
opCode = -1 ;
result = true ;
}

}

public void convertNumsToDouble() {
if ( !firstNum.equals( "" ) ) {
dNum1 = Double.parseDouble( firstNum ) ;
}
if ( !secondNum.equals( "" ) ) {
dNum2 = Double.parseDouble( secondNum ) ;
}
MyPrint( "convertNumsToDouble(): The value of dNum1 is " + dNum1 );
MyPrint( "convertNumsToDouble(): The value of dNum2 is " + dNum2 );

}


public void sysExit() {
System.exit( 0 );

}

public void MyPrint( String str ) {
if ( myDiag )
System.out.println( str );

}

public static void main( String args[] ) {

final BasicCalc app = new BasicCalc () ; /** creates an instance of MyCalc */

app.addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent e )
{
app.sysExit() ;
}
}
);
}
}

 

blogger templates 3 columns | Make Money Online