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

Thread: How To get Data button to Display user inputted "numbers" to data label?

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How To get Data button to Display user inputted "numbers" to data label?

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class DisplayFinal_Panel extends JPanel
    {
    private JLabel label1, label2, label3;
    private JTextField box;
    private JCheckBox c1,c2;
    public DisplayFinal_Panel()
    {
    setLayout(null);
    box = new JTextField("",60);
    box.setBounds(0,1,500,45);
    add(box);
    JButton b1 = new JButton("Data");
    b1.addActionListener(new Listener1());
    b1.setBounds(10, 50,70, 30);

    add(b1);
    JButton b2 = new JButton("Staticticks");
    b2.addActionListener(new Listener2());
    b2.setBounds(100, 50, 100, 30);

    add(b2);
    JButton b3 = new JButton("Graph Data");
    b3.addActionListener(new Listener3());
    b3.setBounds(220, 50,100, 30);

    add(b3);
    JButton b4 = new JButton("Quit");
    b4.addActionListener(new Listener4());
    b4.setBounds(340, 50,70, 30);

    add(b4);



    Font f = new Font("Serif", Font.BOLD, 30);

    label1 = new JLabel("Data:");
    label1.setFont(f);
    label1.setForeground(Color.blue);
    label1.setBounds(10, 100,70, 30);
    add(label1);

    label2 = new JLabel("Mean: ");
    label2.setFont(f);
    label2.setForeground(Color.blue);
    label2.setBounds(10, 150,90, 30);
    add(label2);

    label3 = new JLabel("Standard Deviation:");
    label3.setFont(f);
    label3.setForeground(Color.blue);
    label3.setBounds(10,200,300, 30);
    add(label3);
    JCheckBox c1 = new JCheckBox("Mean");
    c1.addActionListener(new Listener1());
    c1.setBounds(10, 250,70, 30);
    add(c1);
    JCheckBox c2 = new JCheckBox("Standard Deviation");
    c2.addActionListener(new Listener1());
    c2.setBounds(10, 300,150, 30);
    add(c2);

    }

    public void paintComponent(Graphics g)
    {

    }
    private class Listener1 implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {

    }
    }

    private class Listener2 implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {


    }
    }
    private class Listener3 implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {

    }
    }
    private class Listener4 implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {
    System.exit(0);
    }
    }


    }

    --- Update ---

    I only want Listener 1 to work right now. Also, user input is in TextField.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How To get Data button to Display user inputted "numbers" to data label?

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    What are the steps the code needs to do to copy data from one place to another?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    May 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How To get Data button to Display user inputted "numbers" to data label?

    I am new to this and i really need help. How do u wrap ur code with tags

    --- Update ---

    Also, This is my panel so all the code goes here. The only other thing i have is a driver, but i need no code for the driver.

  4. #4
    Junior Member
    Join Date
    May 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How To get Data button to Display user inputted "numbers" to data label?

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class DisplayFinal_Panel extends JPanel
    {
       private JLabel label1, label2, label3;
       private JTextField box;
       private JCheckBox c1,c2;
       public DisplayFinal_Panel()
       {
          setLayout(null);
          box = new JTextField("",60);
          box.setBounds(0,1,500,45);
          add(box);
          JButton b1 = new JButton("Data");
          b1.addActionListener(new Listener1());
          b1.setBounds(10, 50,70, 30); 
     
          add(b1);
          JButton b2 = new JButton("Staticticks");
          b2.addActionListener(new Listener2());
          b2.setBounds(100, 50, 100, 30); 
     
          add(b2);
          JButton b3 = new JButton("Graph Data");
          b3.addActionListener(new Listener3());
          b3.setBounds(220, 50,100, 30); 
     
          add(b3);
          JButton b4 = new JButton("Quit");
          b4.addActionListener(new Listener4());
          b4.setBounds(340, 50,70, 30); 
     
          add(b4);
     
     
     
          Font f = new Font("Serif", Font.BOLD, 30);
     
          label1 = new JLabel("Data:");
          label1.setFont(f);
          label1.setForeground(Color.blue);
          label1.setBounds(10, 100,70, 30);
          add(label1);
     
          label2 = new JLabel("Mean: ");
          label2.setFont(f);
          label2.setForeground(Color.blue);
          label2.setBounds(10, 150,90, 30);
          add(label2);
     
          label3 = new JLabel("Standard Deviation:");
          label3.setFont(f);
          label3.setForeground(Color.blue);
          label3.setBounds(10,200,300, 30);
          add(label3);
          JCheckBox c1 = new JCheckBox("Mean");
          c1.addActionListener(new Listener1());
          c1.setBounds(10, 250,70, 30);
          add(c1); 
          JCheckBox c2 = new JCheckBox("Standard Deviation");
          c2.addActionListener(new Listener1());
          c2.setBounds(10, 300,150, 30);
          add(c2); 
     
       }
     
       public void paintComponent(Graphics g)
       {
     
       }
       private class Listener1 implements ActionListener
       {
          public void actionPerformed(ActionEvent e)          
          {
     
          }  
       }  
     
       private class Listener2 implements ActionListener
       {
          public void actionPerformed(ActionEvent e)
          {
     
     
          }
       }
       private class Listener3 implements ActionListener
       {
          public void actionPerformed(ActionEvent e)          
          {
     
          } 	
       }
       private class Listener4 implements ActionListener
       {
          public void actionPerformed(ActionEvent e)          
          {
             System.exit(0);
          } 	
       }
     
     
    }
    I want my Listener 1 to work for now. Which is the data button.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How To get Data button to Display user inputted "numbers" to data label?

    Put the following in front of the code:
    [code=java]

    YOUR CODE is HERE

    Put the following after the code:
    [/code]

    --- Update ---

    What are the steps the code needs to do to copy data from one place to another?
    Where is the data to be copied from?
    Where do you want to show that data?
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    May 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How To get Data button to Display user inputted "numbers" to data label?

    This code works when i run the driver class. However, i already have the driver class and need help in this panel.

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How To get Data button to Display user inputted "numbers" to data label?

    Ok, please explain what problems you are having. Be as specific as possible about the problems.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    May 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How To get Data button to Display user inputted "numbers" to data label?

    I just cant seem to figure out how to get data button to work. i want that button to take user doubles and show it in label, that i named as data(same name as the button name).

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How To get Data button to Display user inputted "numbers" to data label?

    how to get data button to work
    Is the listener called when the data button is pressed?

    take user doubles and show it in label,
    Where is "user doubles"?
    What label do you want to show it in? Do you know what method to call to set the text of a label?
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Junior Member
    Join Date
    May 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How To get Data button to Display user inputted "numbers" to data label?

    Yes the Listener is called when the data button is pressed.
    I want to show it in label named "data".
    I dont know what method to call to set the text of a label (New to Java sorry).

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How To get Data button to Display user inputted "numbers" to data label?

    I dont know what method to call
    Look at the API doc for the class you are working with to see what methods it has that will do what you want.
    If the class extends another class, then you might have to read the API doc for that class also to see if it has a useful method.

    The API doc: Java Platform SE 7

    Find the class in the lower left, click on it and the API doc will be displayed in the main frame.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #12
    Junior Member
    Join Date
    May 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How To get Data button to Display user inputted "numbers" to data label?

    JLabel(String text), i figured out this code is needed to set text of label. Now what should i do to proceed.

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How To get Data button to Display user inputted "numbers" to data label?

    Now what should i do to proceed.
    Write the code
    compile the code
    execute and test the code
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 1
    Last Post: October 30th, 2013, 09:55 PM
  2. "Separate Numbers"-Problem:Assigning Variables to User Inputs.
    By SaltSlasher in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 10th, 2012, 06:58 PM
  3. Reading file Data into a "struct"
    By Brandt in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: February 9th, 2011, 10:02 AM
  4. Need something like a "Hashtable<String[], Integer>" kind of data type @@
    By Albretch Mueller in forum Java Theory & Questions
    Replies: 2
    Last Post: November 27th, 2010, 10:24 PM
  5. Replies: 4
    Last Post: August 13th, 2009, 05:54 AM

Tags for this Thread