Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 25.22 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3.  
  4. import java.awt.event.ActionListener;
  5. import java.awt.BorderLayout;
  6. import java.awt.Color;
  7. import java.awt.Container;
  8. import java.awt.FlowLayout;
  9. import java.awt.Font;
  10. import java.awt.GridLayout;
  11. import java.awt.Window;
  12. import java.awt.event.KeyAdapter;
  13. import java.awt.event.ActionEvent;
  14. import java.awt.event.ActionListener;
  15. import java.awt.event.KeyEvent;
  16. import java.awt.event.WindowAdapter;
  17. import java.awt.event.WindowEvent;
  18.  
  19. import javax.swing.JButton;
  20. import javax.swing.JDialog;
  21. import javax.swing.JFrame;
  22. import javax.swing.JLabel;
  23. import javax.swing.JMenu;
  24. import javax.swing.JMenuBar;
  25. import javax.swing.JMenuItem;
  26. import javax.swing.JPanel;
  27. import javax.swing.JTextArea;
  28. import javax.swing.KeyStroke;
  29.  
  30. public class NumberConvertor1 extends JFrame {
  31.     // Variables
  32.     //final int MAX_INPUT_LENGTH = 20;
  33.     final int INPUT_MODE = 0;
  34.     final int RESULT_MODE = 1;
  35.     final int ERROR_MODE = 2;
  36.     int displayMode;
  37.      public static final int WIDTH = 600;
  38.     public static final int HEIGHT = 300;
  39.     public static final int LINES = 10;
  40.     public static final int CHAR_PER_LINE = 20;
  41.      public JTextField octString, DecString;
  42.     private JTextArea theText;
  43.     boolean clearOnNextDigit, percent;
  44.     double lastNumber;
  45.     String lastOperator;
  46.  
  47.     public JMenu jmenuFile, jmenuHelp;
  48.     public JMenuItem jmenuitemExit, jmenuitemAbout;
  49.    
  50.     public JLabel jlbOutput;
  51.     public JButton jbnButtons[];
  52.     public JPanel jplMaster, jplBackSpace, jplControl;
  53.    
  54.     /*
  55.      * Font(String name, int style, int size)
  56.       Creates a new Font from the specified name, style and point size.
  57.      */
  58.       /** This method is called from within the constructor to
  59.      * initialize the form.
  60.      * WARNING: Do NOT modify this code. The content of this method is
  61.      * always regenerated by the Form Editor.
  62.      */
  63.      
  64.     Font f12 = new Font("Times New Roman", 0, 12);
  65.     Font f121 = new Font("Times New Roman", 1, 12);
  66.    
  67.      /** Creates new form NewJFrame */
  68.      
  69.     // Variables declaration - do not modify//GEN-BEGIN:variables
  70.       private JLabel Binaries;
  71.       private JButton jButton1;
  72.       private JButton jButton2;
  73.       private JDesktopPane jDesktopPane1;
  74.       private JEditorPane jEditorPane1;
  75.       private JLabel jLabel1;
  76.       private JLabel jLabel2;
  77.       private JLabel jLabel3;
  78.       private JPanel contentPane;
  79.       private JRadioButton jRadioButton1;
  80.       private JRadioButton jRadioButton2;
  81.       private JRadioButton jRadioButton3;
  82.       private JScrollPane jScrollPane1;
  83.       private JScrollPane jScrollPane2;
  84.       private JTextField field [] = new JTextField[16];
  85.         private JTextField jTextField2;
  86.       private JTextPane jTextPane1;
  87.       private String type;
  88.    
  89.         // Constructor
  90.     public NumberConvertor1()
  91.     {
  92.              super();
  93.             addWindowListener(new WindowAdapter() {
  94.  
  95.                 public void windowClosed(WindowEvent e)
  96.                 {
  97.                     System.exit(0);
  98.                 }
  99.             }
  100.         );
  101.         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  102.         jmenuitemAbout  = new JMenuItem("About Conversion");
  103.         jmenuitemAbout.setFont(f12);
  104.         //jmenuHelp.add(jmenuitemAbout);
  105.  
  106.      initComponents();
  107.     //
  108.     // TODO: Add any constructor code after initializeComponent call
  109.     //
  110.      
  111.      this.setVisible(true);
  112.    
  113.         /* Set Up the JMenuBar.
  114.          * Have Provided All JMenu's with Mnemonics
  115.          * Have Provided some JMenuItem components with Keyboard Accelerators
  116.          */
  117.        
  118.         jmenuFile = new JMenu("File");
  119.         jmenuFile.setFont(f121);
  120.         jmenuFile.setMnemonic(KeyEvent.VK_F);
  121.        
  122.         jmenuitemExit = new JMenuItem("Exit");
  123.        
  124.         jmenuitemExit.setFont(f12);
  125.         jmenuitemExit.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_X,
  126.                                                     ActionEvent.CTRL_MASK));
  127.         jmenuFile.add(jmenuitemExit);
  128.  
  129.         jmenuHelp = new JMenu("Help");
  130.         jmenuHelp.setFont(f121);
  131.         jmenuHelp.setMnemonic(KeyEvent.VK_H);
  132.  
  133.    
  134.        
  135.         JMenuBar mb = new JMenuBar();
  136.         mb.add(jmenuFile);
  137.         mb.add(jmenuHelp);
  138.         setJMenuBar(mb);
  139.         setSize(WIDTH, HEIGHT);
  140.       setTitle("Number Convertor");
  141.       Container contentPane = getContentPane( );
  142.       contentPane.setLayout(new BorderLayout( ));
  143.    
  144.         //Set frame layout manager
  145.  
  146.         setBackground(Color.gray);
  147.  
  148.         jplMaster = new JPanel();
  149.  
  150.         jlbOutput = new JLabel("0");
  151.         jlbOutput.setHorizontalTextPosition(JLabel.RIGHT);
  152.         jlbOutput.setBackground(Color.WHITE);
  153.         jlbOutput.setOpaque(true);
  154.        
  155.         // Add components to frame
  156.         getContentPane().add(jlbOutput, BorderLayout.NORTH);
  157.        
  158.     }
  159.    
  160.      private void initComponents() {
  161.      
  162.      contentPane = new JPanel();
  163.      jLabel1 = new JLabel();
  164.      jLabel2 = new JLabel();
  165.      jButton1 = new JButton();
  166.      jButton2 = new JButton();
  167.      jDesktopPane1 = new JDesktopPane();
  168.      jRadioButton1 = new JRadioButton();
  169.      jRadioButton2 = new JRadioButton();
  170.      jRadioButton3 = new JRadioButton();
  171.      Binaries = new JLabel();
  172.      jLabel3 = new JLabel();
  173.      for(int i=0; i<16; i++){
  174.         field[i] = new JTextField(); }
  175.      jScrollPane1 = new JScrollPane();
  176.      jEditorPane1 = new JEditorPane();
  177.      jTextField2 = new JTextField();
  178.      jScrollPane2 = new JScrollPane();
  179.      jTextPane1 = new JTextPane();
  180.      type ="";
  181.    
  182.      
  183.      contentPane.setBackground(Color.GREEN);
  184.      //contentPane.setForeground(Color.White);
  185.      contentPane.setLayout(null);
  186.      
  187.      //jLabel1.setForeground(new Color(255, 255, 255));
  188.      jLabel1.setText("Entered value :");
  189.      jLabel1.setBounds(210, 100,110, 20);
  190.      contentPane.add(jLabel1);
  191.      
  192.      jLabel2.setFont(new Font("Times New Roman", 0, 12)); // NOI18N
  193.      //jLabel2.setForeground(Color.RED);
  194.      jLabel2.setText("Error output");
  195.      jLabel2.setBounds(50, 100, 100,20)   ;
  196.      contentPane.add(jLabel2);
  197.      
  198.      
  199.      jButton1.setText("Submit");
  200.      // jButton1 get1Button = new jButton1("Submit");
  201.         //get1Button.addActionListener(this);
  202.      jButton1.addActionListener(
  203.         new ActionListener() {
  204.            
  205.            public void actionPerformed(ActionEvent e) {
  206.          
  207.              jButton1ActionPerformed(e);
  208.          
  209.           }
  210.            });
  211.          jButton1.setBounds(250, 140,90,25);
  212.      contentPane.add(jButton1);
  213.      
  214.      jButton2.setText("Clear");
  215.      jButton2.addActionListener(
  216.         new ActionListener() {
  217.            
  218.            public void actionPerformed(ActionEvent e) {
  219.              jButton2ActionPerformed(e);
  220.           }
  221.            });
  222.      jButton2.setBounds(360, 140, 70, 25);
  223.      contentPane.add(jButton2);
  224.      
  225.      jRadioButton1.setText("Binary");
  226.      jRadioButton1.addActionListener(
  227.         new ActionListener() {
  228.            
  229.            public void actionPerformed(ActionEvent e) {
  230.              jRadioButton1ActionPerformed(e);
  231.           }
  232.            });
  233.      jRadioButton1.setBounds(100, 40, 60, 23);
  234.      jDesktopPane1.add(jRadioButton1, JLayeredPane.DEFAULT_LAYER);
  235.      
  236.      jRadioButton2.setText("Octal");
  237.      jRadioButton2.addActionListener(
  238.         new ActionListener() {
  239.            
  240.            public void actionPerformed(ActionEvent e) {
  241.              jRadioButton2ActionPerformed(e);
  242.           }
  243.            });
  244.      
  245.      jRadioButton2.setBounds(200, 40, 60, 23);
  246.      
  247.      jDesktopPane1.add(jRadioButton2, JLayeredPane.DEFAULT_LAYER);
  248.      
  249.      jRadioButton3.setText("Hexadecimal");
  250.      jRadioButton3.addActionListener(
  251.         new ActionListener() {
  252.            
  253.            public void actionPerformed(ActionEvent e) {
  254.              jRadioButton3ActionPerformed(e);
  255.           }
  256.            });
  257.      jRadioButton3.setBounds(300, 40, 60, 23);
  258.      jDesktopPane1.add(jRadioButton3, JLayeredPane.DEFAULT_LAYER);
  259.       ButtonGroup radio = new ButtonGroup();
  260.     radio.add(jRadioButton1);
  261.     radio.add(jRadioButton2);
  262.     radio.add(jRadioButton3);
  263.  
  264.  
  265.  
  266.      Binaries.setFont(new Font("Times New Roman", 1, 12));
  267.      Binaries.setText("OUTPUT VALUES");
  268.      Binaries.setBounds(20, 10, 70, 20);
  269.      jDesktopPane1.add(Binaries, JLayeredPane.DEFAULT_LAYER);
  270.      
  271.      jLabel3.setFont(new Font("Times New Roman", 1, 12));
  272.      jLabel3.setText("BASE VALUES :");
  273.      jLabel3.setBounds(10, 44, 90, 20);
  274.      jDesktopPane1.add(jLabel3, JLayeredPane.DEFAULT_LAYER);
  275.       ////////////////////////////////////////////////////////////////////////////////////////
  276.      field[13].setText("0");
  277.      field[13].addActionListener(
  278.         new ActionListener() {
  279.            
  280.            public void actionPerformed(ActionEvent e) {
  281.              jTextField1ActionPerformed(e);
  282.           }
  283.            });
  284.      field[13].addKeyListener(
  285.         new KeyAdapter() {
  286.            
  287.            public void keyTyped(KeyEvent e) {
  288.              jTextField1KeyTyped(e);
  289.           }
  290.            });
  291.      field[13].setBounds(350, 10, 20, 20);
  292.      jDesktopPane1.add(field[13], JLayeredPane.DEFAULT_LAYER);
  293.      
  294.      field[12].setText("0");
  295.      field[12].addKeyListener(
  296.         new KeyAdapter() {
  297.            
  298.            public void keyTyped(KeyEvent e) {
  299.              jTextField3KeyTyped(e);
  300.           }
  301.            });
  302.      field[12].setBounds(330, 10, 20, 20);
  303.      jDesktopPane1.add(field[12], JLayeredPane.DEFAULT_LAYER);
  304.      
  305.      field[11].setText("0");
  306.      field[11].addKeyListener(
  307.         new KeyAdapter() {
  308.            
  309.            public void keyTyped(KeyEvent e) {
  310.              jTextField4KeyTyped(e);
  311.           }
  312.            });
  313.      field[11].setBounds(310, 10, 20, 20);
  314.      jDesktopPane1.add(field[11], JLayeredPane.DEFAULT_LAYER);
  315.      
  316.      field[10].setText("0");
  317.      field[10].addKeyListener(
  318.         new KeyAdapter() {
  319.            
  320.            public void keyTyped(KeyEvent e) {
  321.              jTextField5KeyTyped(e);
  322.           }
  323.            });
  324.      field[10].setBounds(290, 10, 20, 20);
  325.      jDesktopPane1.add(field[10], JLayeredPane.DEFAULT_LAYER);
  326.      
  327.      field[9].setText("0");
  328.      field[9].addKeyListener(
  329.         new KeyAdapter() {
  330.            
  331.            public void keyTyped(KeyEvent e) {
  332.              jTextField6KeyTyped(e);
  333.           }
  334.            });
  335.      field[9].setBounds(270, 10, 20, 20);
  336.      jDesktopPane1.add(field[9], JLayeredPane.DEFAULT_LAYER);
  337.      
  338.      field[8].setText("0");
  339.      field[8].addKeyListener(
  340.         new KeyAdapter() {
  341.            
  342.            public void keyTyped(KeyEvent e) {
  343.              jTextField7KeyTyped(e);
  344.           }
  345.            });
  346.      field[8].setBounds(250, 10, 20, 20);
  347.      jDesktopPane1.add(field[8], JLayeredPane.DEFAULT_LAYER);
  348.      
  349.      field[7].setText("0");
  350.      field[7].addKeyListener(
  351.         new KeyAdapter() {
  352.            
  353.            public void keyTyped(KeyEvent e) {
  354.              jTextField8KeyTyped(e);
  355.           }
  356.            });
  357.      field[7].setBounds(230, 10, 20, 20);
  358.      jDesktopPane1.add(field[7], JLayeredPane.DEFAULT_LAYER);
  359.      
  360.      field[6].setText("0");
  361.      field[6].addKeyListener(
  362.         new KeyAdapter() {
  363.            
  364.            public void keyTyped(KeyEvent e) {
  365.              jTextField9KeyTyped(e);
  366.           }
  367.            });
  368.      field[6].setBounds(210, 10, 20, 20);
  369.      jDesktopPane1.add(field[6], JLayeredPane.DEFAULT_LAYER);
  370.      
  371.      field[5].setText("0");
  372.      field[5].addKeyListener(
  373.         new KeyAdapter() {
  374.            
  375.            public void keyTyped(KeyEvent e) {
  376.              jTextField10KeyTyped(e);
  377.           }
  378.            });
  379.      field[5].setBounds(190, 10, 20, 20);
  380.      jDesktopPane1.add(field[5], JLayeredPane.DEFAULT_LAYER);
  381.      
  382.      field[4].setText("0");
  383.      field[4].addKeyListener(
  384.         new KeyAdapter() {
  385.            
  386.            public void keyTyped(KeyEvent e) {
  387.              jTextField11KeyTyped(e);
  388.           }
  389.            });
  390.      field[4].setBounds(170, 10, 20, 20);
  391.      jDesktopPane1.add(field[4], JLayeredPane.DEFAULT_LAYER);
  392.      
  393.      field[3].setText("0");
  394.      field[3].addKeyListener(
  395.         new KeyAdapter() {
  396.            
  397.            public void keyTyped(KeyEvent e) {
  398.              jTextField12KeyTyped(e);
  399.           }
  400.            });
  401.      field[3].setBounds(150, 10, 20, 20);
  402.      jDesktopPane1.add(field[3], JLayeredPane.DEFAULT_LAYER);
  403.      
  404.      field[2].setText("0");
  405.      field[2].addKeyListener(
  406.         new KeyAdapter() {
  407.            
  408.            public void keyTyped(KeyEvent e) {
  409.              jTextField13KeyTyped(e);
  410.           }
  411.            });
  412.      field[2].setBounds(130, 10, 20, 20);
  413.      jDesktopPane1.add(field[2], JLayeredPane.DEFAULT_LAYER);
  414.      
  415.      field[1].setText("0");
  416.      field[1].addKeyListener(
  417.         new KeyAdapter() {
  418.            
  419.            public void keyTyped(KeyEvent e) {
  420.              jTextField14KeyTyped(e);
  421.           }
  422.            });
  423.      field[1].setBounds(110, 10, 20, 20);
  424.      jDesktopPane1.add(field[1], JLayeredPane.DEFAULT_LAYER);
  425.      
  426.      field[0].setText("0");
  427.      field[0].addKeyListener(
  428.         new KeyAdapter() {
  429.            
  430.            public void keyTyped(KeyEvent e) {
  431.              jTextField15KeyTyped(e);
  432.           }
  433.            });
  434.      field[0].setBounds(90, 10, 20, 20);
  435.      jDesktopPane1.add(field[0], JLayeredPane.DEFAULT_LAYER);
  436.      
  437.      field[14].setText("0");
  438.      field[14].addActionListener(
  439.         new ActionListener() {
  440.            
  441.            public void actionPerformed(ActionEvent e) {
  442.              jTextField16ActionPerformed(e);
  443.           }
  444.            });
  445.      field[14].addKeyListener(
  446.         new KeyAdapter() {
  447.            
  448.            public void keyTyped(KeyEvent e) {
  449.              jTextField16KeyTyped(e);
  450.           }
  451.            });
  452.      field[14].setBounds(370, 10, 20, 20);
  453.      jDesktopPane1.add(field[14], JLayeredPane.DEFAULT_LAYER);
  454.      field[15].setText("0");
  455.      field[15].addActionListener(
  456.         new ActionListener() {
  457.            
  458.            public void actionPerformed(ActionEvent e) {
  459.            //  jTextField17ActionPerformed(e);
  460.           }
  461.            });
  462.      field[15].addKeyListener(
  463.         new KeyAdapter() {
  464.            
  465.            public void keyTyped(KeyEvent e) {
  466.              //jTextField17KeyTyped(e);
  467.           }
  468.            });
  469.      field[15].setBounds(390, 10, 20, 20);
  470.      jDesktopPane1.add(field[15], JLayeredPane.DEFAULT_LAYER);
  471.         ////////////////////////////////////////////////////////////////////////////////////////
  472.      
  473.        // contentPane.add(jDesktopPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 10, 430, 70));
  474.      jDesktopPane1.setBounds(50, 10, 430, 70);
  475.      contentPane.add(jDesktopPane1);
  476.      
  477.      //jEditorPane1.setEditable(false);
  478.      //jEditorPane1.setText("range [1 , 65535]");
  479.      //jScrollPane1.setViewportView(jEditorPane1);
  480.        // contentPane.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 120, -1, 70));
  481.      jScrollPane1.setBounds(40, 120,130, 80);
  482.      contentPane.add(jScrollPane1);
  483.      
  484.      jTextField2.setText("Null");
  485.      jTextField2.setEditable(true);
  486.      jTextField2.addActionListener(
  487.         new ActionListener() {
  488.            
  489.            public void actionPerformed(ActionEvent e) {
  490.              jTextField2ActionPerformed(e);
  491.           }
  492.            });
  493.      jTextField2.addKeyListener(
  494.         new KeyAdapter() {
  495.            
  496.            public void keyTyped(KeyEvent e) {
  497.              jTextField2KeyTyped(e);
  498.           }
  499.            });
  500.      jTextField2.setBounds(320, 100, 120, 20);
  501.      contentPane.add(jTextField2);
  502.     //contentPane.add(jTextField2, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 100, 150, 20));
  503.      
  504.      jTextPane1.setBackground(Color.BLUE);
  505.      jTextPane1.setEditable(false);
  506.      jTextPane1.setFont(new Font("Times New Roman", 1, 20));
  507.      jTextPane1.setText("Number Convertor");
  508.      //jTextPane1.setLineWrap(true);
  509.     //jTextPane1.setWrapStyleWord(true);
  510.      jScrollPane2.setViewportView(jTextPane1);
  511.      
  512.      GroupLayout layout = new GroupLayout(getContentPane());
  513.      getContentPane().setLayout(layout);
  514.      layout.setHorizontalGroup(
  515.         layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(contentPane, GroupLayout.DEFAULT_SIZE, 520, Short.MAX_VALUE).addContainerGap()).addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(0, 0, 0).addComponent(jScrollPane2, GroupLayout.PREFERRED_SIZE, 540, GroupLayout.PREFERRED_SIZE).addGap(0, 0, Short.MAX_VALUE))));
  516.      layout.setVerticalGroup(
  517.         layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap(76, Short.MAX_VALUE).addComponent(contentPane, GroupLayout.PREFERRED_SIZE, 230, GroupLayout.PREFERRED_SIZE).addContainerGap()).addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE).addComponent(jScrollPane2, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE).addGap(247, 247, 247))));
  518.      
  519.      setSize(520, 260);
  520.      setVisible(true);
  521.      
  522.      pack();
  523.       }// </editor-fold>//GEN-END:initComponents
  524.        private void error(int n){
  525.      if (n==1){
  526.         jEditorPane1.setText("Invalid input for function!");
  527.      
  528.      }
  529.      if(n==2){
  530.         System.out.println("Enter your digit");
  531.         JOptionPane.showMessageDialog(null,"Enter your digit");
  532.      }
  533.       }
  534.        private void jButton1ActionPerformed(ActionEvent e){//GEN-FIRST:event_jButton1ActionPerformed
  535.     // TODO add your handling code here:
  536.          //int val [] =null;
  537.     for(int i =0;i<field.length; i++){
  538.         field[i].setText("0");}
  539.      int k=0;
  540.      String s="";
  541.      if(jRadioButton1.isSelected()){
  542.         try{
  543.           // k =Integer.parseInt(JOptionPane.showInputDialog("Enter decimal: \n 0<= number <= 2^16"));
  544.            k =Integer.parseInt(jTextField2.getText());
  545.         if(k>65535){
  546.           error(1);}
  547.            else{
  548.           s =Integer.toBinaryString(k);
  549.           jTextField2.setText(""+k);
  550.           System.out.printf("\nBinary \t\t: %s\n",s);
  551.           k =16-s.length();
  552.           for (int i =0; i<s.length(); i++,k++){
  553.              field [k].setText(""+Integer.parseInt(s.charAt(i)+""));
  554.             field[k].setForeground(Color.ORANGE);
  555.             field[k].setFont(new Font("Times New Roman", 1, 12));
  556.           }
  557.            }
  558.         }
  559.         catch(NumberFormatException er){
  560.           error(2);
  561.            }
  562.        
  563.      }
  564.      else if(jRadioButton2.isSelected()){
  565.         try{
  566.           // k =Integer.parseInt(JOptionPane.showInputDialog("Enter decimal: \n 0<= number <= 2^16"));
  567.             k =Integer.parseInt(jTextField2.getText());
  568.         s =Integer.toOctalString(k);
  569.            jTextField2.setText(""+k);
  570.            System.out.printf("\nOctal \t\t: %s\n",s);
  571.            k =16-s.length();
  572.            for (int i =0; i<s.length(); i++,k++){
  573.           field [k].setText(""+Integer.parseInt(s.charAt(i)+""));
  574.            }
  575.         }
  576.         catch(NumberFormatException er){
  577.           error(2);               }
  578.      }
  579.      else if(jRadioButton3.isSelected()){
  580.         try{
  581.         k =Integer.parseInt(jTextField2.getText());
  582.            //k =Integer.parseInt(JOptionPane.showInputDialog("Enter decimal: \n 0<= number <= 2^16"));
  583.            s =Integer.toHexString(k);
  584.            jTextField2.setText(""+k);
  585.            System.out.printf("\nHexadecimal \t\t: %s\n",s);
  586.            k =16-s.length();
  587.            for (int i =0; i<s.length(); i++,k++){
  588.           field [k].setText((s.charAt(i)+""));
  589.            }         }
  590.         catch(NumberFormatException er){
  591.           error(2);               }
  592.      }
  593.      else{
  594.         JOptionPane.showMessageDialog(null,"You did not select convert type Binary | Octal | Hexadecimal");
  595.      }
  596.       }//GEN-LAST:event_jButton1ActionPerformed
  597.    
  598.        private void jButton2ActionPerformed(ActionEvent e) {//GEN-FIRST:event_jButton2ActionPerformed
  599.     // TODO add your handling code here:
  600.      jRadioButton1.setEnabled(true);
  601.      jRadioButton2.setEnabled(true);
  602.      jRadioButton3.setEnabled(true);
  603.      type ="";
  604.      for(int i =0;i<field.length; i++){
  605.         field[i].setText("0");}
  606.       }//GEN-LAST:event_jButton2ActionPerformed
  607.    
  608.        private void jRadioButton1ActionPerformed(ActionEvent e) {//GEN-FIRST:event_jRadioButton1ActionPerformed
  609.     // TODO add your handling code here:
  610.      type ="B";
  611.     // jRadioButton2.setEnabled(false);
  612.     // jRadioButton3.setEnabled(false);
  613.       }//GEN-LAST:event_jRadioButton1ActionPerformed
  614.      
  615.        private void jRadioButton2ActionPerformed(ActionEvent e) {//GEN-FIRST:event_jRadioButton1ActionPerformed
  616.     // TODO add your handling code here:
  617.      type ="O";
  618.     // jRadioButton1.setEnabled(false);
  619.     // jRadioButton3.setEnabled(false);
  620.       }//GEN-LAST:event_jRadioButton1ActionPerformed
  621.    
  622.        private void jRadioButton3ActionPerformed(ActionEvent e) {//GEN-FIRST:event_jRadioButton3ActionPerformed
  623.     // TODO add your handling code here:
  624.      type ="H";
  625.      //jRadioButton2.setEnabled(false);
  626.     // jRadioButton1.setEnabled(false);
  627.       }//GEN-LAST:event_jRadioButton3ActionPerformed
  628.    
  629.        private void jTextField1ActionPerformed(ActionEvent e) {//GEN-FIRST:event_jTextField1ActionPerformed
  630.     // TODO add your handling code here:
  631.       }//GEN-LAST:event_jTextField1ActionPerformed
  632.    
  633.        private void jTextField1KeyTyped(KeyEvent e) {//GEN-FIRST:event_jTextField1KeyTyped
  634.     // TODO add your handling code here:
  635.       }//GEN-LAST:event_jTextField1KeyTyped
  636.    
  637.        private void jTextField3KeyTyped(KeyEvent e) {//GEN-FIRST:event_jTextField3KeyTyped
  638.     // TODO add your handling code here:
  639.       }//GEN-LAST:event_jTextField3KeyTyped
  640.    
  641.        private void jTextField4KeyTyped(KeyEvent e) {//GEN-FIRST:event_jTextField4KeyTyped
  642.     // TODO add your handling code here:
  643.       }//GEN-LAST:event_jTextField4KeyTyped
  644.    
  645.        private void jTextField5KeyTyped(KeyEvent e) {//GEN-FIRST:event_jTextField5KeyTyped
  646.     // TODO add your handling code here:
  647.       }//GEN-LAST:event_jTextField5KeyTyped
  648.    
  649.        private void jTextField6KeyTyped(KeyEvent e) {//GEN-FIRST:event_jTextField6KeyTyped
  650.     // TODO add your handling code here:
  651.       }//GEN-LAST:event_jTextField6KeyTyped
  652.    
  653.        private void jTextField7KeyTyped(KeyEvent e) {//GEN-FIRST:event_jTextField7KeyTyped
  654.     // TODO add your handling code here:
  655.       }//GEN-LAST:event_jTextField7KeyTyped
  656.    
  657.        private void jTextField8KeyTyped(KeyEvent e) {//GEN-FIRST:event_jTextField8KeyTyped
  658.     // TODO add your handling code here:
  659.       }//GEN-LAST:event_jTextField8KeyTyped
  660.    
  661.        private void jTextField9KeyTyped(KeyEvent e) {//GEN-FIRST:event_jTextField9KeyTyped
  662.     // TODO add your handling code here:
  663.       }//GEN-LAST:event_jTextField9KeyTyped
  664.    
  665.        private void jTextField10KeyTyped(KeyEvent e) {//GEN-FIRST:event_jTextField10KeyTyped
  666.     // TODO add your handling code here:
  667.       }//GEN-LAST:event_jTextField10KeyTyped
  668.    
  669.        private void jTextField11KeyTyped(KeyEvent e) {//GEN-FIRST:event_jTextField11KeyTyped
  670.     // TODO add your handling code here:
  671.       }//GEN-LAST:event_jTextField11KeyTyped
  672.    
  673.        private void jTextField12KeyTyped(KeyEvent e) {//GEN-FIRST:event_jTextField12KeyTyped
  674.     // TODO add your handling code here:
  675.       }//GEN-LAST:event_jTextField12KeyTyped
  676.    
  677.        private void jTextField13KeyTyped(KeyEvent e) {//GEN-FIRST:event_jTextField13KeyTyped
  678.     // TODO add your handling code here:
  679.       }//GEN-LAST:event_jTextField13KeyTyped
  680.    
  681.        private void jTextField14KeyTyped(KeyEvent e) {//GEN-FIRST:event_jTextField14KeyTyped
  682.     // TODO add your handling code here:
  683.       }//GEN-LAST:event_jTextField14KeyTyped
  684.    
  685.        private void jTextField15KeyTyped(KeyEvent e) {//GEN-FIRST:event_jTextField15KeyTyped
  686.     // TODO add your handling code here:
  687.       }//GEN-LAST:event_jTextField15KeyTyped
  688.    
  689.        private void jTextField16ActionPerformed(ActionEvent e) {//GEN-FIRST:event_jTextField16ActionPerformed
  690.     // TODO add your handling code here:
  691.       }//GEN-LAST:event_jTextField16ActionPerformed
  692.    
  693.        private void jTextField16KeyTyped(KeyEvent e) {//GEN-FIRST:event_jTextField16KeyTyped
  694.     // TODO add your handling code here:
  695.       }//GEN-LAST:event_jTextField16KeyTyped
  696.    
  697.        private void jTextField2ActionPerformed(ActionEvent e) {//GEN-FIRST:event_jTextField2ActionPerformed
  698.     // TODO add your handling code here:
  699.       }//GEN-LAST:event_jTextField2ActionPerformed
  700.    
  701.        private void jTextField2KeyTyped(KeyEvent e) {//GEN-FIRST:event_jTextField2KeyTyped
  702.     // TODO add your handling code here:
  703.       }//GEN-LAST:event_jTextField2KeyTyped
  704.  
  705.  
  706.  
  707.   public static int [] toBinary(String s){
  708.      int n =Integer.parseInt(s);
  709.      s="";
  710.      while (n>0){
  711.         if (n%2==0){
  712.            s =0+s;}
  713.         else{
  714.            s=1+s;
  715.         }
  716.         n =n/2;
  717.      }
  718.      int arr [] = new int [s.length()];            
  719.      System.out.print("\nBinary \t\t: ");
  720.      for (int i =0; i<s.length(); i++){
  721.         arr[i] =Integer.parseInt(s.charAt(i)+"");
  722.         System.out.print(arr[i]);
  723.      }
  724.      return arr;
  725.       }
  726.    
  727.        public static int [] toOctal(String s){
  728.      int n =Integer.parseInt(s);
  729.      s="";
  730.      while (n>0){
  731.      
  732.         s =n%8+s;
  733.      
  734.         n =n/8;
  735.      }
  736.      int arr [] = new int [s.length()];            
  737.      System.out.print("\nOctal \t\t: ");
  738.      for (int i =0; i<s.length(); i++){
  739.         arr[i] =Integer.parseInt(s.charAt(i)+"");
  740.         System.out.print(arr[i]);
  741.      }
  742.      return arr;
  743.       }
  744.     /**
  745.      * @param args the command line arguments
  746.      */
  747.        public static void main(String []args) {
  748.    
  749.      new NumberConvertor1();
  750.      
  751.       }
  752.    }
  753. /*class CustomABOUTDialog extends JDialog implements ActionListener {
  754.     JButton jbnOk;
  755.     CustomABOUTDialog(JFrame parent, String title, boolean modal){
  756.         super(parent, title, modal);
  757.         setBackground(Color.black);
  758.        
  759.         JPanel p1 = new JPanel(new FlowLayout(FlowLayout.CENTER));
  760.  
  761.         StringBuffer text = new StringBuffer();
  762.         text.append("Number System Information\n\n");
  763.         text.append("Developer: COM\n");
  764.         text.append("Version:   1.0");
  765.        
  766.         JTextArea jtAreaAbout = new JTextArea(5, 21);
  767.         jtAreaAbout.setText(text.toString());
  768.         jtAreaAbout.setFont(new Font("Times New Roman", 1, 13));
  769.         jtAreaAbout.setEditable(false);
  770.  
  771.         p1.add(jtAreaAbout);
  772.         p1.setBackground(Color.red);
  773.         getContentPane().add(p1, BorderLayout.CENTER);
  774.  
  775.         JPanel p2 = new JPanel(new FlowLayout(FlowLayout.CENTER));
  776.         jbnOk = new JButton(" OK ");
  777.         jbnOk.addActionListener(this);
  778.  
  779.         p2.add(jbnOk);
  780.         getContentPane().add(p2, BorderLayout.SOUTH);
  781.  
  782.         setLocation(408, 270);
  783.         setResizable(false);
  784.  
  785.         addWindowListener(new WindowAdapter() {
  786.                 public void windowClosing(WindowEvent e)
  787.                 {
  788.                     Window aboutDialog = e.getWindow();
  789.                     aboutDialog.dispose();
  790.                 }
  791.             }
  792.         );
  793.  
  794.         pack();
  795.     }
  796.     public void actionPerformed(ActionEvent e)
  797.     {
  798.     String actionCommand = e.getSource();
  799.         if(actionCommand == jmenuitemAbout){
  800.             JDialog dlgAbout = new CustomABOUTDialog(this, "About Number System", true);
  801.             dlgAbout.setVisible(true);
  802.         }else if(e.getSource() == jmenuitemExit){
  803.             System.exit(0);
  804.         }
  805.         if(e.getSource() == jbnOk)  {
  806.             this.dispose();
  807.         }
  808.     }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement