Posted by: Sourav | October 17, 2015

miles to kilometre converter using java swing,Sourav Bhattacharya


private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
       double input=0;
     
       DecimalFormat df=new DecimalFormat(“#.##”);
       try
       {
        input=Double.parseDouble(jTextField1.getText());
       
       
       }catch(Exception e)
       {
           JOptionPane.showMessageDialog(this, “Please enter a valid number”, “Error”, JOptionPane.ERROR_MESSAGE);
       }
      
       String answer=df.format(input*1.609344f);
     jLabel2.setText(answer +” kilometers”);
      
       
       
       
    }                                       

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: