Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: netbean nextLine

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation netbean nextLine

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /*
     * Menu.java
     *
     * Created on Jul 4, 2011, 1:04:24 PM
     */
    package cryptocalc;
     
    import java.math.BigInteger;
     
    /**
     *
     * @author USER
     */
    public class Menu extends javax.swing.JPanel {
     
        /** Creates new form Menu */
        BigInteger rsaP,rsaQ,rsaE,rsaD,rsaN,msgByte,cipher,decrypted; 
        String rsaMsg,decMsg;
     
        public Menu() {
            initComponents();
        }
     
     
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
     
            RSA = new javax.swing.JTabbedPane();
            jPanel2 = new javax.swing.JPanel();
            jPanel3 = new javax.swing.JPanel();
            jPanel1 = new javax.swing.JPanel();
            RSA_P = new javax.swing.JTextField();
            EncryptButton = new javax.swing.JButton();
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jLabel3 = new javax.swing.JLabel();
            jLabel4 = new javax.swing.JLabel();
            jLabel5 = new javax.swing.JLabel();
            RSA_Q = new javax.swing.JTextField();
            RSA_E = new javax.swing.JTextField();
            RSA_N = new javax.swing.JTextField();
            jLabel6 = new javax.swing.JLabel();
            RSA_Cipher = new javax.swing.JTextField();
            jLabel7 = new javax.swing.JLabel();
            RSA_Decrypted = new javax.swing.JTextField();
            RSA_D = new javax.swing.JTextField();
            jLabel8 = new javax.swing.JLabel();
            RSA_Msg = new javax.swing.JTextField();
            DecryptButton = new javax.swing.JButton();
            jLabel62 = new javax.swing.JLabel();
            jLabel67 = new javax.swing.JLabel();
            display = new javax.swing.JTextField();
     
            RSA.setTabPlacement(javax.swing.JTabbedPane.LEFT);
     
            javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
            jPanel2.setLayout(jPanel2Layout);
            jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 666, Short.MAX_VALUE)
            );
            jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 281, Short.MAX_VALUE)
            );
     
            RSA.addTab("tab4", jPanel2);
     
            javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
            jPanel3.setLayout(jPanel3Layout);
            jPanel3Layout.setHorizontalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 666, Short.MAX_VALUE)
            );
            jPanel3Layout.setVerticalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 281, Short.MAX_VALUE)
            );
     
            RSA.addTab("tab5", jPanel3);
     
            EncryptButton.setText("Encrypt");
            EncryptButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    EncryptButtonActionPerformed(evt);
                }
            });
     
            jLabel1.setText("p: ");
     
            jLabel2.setText("Message: ");
     
            jLabel3.setText("q: ");
     
            jLabel4.setText("e: ");
     
            jLabel5.setText("n: ");
     
            jLabel6.setText("CipherText: ");
     
            jLabel7.setText("d: ");
     
            jLabel8.setText("Decrypted Message: ");
     
            DecryptButton.setText("Decrypt");
            DecryptButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    DecryptButtonActionPerformed(evt);
                }
            });
     
            jLabel62.setFont(new java.awt.Font("Tahoma", 0, 18));
            jLabel62.setForeground(new java.awt.Color(0, 0, 153));
            jLabel62.setText("Encrypting");
     
            jLabel67.setFont(new java.awt.Font("Tahoma", 0, 18));
            jLabel67.setForeground(new java.awt.Color(0, 0, 153));
            jLabel67.setText("Decrypting");
     
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel2)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(RSA_Msg, javax.swing.GroupLayout.DEFAULT_SIZE, 321, Short.MAX_VALUE))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGap(34, 34, 34)
                                    .addComponent(jLabel1)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(RSA_P, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGap(33, 33, 33)
                                    .addComponent(jLabel3)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(RSA_Q, javax.swing.GroupLayout.DEFAULT_SIZE, 324, Short.MAX_VALUE))
                                .addComponent(jLabel62))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel5)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(RSA_N, javax.swing.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE)
                                        .addComponent(EncryptButton)))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel4)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(RSA_E, javax.swing.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE))))
                        .addComponent(jLabel67)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel7)
                                .addComponent(jLabel6))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(RSA_D, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(26, 26, 26)
                                    .addComponent(DecryptButton))
                                .addComponent(RSA_Cipher, javax.swing.GroupLayout.DEFAULT_SIZE, 582, Short.MAX_VALUE))))
                    .addContainerGap())
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jLabel8)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(RSA_Decrypted, javax.swing.GroupLayout.DEFAULT_SIZE, 516, Short.MAX_VALUE)
                    .addGap(34, 34, 34))
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel62)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(RSA_P, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(1, 1, 1)
                            .addComponent(RSA_E, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(jLabel4))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel5)
                        .addComponent(RSA_N, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel3)
                        .addComponent(RSA_Q, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(EncryptButton)
                        .addComponent(RSA_Msg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jLabel67)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel6)
                        .addComponent(RSA_Cipher, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel7)
                        .addComponent(RSA_D, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(DecryptButton))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel8)
                        .addComponent(RSA_Decrypted, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(146, 146, 146))
            );
     
            RSA.addTab("RSA", jPanel1);
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
            this.setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(RSA, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 709, Short.MAX_VALUE)
                        .addComponent(display, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 709, Short.MAX_VALUE))
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(display, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(RSA, javax.swing.GroupLayout.PREFERRED_SIZE, 286, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap())
            );
        }// </editor-fold>
     
        private void DecryptButtonActionPerformed(java.awt.event.ActionEvent evt) {                                              
            // TODO add your handling code here:
            /*rsaP = new BigInteger(RSA_P.getText());
            rsaQ = new BigInteger(RSA_Q.getText());
            rsaE = new BigInteger(RSA_E.getText());
            rsaD = new BigInteger(RSA_D.getText());
            rsaN = rsaP.multiply(rsaQ);//find value n*/
            /////////////////////////////////////////////////
            cipher = new BigInteger(RSA_Cipher.getText());
            decrypted = cipher.modPow(rsaD, rsaN);
            byte[] messageBytes = decrypted.toByteArray();
            String s = new String (messageBytes);
            RSA_Decrypted.setText(s/*decrypted.toString()*/);
        }                                             
     
        private void EncryptButtonActionPerformed(java.awt.event.ActionEvent evt) {
            try{
            // TODO add your handling code here:
            //RSA_Msg.setText(RSA_P.getText());
            String s = "";
           // s = RSA_P.getText();
            rsaP = new BigInteger(RSA_P.getText());
            rsaQ = new BigInteger(RSA_Q.getText());
            rsaE = new BigInteger(RSA_E.getText());
            rsaD = new BigInteger(RSA_D.getText());
            rsaMsg = RSA_Msg.getText();
     
            ////////////////////////////////////////////get user input
     
            rsaN = rsaP.multiply(rsaQ);//find value n
            RSA_N.setText(rsaN.toString());//show value n to users
            byte[] messageBytes = rsaMsg.getBytes();//convert message to bytes
            msgByte = new BigInteger(messageBytes);//convert byte to bigInteger
            // RSA Encrypt code
            cipher = msgByte.modPow(rsaE, rsaN);//encrypt message
            RSA_Cipher.setText(cipher.toString());//show ciphertext to users
              display.setText(display.getText()+"p: "+ rsaP.toString()+" q: "+ rsaQ.toString()+" e: "+ rsaE.toString()+" d: "+ rsaD.toString());
            display.setText(display.getText()+"\n\n\n");
            display.setText(display.getText()+ rsaP.toString()+"x"+ rsaQ.toString() +"="+ rsaN.toString());
            }
            catch (Exception e){
     
            }
        }
     
        // Variables declaration - do not modify
        private javax.swing.JButton DecryptButton;
        private javax.swing.JButton EncryptButton;
        private javax.swing.JTabbedPane RSA;
        private javax.swing.JTextField RSA_Cipher;
        private javax.swing.JTextField RSA_D;
        private javax.swing.JTextField RSA_Decrypted;
        private javax.swing.JTextField RSA_E;
        private javax.swing.JTextField RSA_Msg;
        private javax.swing.JTextField RSA_N;
        private javax.swing.JTextField RSA_P;
        private javax.swing.JTextField RSA_Q;
        private javax.swing.JTextField display;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JLabel jLabel5;
        private javax.swing.JLabel jLabel6;
        private javax.swing.JLabel jLabel62;
        private javax.swing.JLabel jLabel67;
        private javax.swing.JLabel jLabel7;
        private javax.swing.JLabel jLabel8;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JPanel jPanel3;
        // End of variables declaration
    }
    display.setText(display.getText()+"p: "+ rsaP.toString()+" q: "+ rsaQ.toString()+" e: "+ rsaE.toString()+" d: "+ rsaD.toString());
    display.setText(display.getText()+"\n\n\n");
    display.setText(display.getText()+ rsaP.toString()+"x"+ rsaQ.toString() +"="+ rsaN.toString());
    i try to display nextline, however the display come out one line. How to fix it?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,652
    Thanks
    45
    Thanked 1,959 Times in 1,933 Posts

    Default Re: netbean nextLine

    What type is the display variable?
    Are you saying that the object display refers to does NOT recognize the \n character as a command to move the text following the \n to the next line?

  3. #3
    Junior Member
    Join Date
    Jun 2011
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: netbean nextLine

    Quote Originally Posted by Norm View Post
    What type is the display variable?
    Are you saying that the object display refers to does NOT recognize the \n character as a command to move the text following the \n to the next line?
    Anyway i find the sloution Thanks for the Help

Similar Threads

  1. Netbean Desktop Application Help!!
    By flyto9 in forum Java Theory & Questions
    Replies: 2
    Last Post: June 30th, 2011, 05:52 PM
  2. name=scan.nextLine();
    By Amro in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 13th, 2010, 07:38 PM
  3. netbean and debuger client
    By 11moshiko11 in forum Java Networking
    Replies: 0
    Last Post: October 8th, 2010, 12:43 PM
  4. I need help! Re: strings, nextLine, while and more..
    By rockerade in forum What's Wrong With My Code?
    Replies: 19
    Last Post: October 5th, 2010, 03:51 PM
  5. Replies: 1
    Last Post: August 13th, 2010, 06:58 AM