Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By JosAH

Thread: I hope i can get a little help with this.

  1. #1
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    130
    Rep Power
    0

    Default I hope i can get a little help with this.

    so yes im here again, and i have a problem.
    while making this log-in system, you first create an account (in the first JFrame), then it pops up a window with your information you just filled in.

    then after that i really want another JFrame to pop up to actually log in with your account, although i created that JFrame, it doesnt pop up.

    anyone?

    Java Code:
    import javax.swing.JOptionPane;
    import java.awt.event.ActionListener;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import javax.swing.JLabel;
    import javax.swing.JFrame;
    import javax.swing.JButton;
    import javax.swing.JTextField;
    import javax.swing.JPasswordField;
    import javax.swing.JPanel;
    public class LogIn extends JFrame{
    	
    	private JTextField txt1;
    	private JTextField txt2;
    	private JPasswordField ps1;
    	private JPasswordField ps2;
    	private JPasswordField ps3;
    	private JLabel label1;
    	private JLabel label2;
    	private JLabel label3;
    	private JLabel label4;
    	private JLabel label5;
    	private JButton b1;
    	private JButton b2;
    	
    
    
    
    public LogIn(){
    	super("Account");
    	setLayout (new FlowLayout());
    	label1 = new JLabel("Enter your username: ");
    	txt1 = new JTextField(10);
    	label2 = new JLabel("Enter your password: ");
    	ps1 = new JPasswordField(10);
    	label3 = new JLabel("Confirm your password: ");
    	ps2 = new JPasswordField(10);
    	b1 = new JButton("OK");
    	add(label1);
    	add(txt1);
    	add(label2);
    	add(ps1);
    	add(label3);
    	add(ps2);
    	add(b1);
    	
    	
    	thehandler handler = new thehandler();
    	b1.addActionListener(handler);
    	
    	
    }
    public class thehandler implements ActionListener{
    	public void actionPerformed(ActionEvent event){
    		String mick2 = "";
    		if(txt1.getText().equals(ps1.getText())){
    		JOptionPane.showMessageDialog(null, "Password error, your username can't be the same as your password","Password Error!",JOptionPane.ERROR_MESSAGE);}
    		else if(ps1.getText().equals(ps2.getText())){
    		JOptionPane.showMessageDialog(null, "Account information: "+"\n"+"User: "+txt1.getText()+"\n"+"Password: "+ps1.getText(), "Account Information", JOptionPane.INFORMATION_MESSAGE);}
    		else{
    		JOptionPane.showMessageDialog(null, "Passwords did not match! Try again please!", "Password error!", JOptionPane.ERROR_MESSAGE);}
    		if(txt1.getText()== mick2 )
    			JOptionPane.showMessageDialog(null, "Please fill in a username!", "Username Error", JOptionPane.ERROR_MESSAGE);
    		if(ps1.getText().equals(ps2.getText())){
    			JFrame frame = new JFrame();
    
    
    			class frame extends JFrame{
    				public frame(){
    					super ("Log In");
    					setVisible(true);
    					setLayout (new FlowLayout());
    					label4 = new JLabel("Username: "); txt1 = new JTextField(10);
    					label5 = new JLabel("Password: "); ps3 = new JPasswordField(10);
    					b2 = new JButton("Log In");
    					add(label4); add(txt1);
    					add(label5); add(ps3);
    					add(b2);
    					
    				}
    						
    			}
    		}
    		
    
    		
    
    
    	}
    	
    	
    
    	
    }
    
    
    	
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: I hope i can get a little help with this.

    Did you just give up on using JOptionPane/JDialog?
    Because that's what should be used in this case.

    You really need to learn some more basic Java, rather than relying on a forum to teach you.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    130
    Rep Power
    0

    Default Re: I hope i can get a little help with this.

    well,i tried looking up stuff about JDialog but i couldnt find anything really useful in this situation.
    on another forum i read that you cant add these components to a JOptionPane.

    anyways, where will you recomend me to learn JOptionPane and JDialog things from.

    because thenewboston - YouTube didnt teach me in all of his basic tutorials

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,525
    Blog Entries
    7
    Rep Power
    20

    Default Re: I hope i can get a little help with this.

    Quote Originally Posted by MR bruto View Post
    because thenewboston - YouTube didnt teach me in all of his basic tutorials
    Why do you refuse to read Oracle's/Sun's tutorials? They are the best and most complete tutorials around. Now you're crafting nonsense code; I don't even know where to start; it is utter rubbish.

    Jos
    Tolls likes this.
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    monkeyjr97 is offline Senior Member
    Join Date
    Nov 2012
    Posts
    258
    Rep Power
    2

    Default Re: I hope i can get a little help with this.

    Quote Originally Posted by MR bruto View Post
    well,i tried looking up stuff about JDialog but i couldnt find anything really useful in this situation.
    on another forum i read that you cant add these components to a JOptionPane.

    anyways, where will you recomend me to learn JOptionPane and JDialog things from.
    Why do you have an inner Class that extends JFrame as well as the "outer" Class also extending JFrame, seems pointless to me, you only want one frame, but you waned several component on the JFrame.

    Go back to your old code, this code seems to me like you ignored every ones suggestions on your other posts and just hacked and slashed something together.

    Without being too harsh, if you arent going to put the effort in and read the API documentation then why should we put the effort in correcting code you have "abandoned"

    Really? in your other forum post on this matter i basically gave you the syntax to add these component to a JOptionPane. Any component can be added to an JOptionPane, you can also add an Array of Objects.

Similar Threads

  1. Simple Scanner Question (i hope)
    By elm101 in forum New To Java
    Replies: 1
    Last Post: 07-09-2011, 12:24 AM
  2. hi guys , hope all are fine , help me please
    By funkygarzon in forum New To Java
    Replies: 2
    Last Post: 06-10-2011, 10:56 AM
  3. Simple question...I hope
    By marksey07 in forum New To Java
    Replies: 6
    Last Post: 01-07-2011, 05:40 PM
  4. hope to help me
    By ABUALI in forum Advanced Java
    Replies: 7
    Last Post: 05-27-2010, 04:43 PM
  5. hope there is an easier way.
    By IYIaster in forum New To Java
    Replies: 6
    Last Post: 10-14-2009, 07:26 AM

Posting Permissions

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