Thursday 26 April 2012

Calculator Program in Java

TitleCalculator Program in Java
AuthorSathish Kumar .S
Author Emailmail2sathish [at] programmer.net
DescriptionThis is a GUI oriented Simple Calculator program.
CategoryJava » GUI
Hits152142
CodeSelect and Copy the Code 

/**
  This is a simple calculator program can any one take and use.

  @author sathish_ssmca
  @param nothing */
import javax.swing.*;
import javax.swing.JOptionPane;
import java.awt.*;
import java.awt.event.*;
//<applet code=Calculator height=300 width=200></applet>
public class Calculator extends JApplet {
   public void init() {
      CalculatorPanel calc=new CalculatorPanel();
      getContentPane().add(calc);
      }
   }

   class CalculatorPanel extends JPanel implements ActionListener {
      JButton
n1,n2,n3,n4,n5,n6,n7,n8,n9,n0,plus,minus,mul,div,dot,equal;
      static JTextField result=new JTextField("0",45);
      static String lastCommand=null;
      JOptionPane p=new JOptionPane();
      double preRes=0,secVal=0,res;

      private static void assign(String no)
        {
         if((result.getText()).equals("0"))
            result.setText(no);
          else if(lastCommand=="=")
           {
            result.setText(no);
            lastCommand=null;
           }
          else
            result.setText(result.getText()+no);
         }

      public CalculatorPanel() {
         setLayout(new BorderLayout());
         result.setEditable(false);
         result.setSize(300,200);
         add(result,BorderLayout.NORTH);
         JPanel panel=new JPanel();
         panel.setLayout(new GridLayout(4,4));

         n7=new JButton("7");
         panel.add(n7);
         n7.addActionListener(this);
         n8=new JButton("8");
         panel.add(n8);
         n8.addActionListener(this);
         n9=new JButton("9");
         panel.add(n9);
         n9.addActionListener(this);
         div=new JButton("/");
         panel.add(div);
         div.addActionListener(this);

         n4=new JButton("4");
         panel.add(n4);
         n4.addActionListener(this);
         n5=new JButton("5");
         panel.add(n5);
         n5.addActionListener(this);
         n6=new JButton("6");
         panel.add(n6);
         n6.addActionListener(this);
         mul=new JButton("*");
         panel.add(mul);
         mul.addActionListener(this);

         n1=new JButton("1");
         panel.add(n1);
         n1.addActionListener(this);
         n2=new JButton("2");
         panel.add(n2);
         n2.addActionListener(this);
         n3=new JButton("3");
         panel.add(n3);
         n3.addActionListener(this);
         minus=new JButton("-");
         panel.add(minus);
         minus.addActionListener(this);

         dot=new JButton(".");
         panel.add(dot);
         dot.addActionListener(this);
         n0=new JButton("0");
         panel.add(n0);
         n0.addActionListener(this);
         equal=new JButton("=");
         panel.add(equal);
         equal.addActionListener(this);
         plus=new JButton("+");
         panel.add(plus);
         plus.addActionListener(this);
         add(panel,BorderLayout.CENTER);
      }
      public void actionPerformed(ActionEvent ae)
         {
      if(ae.getSource()==n1) assign("1");
      else if(ae.getSource()==n2) assign("2");
      else if(ae.getSource()==n3) assign("3");
      else if(ae.getSource()==n4) assign("4");
      else if(ae.getSource()==n5) assign("5");
      else if(ae.getSource()==n6) assign("6");
      else if(ae.getSource()==n7) assign("7");
      else if(ae.getSource()==n8) assign("8");
      else if(ae.getSource()==n9) assign("9");
      else if(ae.getSource()==n0) assign("0");
      else if(ae.getSource()==dot)
            {
             if(((result.getText()).indexOf("."))==-1)
                result.setText(result.getText()+".");
           }
      else if(ae.getSource()==minus)
             {
             preRes=Double.parseDouble(result.getText());
             lastCommand="-";
             result.setText("0");
             }
      else if(ae.getSource()==div)
             {
             preRes=Double.parseDouble(result.getText());
             lastCommand="/";
             result.setText("0");
             }
      else if(ae.getSource()==equal)
             {
             secVal=Double.parseDouble(result.getText());
             if(lastCommand.equals("/"))
                  res=preRes/secVal;
             else if(lastCommand.equals("*"))
                  res=preRes*secVal;
             else if(lastCommand.equals("-"))
                  res=preRes-secVal;
             else if(lastCommand.equals("+"))
                  res=preRes+secVal;
             result.setText(" "+res);
             lastCommand="=";
             }
      else if(ae.getSource()==mul)
             {
              preRes=Double.parseDouble(result.getText());
              lastCommand="*";
              result.setText("0");
              }
      else if(ae.getSource()==plus)
              {
              preRes=Double.parseDouble(result.getText());
              lastCommand="+";
              result.setText("0");
              }

       }
 }

Tuesday 10 January 2012

Car Shot and Burnt at Freeport Area, Two Dead


VIVAnews – Trailer inspector’s vehicle, KPI LWB 01-3608, which was owned by PT Freeport Indonesia was targeted gunshots in Freeport mining areas in Papua. Afterwards, a group of unidentified men set the car on fire on Monday, Jan 9.

The incident took place in Poros Tambang road, mile 51. “The investigation at the crime scene shows that the vehicle was shot by unknown men from both sides of the road as it passed through mile 32 toward Tembagapura mining area. The vehicle then rolled over and burned by the unidentified men,” said Papua Police spokesman, Chief. Comm. Wachyono on Tuesday, Jan 10.

He added that two passengers of the vehicle were found dead. “Thomas Bagenta, the driver, was found with burns under the vehicle. Meanwhile Nasyun Naboht Simopiaref was found 1.5 meters away from the vehicle with cut injuries to his neck and right check,” he explained.

The evidences found on the scene, he added, were a black bag containing areca nuts; another bag contained 3 shells of 5,56 caliber of FNB 84, 2 shells of 5,56 caliber of TJPLN. “A projectile was found in Nasyun’s body which brought the possibility that he had been shot,” Wachyono said.

According to Wachyono, police have yet to conclude the perpetrators as well as the motives behind the shootings.

Thomas’ body has been flown to Jakarta for autopsy in Cipto Mangunkusumo hospital. Police are still discussing with family members to perform autopsy over Nasyun’s body.

Four Freeport’s employees and security guards have been questioned in relation with this case as witnesses.

Monday 9 January 2012

Menghentikan Restart Automatic Updates pada Komputer

gb1

Pada Artikel kali ini saya akan berbagi tentang Bagaimana cara menghentikan Automatic Update pada windows. Sebagai pengguna Windows kita pasti menemukan masalah dengan automatic Update , yang membawa Komputer kita terdapat pilihan untuk merestart. Atau muncul pilihan Restart Dialogue Box.

Saya yakin, sobat pernah berurusan dengan hal ini. Itu muncul setiap sepuluh menit setelah update sistem utama. Untungnya, hal itu dapat di atasi. Berikut adalah cara-caranya.


Langkah 1
Buka Notepad.(Start= Run="Notepad")
gb2
Tuliskan pada Notepad, ketikkan perintah “net stop wuauserv” (tanpa tanda kutip seperti yang ditunjukkan pada gambar di atas). Kemudian tutup jendela, dan pilih "Ya" untuk menyimpan perubahan.

Langkah 2
Membuat file bat dari notepad
gb3

Disini kita sedang membuat sebuah file eksekusi batch yang akan menjalankan perintah ketika diklik ganda, untuk menghentikan Windows Update Layanan Otomatis. Pastikan bahwa "Save as type" disetel ke "All Files". Simpan file Anda dengan ekstensi "bat." Misalnya “stop this.bat” seperti yang ditunjukkan gambar di atas.

Langkah 3
Seperti ini icon file bat yang telah anda buat tadi.
gb4
Halah malah mas Tukul yang nongol.maaf...yang bener di bawah ini.

gb4a
Kita cukup klik kiri 2x icon file tersebut untuk menjalankan dan menghentikan layanan Update otomatis pada windows. Dan hasilnya Komputer kita sudah bebas dari gangguan restart dari update otomatis layanan ini.

Salam