Solved

JTextField getText()

Posted on 2006-07-05
4
1,812 Views
Last Modified: 2012-06-21
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Chapter636 extends JApplet
{
      private static final long serialVersionUID = 1L;
      public void init()
      {
            Container Form = getContentPane();
            Form.setLayout(new BorderLayout());
            JButton Calculate = new JButton("Calculate");
            Form.add(Calculate,BorderLayout.SOUTH);
            JPanel Panel = new JPanel();
            JTextField Base = new JTextField("Base",5);
            JTextField Exp = new JTextField("Exp",5);
            Panel.add(Base,BorderLayout.NORTH);
            Panel.add(Exp,BorderLayout.SOUTH);
            Form.add(Panel,BorderLayout.NORTH);
            Calculate.addActionListener(
                        new ActionListener()
                        {
                              public void actionPerformed(ActionEvent e)
                              {
                                    //JOptionPane.showMessageDialog(null,Base.getText()); //////////////////Error\\\\\\\\\\\\\\\\\\\\\\\
                              }
                        });
      }
}

In the above code, what do I need to change in order to get the value of the text field Base?
0
Comment
Question by:List244
  • 3
4 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
ID: 17045302
final JTextField Base = new JTextField("Base",5);
0
 
LVL 8

Author Comment

by:List244
ID: 17045323
Why does it need to be final?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17045401
Because Base is accessed in an anonymous class
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17045525
:-)
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 86
eclipse java  build path 6 57
xampp tool 12 49
ejb on wildfly 5 20
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question