Solved

JTextField getText()

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 …
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 about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

708 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

12 Experts available now in Live!

Get 1:1 Help Now