Results 1 to 20 of 20

Thread: HELP GUI Only

  1. #1
    yellowcorn is offline Member
    Join Date
    Jul 2010
    Posts
    9
    Rep Power
    0

    Default HELP GUI Only

    Hi guyz, its me javafanatic. I forgot my password and the email add so i created another account.. anyways, i have problem here.. i am getting difficulties on how to solve this error... .i created a password generator in java which i just copy and paste it somewhere the codes but i want to put and UI into it but there is an error... .

    Here is the original code:
    Java Code:
    public class PassPhrase {
      /** Minimum length for a decent password */
      public static final int MIN_LENGTH = 10;
    
      /** The random number generator. */
      protected static java.util.Random r = new java.util.Random();
    
      /*
       * Set of characters that is valid. Must be printable, memorable, and "won't
       * break HTML" (i.e., not ' <', '>', '&', '=', ...). or break shell commands
       * (i.e., not ' <', '>', '$', '!', ...). I, L and O are good to leave out,
       * as are numeric zero and one.
       */
      protected static char[] goodChar = { 'a', 'b', 'c', 'd', 'e', 'f', 'g',
          'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
          'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K',
          'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
          '2', '3', '4', '5', '6', '7', '8', '9', '+', '-', '@', };
    
      /* Generate a Password object with a random password. */
      public static String getNext() {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < MIN_LENGTH; i++) {
          sb.append(goodChar[r.nextInt(goodChar.length)]);
        }
        return sb.toString();
      }
    
      public static void main(String[] argv) {
        for (int i = 0; i < 20; i++) {
          System.out.println(PassPhrase.getNext());
        }
      }
    }

    and this is my revised code which i want to put a simple UI, (the UI is not finish yet, you will see the UI is not set properly because i want to test yet if the original code is okay with my UI.):


    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    
    
    
    public class PassPhrase extends JFrame  {
    	
    	private JButton generate, exit, clear;
    	private JTextArea plaintxt, pass;
    	private JLabel passwordL;
    	
    		public PassPhrase()
    	{
    		generateX();	
    	}
    		public void generateX()
    		
    		{
    		Container contentPane = getContentPane();
    		contentPane.setLayout(null);
    		contentPane.setBackground(Color.pink);
    		
    		plaintxt = new JTextArea();
    		plaintxt.setBounds(10, 50, 200, 250);
    		plaintxt.setEditable(false);
    		contentPane.add(plaintxt);
    		
    		passwordL = new JLabel();
    		passwordL.setText("Generated Password");
    		passwordL.setBounds(10, 10, 150, 50);
    		contentPane.add(passwordL);
    		
    		
    		exit = new JButton();
    		exit.setText("Exit");
    		exit.setBounds(10, 330, 95, 50);
    		exit.addActionListener(
    			new ActionListener()
    			{
    			
    				public void actionPerformed(ActionEvent event)
    				{
    					
     							System.exit(0);		
    					
    				}
    			}	
    		);		
    		contentPane.add(exit);
    		
    		
    		clear = new JButton();
    		clear.setText("Clear");
    		clear.setBounds(90, 330, 95, 50);
    		clear.addActionListener(
    			new ActionListener()
    			{
    			
    				public void actionPerformed(ActionEvent event)
    				{
    					plaintxt.setText("");
    					
    				}
    			}	
    		);
    		contentPane.add(clear);
    		
    		
    		generate = new JButton();
    		generate.setText("generate");
    		generate.setBounds(10, 330, 95, 50);
    		generate.addActionListener(
    			new ActionListener()
    			{
    			
    				public void actionPerformed(ActionEvent event)
    				{
    					
     					generateY();		
    					
    				}
    			}	
    		);		
    		contentPane.add(generate);
    		
    		
    		setSize(300,500);
    		setTitle("Core Function Unlimited");
    		show();
    			
    		}
    		
    		
    			public void generateY()
    			{
    			
    			
    	
     	public static final int MIN_LENGTH = 10;
      	protected static java.util.Random r = new java.util.Random();
      	protected static char[] goodChar = { 'a', 'b', 'c', 'd', 'e', 'f', 'g',
          'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
          'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K',
          'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
          '2', '3', '4', '5', '6', '7', '8', '9', '+', '-', '@', };
    
      public static String getNext() {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < MIN_LENGTH; i++) {
          sb.append(goodChar[r.nextInt(goodChar.length)]);
        }
        return sb.toString();
      }
    
      public static void main(String[] argv) {
        for (int i = 0; i < 20; i++) {
    
      //   This area where in my output will be append in plaintxt <--- my JTextArea
           plaintxt.append(""+(PassPhrase.getNext()));
          }
        }
    }
    	
    	
    
    
      
      
    
      
      		public static void main(String[] args)
    		{
    		PassPhrase application = new PassPhrase();
    		application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);	
    		}

  2. #2
    Sno's Avatar
    Sno
    Sno is offline Senior Member
    Join Date
    Apr 2010
    Posts
    196
    Rep Power
    5

    Default

    well awesome. but. what is the error?
    :rolleyes: ~ Sno ~ :rolleyes:
    '-~ B.S. Computer Science ~-'

  3. #3
    yellowcorn is offline Member
    Join Date
    Jul 2010
    Posts
    9
    Rep Power
    0

    Default

    this is the error:


  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    ...and as side thing, I'd have kept the password generator as a separate class.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Why don't some of these IDEs provide a proper copy/pasteable set of compilation errors?!

    Anyway, what's line 101, etc?

    ETA: And have you checked your brackets? You really need to get into the habit of indenting correctly...

  6. #6
    yellowcorn is offline Member
    Join Date
    Jul 2010
    Posts
    9
    Rep Power
    0

    Default

    this is only a simple program. . .i cant really explain exactly what is the error all about... may i suggest that can you run the codes that had a GUI so that you can understand and determine where and what is the error.. . :) thanks!!!

  7. #7
    yellowcorn is offline Member
    Join Date
    Jul 2010
    Posts
    9
    Rep Power
    0

    Default

    this is line 101
    public static final int MIN_LENGTH = 10;
    line 133
    public static void main(String[] args)

    line 136 and 137
    application.setDefaultCloseOperation(JFrame.EXIT_O N_CLOSE);
    }

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Look at your brackets.

    As I said, you should have kept your PassPhrase class separate from whatever GUI stuff you do...it's not GUI code (and you know it works).

    So this bit:
    Java Code:
    			public void generateY()
    			{	
     	public static final int MIN_LENGTH = 10;
      	protected static java.util.Random r = new java.util.Random();
    which is caused by doing some sort of cut and paste fo gui code possibly would not have happened. This is declaring what was once a public static final attribute inside a method which is illegal.

  9. #9
    yellowcorn is offline Member
    Join Date
    Jul 2010
    Posts
    9
    Rep Power
    0

    Default

    so what can you suggest to solve this error? i dont have any idea how to recode it... :(

    you can revised my code if you want... . :(

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Nope.

    If you can't see what's wrong then you probably need to go through the tutorials.

  11. #11
    yellowcorn is offline Member
    Join Date
    Jul 2010
    Posts
    9
    Rep Power
    0

    Default

    Huhuhuhu.... .i dont have a time anymore to read tutorials... .im gonna pass this later... :( help please.... .:(

  12. #12
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by yellowcorn View Post
    Huhuhuhu.... .i dont have a time anymore to read tutorials... .im gonna pass this later...
    Are you sure that's wise?

  13. #13
    yellowcorn is offline Member
    Join Date
    Jul 2010
    Posts
    9
    Rep Power
    0

    Default

    hi furable, i thought you are not active anymore in this forum... ahehehe... .can you help me? weeeeeeeeeeee... :) :) :)

  14. #14
    yellowcorn is offline Member
    Join Date
    Jul 2010
    Posts
    9
    Rep Power
    0

    Default

    its okay now...thread closed.. :)

  15. #15
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    I have a bad feeling that implies you've found someone to do it for you elsewhere...

  16. #16
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Quote Originally Posted by Tolls View Post
    I have a bad feeling that implies you've found someone to do it for you elsewhere...
    Don't worry Tolls it just means you will be working overtime this christmas fixing people like his mistakes ;)

    wonders where effort went to ooo000000:rolleyes:

  17. #17
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Ah, I'm a contractor...I don't do overtime.
    :)

  18. #18
    yellowcorn is offline Member
    Join Date
    Jul 2010
    Posts
    9
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    I have a bad feeling that implies you've found someone to do it for you elsewhere...
    no i did not... .:p:p

  19. #19
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    In the words of Bill The Cat...*ack* **thrrrrrp**
    :)

  20. #20
    killerf2006 is offline Member
    Join Date
    Jul 2010
    Posts
    6
    Rep Power
    0

    Default

    Hi all,
    I'm new to this site.
    I have a doubt.
    Is it possible to run a jar file from a button click in swing.
    Help required in this. If possible can you post the code please.

    Thanks in advance.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •