Solved

JTextField getText()

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 242
How  can  i  resolve  HTTP Status 404 -? 8 61
ejb mdb examples 1 21
Html split(text) 2 32
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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 learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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…

730 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