Pages

Rabu, 18 April 2012

PROGRAM KODE ASCII

Listing Program
package testascii.app;
import javax.swing.JOptionPane;
public class TestAscii extends javax.swing.JFrame {

    public TestAscii() {
        initComponents();
    }
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
         String str = jTextField1.getText() ;
     long num = Long.parseLong ( str ) ;
     long rem;
        while ( num > 0 ){
       rem = num % 10 ;
       num = num / 10 ;
       if ( rem != 0 && rem != 1 ){
         JOptionPane.showMessageDialog( null,"Ini bukan bilangan biner" ) ;
       }
     }
     int i= Integer.parseInt ( str, 2 ) ;
     jTextField2.setText(String.valueOf(i));
     jLabel3.setText(String.valueOf((char) i));
    }                 
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
for(int i=0;i<=128;i++)
        {
            jTextArea1.append("Codenya: "+i+" ASCII NYA:"+String.valueOf((char)i)+"\n");
        }   
   public static void main(String args[]) {
      
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new TestAscii().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                    
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration                  
}

Output


Tidak ada komentar:

Posting Komentar