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

Thread: Looking for a simple code

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Location
    Brazil
    Posts
    2
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Looking for a simple code

    Hello friends, im beginner with Java and I used to have a very nice code...that I unhappily lost...

    The code used to do something like this, its a "kind" of password...

    When someone clicks on the link, a java box appears, asking for the password..if the person types "night" as password and click "ok/send" the page automaticaly redirects to "www.mysite.com/night.html". If the person types "goodday" as password, and click "ok/send" the page automaticaly redirects to "www.mysite.com/goodday.html"

    Its a kind of password, only the person knows how to acess the page. I know that's not secure, but I really don't need security, just an easy way to hide some pages.

    Thank you very much guys =)


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,301
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default Re: Looking for a simple code

    Did you have a question?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member Cronus's Avatar
    Join Date
    Feb 2013
    Location
    Gothenburg, Sweden
    Posts
    41
    My Mood
    Inspired
    Thanks
    6
    Thanked 7 Times in 6 Posts

    Default Re: Looking for a simple code

    Welcome to the forum, Pipar!

    KevinWorkman, he's looking for the sample code, as mentioned in the title. I do agree with your statement, though.

    If you're a beginner, you should consider working with simpler tasks. Here's my version of the program, though:

    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
     
     
    public class redirectSample {
     
    	public static void main(String Args[]) { //Main method, always called first
     
    		window(); //Call the window
     
     
    	}
     
    	private static void window() { //The window of the program
     
    		final JFrame frame = new JFrame("Redirect Sample"); //Title
    		JButton prompt = new JButton("Redirect!"); //This is the button that will ask for the URL
     
    		prompt.addActionListener(new ActionListener() { //Without this statement, the button will not react when clicked
     
    			@Override
    			public void actionPerformed(ActionEvent e) {
     
    				String response = JOptionPane.showInputDialog("Enter a word (Spaces are not allowed):");	
     
    				String webURL = "www.mysite.com/" + response + ".html";
     
    				JLabel siteLabel = new JLabel(webURL);
    				frame.add(siteLabel);
     
    			}
    		});
     
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set exit behavior
    		frame.setVisible(true); //The frame is now visible
    		frame.setLayout(new FlowLayout());
     
    		frame.add(prompt);
    		frame.pack();
     
    	}
     
    }

    This forum is based on the "Thanks" button right below the username information to the left. If you liked my answer, please do me a favor and hit the button. I could really use it!

  4. The Following User Says Thank You to Cronus For This Useful Post:

    Pipar (July 22nd, 2013)

  5. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,301
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default Re: Looking for a simple code

    Quote Originally Posted by Cronus View Post
    KevinWorkman, he's looking for the sample code, as mentioned in the title. I do agree with your statement, though.
    I urge you to read through this: The Problem with Spoon-feeding

    The problem as stated isn't really a question that we can answer. You're assuming he's talking about Swing, but he could just as easily be talking about a JSP page, or JavaFX, or something else entirely. On top of that, your code also contains a few problems that will bite the OP down the road if he continues using it as is. That's why we usually try to talk posters through the problem themselves instead of just handing them code.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #5
    Member Cronus's Avatar
    Join Date
    Feb 2013
    Location
    Gothenburg, Sweden
    Posts
    41
    My Mood
    Inspired
    Thanks
    6
    Thanked 7 Times in 6 Posts

    Default Re: Looking for a simple code

    I see, I've read through the article. I just wanted to show my version of what he was trying to say, also, he said he lost the code. So I'm assuming he knew what he was doing. You do make a good point. Thank you for the heads up, man!

    By the way, what "problems that will bite the OP down the road" are you referring to?

  7. The Following User Says Thank You to Cronus For This Useful Post:

    Pipar (July 22nd, 2013)

  8. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,301
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default Re: Looking for a simple code

    Quote Originally Posted by Cronus View Post
    I see, I've read through the article. I just wanted to show my version of what he was trying to say, also, he said he lost the code. So I'm assuming he knew what he was doing. You do make a good point. Thank you for the heads up, man!
    No problem. It's awesome that you want to help, and it can be hard to resist the urge to just write some code that does what the OP wants (after all, we're programmers, we love problem solving). But usually it's a lot more helpful to walk the OP through the problem by asking questions, pointing out tutorials, and maybe giving example code- but full solutions often hurt more than they help.

    Quote Originally Posted by Cronus View Post
    By the way, what "problems that will bite the OP down the road" are you referring to?
    Little things like naming conventions are a lot more important than you might think, and we see a lot of questions here caused by things like setting the layout and adding components to an already visible JFrame. Also, I would have thought something like a CardLayout would be more like what the OP wants instead of adding multiple JLabels. But that's one of the reasons I would advise against offering code like that- we still haven't heard from the OP what the actual problem is.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  9. #7
    Member Cronus's Avatar
    Join Date
    Feb 2013
    Location
    Gothenburg, Sweden
    Posts
    41
    My Mood
    Inspired
    Thanks
    6
    Thanked 7 Times in 6 Posts

    Default Re: Looking for a simple code

    Quote Originally Posted by KevinWorkman View Post
    ...And it can be hard to resist the urge to just write some code that does what the OP wants (after all, we're programmers, we love problem solving)
    Boys will be boys.

    Little things like naming conventions are a lot more important than you might think, and we see a lot of questions here caused by things like setting the layout and adding components to an already visible JFrame. Also, I would have thought something like a CardLayout would be more like what the OP wants instead of adding multiple JLabels. But that's one of the reasons I would advise against offering code like that- we still haven't heard from the OP what the actual problem is.
    I'll keep that in mind, thank you!

  10. The Following User Says Thank You to Cronus For This Useful Post:

    Pipar (July 22nd, 2013)

  11. #8
    Junior Member
    Join Date
    Jul 2013
    Location
    Brazil
    Posts
    2
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Looking for a simple code

    Thank you Cronus
    I'm not a programmer, just a curious that is looking for codes for my personal website I used to have this code, found it a long time ago on a website, and just used it. I'm going to try your code, thank you SO MUCH! <3

Similar Threads

  1. [SOLVED] Simple array code
    By azizmaiden in forum Java Theory & Questions
    Replies: 1
    Last Post: March 2nd, 2013, 05:54 PM
  2. Need help with simple code
    By suxen in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 21st, 2011, 07:10 PM
  3. [SOLVED] Help with simple Applet code
    By that_guy in forum What's Wrong With My Code?
    Replies: 13
    Last Post: January 11th, 2011, 09:22 PM
  4. im dying here..on a simple code
    By Jason in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 28th, 2010, 10:33 PM
  5. Help! how would you code these simple games?
    By makarov in forum Java Applets
    Replies: 1
    Last Post: November 14th, 2009, 11:31 AM