Solved

JTextField getText()

Posted on 2006-07-05
4
1,828 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.

734 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