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

Thread: how do i get the answer to appear in textFieldD (line 92)

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how do i get the answer to appear in textFieldD (line 92)

    import java.awt.EventQueue;
     
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JTextField;
    import javax.swing.JButton;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
     
     
    public class Week02 {
     
    	private JFrame frame;
    	private JTextField textFieldA;
    	private JTextField textFieldB;
    	private JTextField textFieldC;
    	private JTextField textFieldD;
    	private JButton btnNewButton;
     
    	/**
    	 * Launch the application.
    	 */
    	public static void main(String[] args) {
    		EventQueue.invokeLater(new Runnable() {
    			public void run() {
    				try {
    					Week02 window = new Week02();
    					window.frame.setVisible(true);
    				} catch (Exception e) {
    					e.printStackTrace();
    				}
    			}
    		});
    	}
     
    	/**
    	 * Create the application.
    	 */
    	public Week02() {
    		initialize();
    	}
     
    	/**
    	 * Initialize the contents of the frame.
    	 */
    	private void initialize() {
    		frame = new JFrame();
    		frame.setBounds(100, 100, 546, 412);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.getContentPane().setLayout(null);
     
    		textFieldA = new JTextField();
    		textFieldA.setBounds(30, 31, 173, 53);
    		frame.getContentPane().add(textFieldA);
    		textFieldA.setColumns(10);
     
    		textFieldB = new JTextField();
    		textFieldB.setBounds(30, 119, 173, 53);
    		frame.getContentPane().add(textFieldB);
    		textFieldB.setColumns(10);
     
    		textFieldC = new JTextField();
    		textFieldC.setBounds(30, 206, 173, 58);
    		frame.getContentPane().add(textFieldC);
    		textFieldC.setColumns(10);
     
    		textFieldD = new JTextField();
    		textFieldD.setEditable(false);
    		textFieldD.setBounds(30, 288, 173, 53);
    		frame.getContentPane().add(textFieldD);
    		textFieldD.setColumns(10);
     
    		JButton compute = new JButton("Compute");
    		compute.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    				String Input;
    				double textFieldA;
    				double textFieldB;
    				double textFieldC;
    				double textFieldD;
    				double Add;
    				double Multiply;
    				double Divide;
    				double Subtract;
     
    				if (textFieldC == Add) {
     
    					double a, b, c;
    					a = Double.parseDouble(Input);
    					b = Double.parseDouble(Input);
    					c = a + b;
    					textFieldD (+ c); //how do we send the answer to textFieldD???? this method isn't working
    				}
     
    			}
    		});
    		compute.setBounds(233, 224, 139, 29);
    		frame.getContentPane().add(compute);
     
    		btnNewButton = new JButton("Instructions");
    		btnNewButton.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    				JOptionPane.showMessageDialog(null, "All possable imputs \n" +
    						"Add \n" +
    						"Subtract \n" +
    						"Multiply \n" +
    						"Divide \n");
    			}
    		});
    		btnNewButton.setBounds(382, 224, 123, 29);
    		frame.getContentPane().add(btnNewButton);
    	}
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: how do i get the answer to appear in textFieldD (line 92)

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


    text fields have methods you can call to set the text that is being shown. Read the API doc to see what methods the class has.
    Java Platform SE 7
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how do i get the answer to appear in textFieldD (line 92)

    i wrapped the code. i really don't know what that line needs to be to display the answer in a textfield. :/

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: how do i get the answer to appear in textFieldD (line 92)

    Read the API doc to see what methods the class has. You will need to use one of them to display the data.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jan 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how do i get the answer to appear in textFieldD (line 92)

    what if i dont know what class?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: how do i get the answer to appear in textFieldD (line 92)

    I don't understand how you don't know the class of a variable.
    One way to find the class of a variable is to use the editor on the source code and do a Find for the variable's name. Some where in the code there will be a definition for the variable. When you find the definition the name of the class will be on the line with the variable name to the left of the name.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 10
    Last Post: September 16th, 2011, 07:49 PM
  2. Reading a file line by line using the Scanner class
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: April 17th, 2009, 07:34 AM
  3. Reading a file line by line using the Scanner class
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: April 17th, 2009, 07:34 AM
  4. How to Read a file line by line using BufferedReader?
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: May 19th, 2008, 06:32 AM
  5. How to Read a file line by line using BufferedReader?
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: May 19th, 2008, 06:32 AM