Results 1 to 11 of 11
  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 [HELP] Not sure how to make this JButton work properly.

    i made this proram that open a window and lets you fill in account information(like creating an account), but i have some trouble with the button i made. (b1).

    when you click the OK button now, it tells me: "your account information: OK".


    but i want it so when you click on the OK button that it lets a window pop up an give you all the account information you just entered.
    like:
    your account information:

    username: me
    password: example
    last name: me
    e-mail: example@me.com

    this is the code:

    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;
    public class MICKGUI extends JFrame {
    	
    	private JTextField txt1;
    	private JTextField txt2;
    	private JTextField txt3;
    	private JButton b1;
    	private JLabel label1;
    	private JLabel label2;
    	private JLabel label3;
    	private JLabel label4;
    	private JPasswordField ps1;
    
    
    
    public MICKGUI(){
    	super("Oefening");
    	setLayout(new FlowLayout());
    	label1 = new JLabel("Enter your username:");
    	txt1 = new JTextField(10);
    	label2 = new JLabel("Enter your last name:");
    	txt2 = new JTextField(10);
    	label3 = new JLabel("Enter your e-mail adress: ");
    	txt3 = new JTextField(10);
    	label4 = new JLabel("Enter your password: ");
    	ps1 = new JPasswordField(10);
    	b1 = new JButton("OK");
    	add(label1);
    	add(txt1);
    	add(label2);
    	add(txt2);
    	add(label3);
    	add(txt3);
    	add(label4);
    	add(ps1);
    	add(b1);
    	
    	thehandler handler = new thehandler();
    	b1.addActionListener(handler);
    	
    	}
    public class thehandler implements ActionListener{
    	public void actionPerformed (ActionEvent event){
    		String bats = "";
    		
    		if(event.getSource()==b1)
    			bats = String.format("Your account details: %s", event.getActionCommand());
    		
    		JOptionPane.showMessageDialog(null, bats);
    	}
    
    
    	
    }
    
    
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,969
    Rep Power
    8

    Default Re: [HELP] Not sure how to make this JButton work properly.

    Check out the API for JTextField for useful functions. Hint: you're trying to get the text from them, right?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  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: [HELP] Not sure how to make this JButton work properly.

    im trying to get the text you fill in in the text fields, in the windows that pops up when you click the OK button.

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

    Default Re: [HELP] Not sure how to make this JButton work properly.

    can anyone help me??

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,570
    Blog Entries
    7
    Rep Power
    21

    Default Re: [HELP] Not sure how to make this JButton work properly.

    Kevin gave you a good tip in the first reply.

    Jos
    cenosillicaphobia: the fear for an empty beer glass

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

    Default Re: [HELP] Not sure how to make this JButton work properly.

    i dont know what he meant by that...

    i didnt understand it

  7. #7
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,570
    Blog Entries
    7
    Rep Power
    21

    Default Re: [HELP] Not sure how to make this JButton work properly.

    Does the verb 'reading' ring a bell?

    Jos
    cenosillicaphobia: the fear for an empty beer glass

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

    Default Re: [HELP] Not sure how to make this JButton work properly.

    yes but i dont even know what to read.

    i didnt see a link

  9. #9
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,969
    Rep Power
    8

    Default Re: [HELP] Not sure how to make this JButton work properly.

    I recommended you look at the Java API. Googling "Java API" returns this result: Java Platform SE 7

    Navigate to the component you're using, then check out the methods available to you.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

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

    Default Re: [HELP] Not sure how to make this JButton work properly.

    i cant find a way to make that button work the way i want it to work

  11. #11
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,570
    Blog Entries
    7
    Rep Power
    21

    Default Re: [HELP] Not sure how to make this JButton work properly.

    You should read and study more before you blindly start to code; we are not supplying the answer for you; this is not a copy and paste facilty.

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Can't get JInput work properly
    By scarface78987 in forum New To Java
    Replies: 10
    Last Post: 01-31-2013, 08:56 PM
  2. Properly buffering a custom JButton
    By Reskaillev in forum New To Java
    Replies: 2
    Last Post: 04-08-2012, 08:32 PM
  3. The <sup> tag doesn't work properly
    By JosAH in forum AWT / Swing
    Replies: 26
    Last Post: 02-18-2012, 07:55 AM
  4. Help, I can't make the JButton to work properly
    By furieux in forum New To Java
    Replies: 11
    Last Post: 01-07-2012, 05:13 PM
  5. [SOLVED] JButton does not display ImageIcon properly
    By Singing Boyo in forum New To Java
    Replies: 1
    Last Post: 04-17-2009, 03:47 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
  •