Solved

JTextField getText()

Posted on 2006-07-05
4
1,805 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Free Alternative to JIRA 4 91
HSSFWorkbook cannot be resolved error 10 50
ForLoop Example 3 40
use lov values 2 33
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

896 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now