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 5 of 5

Thread: Too long of a number for GUI

  1. #1
    Member
    Join Date
    Sep 2013
    Posts
    64
    Thanks
    24
    Thanked 0 Times in 0 Posts

    Default Too long of a number for GUI

    I'm working on an RSA cryptosystem, and I want to use a GUI to publish a person's public key.

    I have no problem displaying ints / strings via the GUI, but my problem is that the person's public key has an integer that's like 400 digits long, and it's getting chopped off because it can't fit in one horizontal line. How do I make it "roll over" to the next line?

    Here's my code:
            public class RSA extends JFrame
    {
            private String name; // name of the person who owns this cryptosystem
            private String message; // message to be sent
            private BigInteger m; // holds message
            private BigInteger p; // prime 1
            private BigInteger q; // prime 2
            private BigInteger n; // p*q
            private BigInteger e; // GCD(e, phi) = 1
            private BigInteger d; // relatively prime to e in mod phi
            private BigInteger c; // Encrypted message 
            private BigInteger phi; // (p-1)*(q-1)
     
     
            public static void main (String[] args)
            {
                    RSA Alice = new RSASignature("Alice", "message");
                    RSA Bob = new RSASignature("Bob");
     
                    Alice.buildRSA(); // generates e and n for Alice
                    Bob.buildRSA(); // generates e and n for Bob
     
     
     
                    TestFlowLayout frame = new TestFlowLayout(Alice.name, Alice.e, Alice.n, Bob.name, Bob.e, Bob.n);
     
     
                    frame.setSize(300,300);
     
                    frame.setLocationRelativeTo(null);
     
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
                    frame.setVisible(true);



    public class TestFlowLayout extends JFrame
    {
            public TestFlowLayout(String name1, BigInteger e1, BigInteger n1, String name2, BigInteger e2, BigInteger n2)
            {
                    setLayout(new FlowLayout(FlowLayout.LEFT, 100, 200));
     
                    add(new JLabel(name1 + "'s public key: (" + e1 + ", " +  n1 + ")"));
     
                    add(new JLabel(name2 + "'s public key: (" + e2 + ", " +  n2 + ")"));
             }
    }


  2. #2
    Member GoodbyeWorld's Avatar
    Join Date
    Jul 2012
    Location
    Hidden command post deep within the bowels of a hidden bunker somewhere under a nondescrip building
    Posts
    161
    My Mood
    Stressed
    Thanks
    14
    Thanked 25 Times in 25 Posts

    Default Re: Too long of a number for GUI

    You could try adding a JScrollPane to where you're putting the labels. (Though, if you do that, make sure to add the labels to a JPanel or something like that as adding one to a JFrame or other Window will cause an exception. Make the JPanel or whatever the content pane or something of the JFrame.)

  3. The Following User Says Thank You to GoodbyeWorld For This Useful Post:

    ineedahero (November 30th, 2013)

  4. #3
    Member
    Join Date
    Sep 2013
    Posts
    64
    Thanks
    24
    Thanked 0 Times in 0 Posts

    Default Re: Too long of a number for GUI

    Thanks!

    I've been trying to add the scroll bar, and it doesn't seem to be working. No matter what I do, I can't get the scroll bar to actually come up when I run the program.

    Here's my code...why isn't it working?


    import javax.swing.*;
    import java.awt.*;
     
    public class TestPanels extends JFrame
    {
            public static void main(String[] args)
            {
                  TestPanels frame = new TestPanels();
     
                  frame.setTitle("Panel Test");
                    frame.setSize(400,250);
                    frame.setLocationRelativeTo(null);
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
                    frame.setVisible(true);
            }
     
     
     
            public TestPanels()
            {
                    JPanel panel = new JPanel();
                    JScrollPane scrollPane = new JScrollPane( panel );
     
                    panel.setLayout(new GridLayout(4,3));
                    panel.add( new JButton("6777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777767777777777777777777777777777777777777777777777777777777777677777777777777777777777777777777777777777777777777777777776777777777777777777777777777777777777777777777777777777777767777777777777777777777777777777777777777777777777777777777"));
     
                    add(scrollPane, BorderLayout.EAST);

    }

    All I'm getting is a button at the top of the GUI screen with a portion of the number in it, and then it gets cut off.

  5. #4
    Member GoodbyeWorld's Avatar
    Join Date
    Jul 2012
    Location
    Hidden command post deep within the bowels of a hidden bunker somewhere under a nondescrip building
    Posts
    161
    My Mood
    Stressed
    Thanks
    14
    Thanked 25 Times in 25 Posts

    Default Re: Too long of a number for GUI

    I removed the BorderLayout.EAST part and now it shows the scroll.

     
    import javax.swing.*;
    import java.awt.*;
     
    public class TestPanels extends JFrame
    {
       public static void main(String[] args)
       {
          TestPanels frame = new TestPanels();
     
          frame.setTitle("Panel Test");
          frame.setSize(400,250);
          frame.setLocationRelativeTo(null);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
          frame.setVisible(true);
       }
     
     
     
       public TestPanels()
       {
          JPanel panel = new JPanel();
          JScrollPane scrollPane = new JScrollPane( panel);
     
          panel.setLayout(new GridLayout(4,3));
          panel.add( new JButton("6777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777767777777777777777777777777777777777777777777777777777777777677777777777777777777777777777777777777777777777777777777776777777777777777777777777777777777777777777777777777777777767777777777777777777777777777777777777777777777777777777777"));
     
          add(scrollPane);
       }
     
    }

  6. The Following User Says Thank You to GoodbyeWorld For This Useful Post:

    ineedahero (November 30th, 2013)

  7. #5
    Member
    Join Date
    Sep 2013
    Posts
    64
    Thanks
    24
    Thanked 0 Times in 0 Posts

    Default Re: Too long of a number for GUI

    Ah, it works for me too! Thank you so much!

Similar Threads

  1. Replies: 10
    Last Post: November 8th, 2012, 06:29 AM
  2. Problems getting floating point number to show in GUI...
    By Eclecstatic in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 18th, 2012, 11:48 PM
  3. Java - Crypto ISBN number verification, GUI program
    By djl1990 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: October 13th, 2011, 11:22 AM
  4. Number Format Exception while parsing long
    By Aamir in forum Java Networking
    Replies: 1
    Last Post: May 19th, 2011, 03:59 AM
  5. Replies: 4
    Last Post: June 10th, 2009, 01:04 AM