Here's a weird one. I compile and run this code, and get Bob Jones as the account holder, and a Withdrawel <sic> JTextField where there should not be one. Anybody help me on this one? -
-
// Exercise 4.16: AccountInformation.java
-
// This application inputs and outputs account information.
-
import java.awt.*;
-
import java.awt.event.*;
-
import javax.swing.*;
-
import javax.swing.border.*;
-
-
public class AccountInformation extends JFrame
-
{
-
// JPanel to group deposit components
-
private JPanel enterJPanel;
-
-
// JLabel and JTextField for deposits
-
private JLabel depositJLabel;
-
private JTextField depositJTextField;
-
-
// JButton to initiate balance calculation
-
private JButton enterJButton;
-
-
// JPanel to group account information components
-
private JPanel accountJPanel;
-
-
// JLabel and JTextField for account holder's name
-
private JLabel nameJLabel;
-
private JTextField nameJTextField;
-
-
// JLabel and JTextField for account number
-
private JLabel accountNumberJLabel;
-
private JTextField accountNumberJTextField;
-
-
// JLabel and JTextField for balance
-
private JLabel balanceJLabel;
-
private JTextField balanceJTextField;
-
-
// no-argument constructor
-
public AccountInformation()
-
{
-
createUserInterface();
-
}
-
-
// create and position GUI components; register event handlers
-
private void createUserInterface()
-
{
-
// get content pane and set layout to null
-
Container contentPane = getContentPane();
-
contentPane.setLayout( null );
-
-
// set up enterJPanel
-
enterJPanel = new JPanel();
-
enterJPanel.setLayout( null );
-
enterJPanel.setBounds( 16, 16, 152, 126 );
-
enterJPanel.setBorder(
-
new TitledBorder( "Enter information" ) );
-
contentPane.add( enterJPanel );
-
-
// set up depositJLabel
-
depositJLabel = new JLabel();
-
depositJLabel.setText( "Deposit amount:" );
-
depositJLabel.setBounds( 16, 40, 140, 16 );
-
enterJPanel.add( depositJLabel );
-
-
// set up depositJTextField
-
depositJTextField = new JTextField();
-
depositJTextField.setText( "0" );
-
depositJTextField.setBounds( 16, 56, 120, 21 );
-
depositJTextField.setHorizontalAlignment( JTextField.RIGHT );
-
enterJPanel.add( depositJTextField );
-
-
// set up enterJButton
-
enterJButton = new JButton();
-
enterJButton.setText( "Enter" );
-
enterJButton.setBounds( 16, 150, 152, 34 );
-
contentPane.add( enterJButton );
-
enterJButton.addActionListener(
-
-
new ActionListener() // anonymous inner class
-
{
-
// event handler called when enterJButton is pressed
-
public void actionPerformed( ActionEvent event )
-
{
-
enterJButtonActionPerformed( event );
-
}
-
-
} // end anonymous inner class
-
-
); // end call to addActionListener
-
-
// set up accountJPanel
-
accountJPanel = new JPanel();
-
accountJPanel.setLayout( null );
-
accountJPanel.setBounds( 180, 16, 136, 170 );
-
accountJPanel.setBorder(
-
new TitledBorder( "Account information" ) );
-
contentPane.add( accountJPanel );
-
-
// set up nameJLabel
-
nameJLabel = new JLabel();
-
nameJLabel.setText( "Name:" );
-
nameJLabel.setBounds( 16, 24, 100, 16 );
-
accountJPanel.add( nameJLabel );
-
-
// set up nameJTextField
-
nameJTextField = new JTextField();
-
nameJTextField.setText( "Sue Purple" );
-
nameJTextField.setBounds( 16, 40, 104, 21 );
-
nameJTextField.setEditable( false );
-
accountJPanel.add( nameJTextField );
-
-
// set up accountNumberJLabel
-
accountNumberJLabel = new JLabel();
-
accountNumberJLabel.setText( "Account Number:" );
-
accountNumberJLabel.setBounds( 16, 70, 140, 16 );
-
accountJPanel.add( accountNumberJLabel );
-
-
// set up accountNumberJTextField
-
accountNumberJTextField = new JTextField();
-
accountNumberJTextField.setText( "12345" );
-
accountNumberJTextField.setBounds( 16, 86, 104, 21 );
-
accountNumberJTextField.setEditable( false );
-
accountNumberJTextField.setHorizontalAlignment(
-
JTextField.RIGHT );
-
accountJPanel.add( accountNumberJTextField );
-
-
// set up balanceJLabel
-
balanceJLabel = new JLabel();
-
balanceJLabel.setText( "Balance:" );
-
balanceJLabel.setBounds( 16, 116, 100, 16 );
-
accountJPanel.add( balanceJLabel );
-
-
// set up balanceJTextField
-
balanceJTextField = new JTextField();
-
balanceJTextField.setText( "0" );
-
balanceJTextField.setBounds( 16, 132, 104, 21 );
-
balanceJTextField.setEditable( false );
-
balanceJTextField.setHorizontalAlignment( JTextField.RIGHT );
-
accountJPanel.add( balanceJTextField );
-
-
// set properties of application's window
-
setTitle( "Account Information" ); // set title bar text
-
setSize( 325, 225 ); // set window size
-
setVisible( true ); // display window
-
-
} // end method createUserInterface
-
-
// method called when enterJButton is pressed
-
private void enterJButtonActionPerformed( ActionEvent event )
-
{
-
// display new balance
-
balanceJTextField.setText( String.valueOf(
-
Integer.parseInt( depositJTextField.getText() ) -
-
Integer.parseInt( withdrawelJTextField.getText() ) ) );
-
-
// clear depositJTextField
-
depositJTextField.setText( "0" );
-
-
} // end method enterJButtonActionPerformed
-
-
// main method
-
public static void main( String[] args )
-
{
-
AccountInformation application = new AccountInformation();
-
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
-
-
} // end method main
-
-
} // end class AccountInformation
-
-
I just can't figure this out. I sent in the code to my teacher, and he says he can't figure it out, either. How can the text, "Bob Jones", appear, when it does not exist anywhere in the code?
Flummoxed.
4 1446
What is suprising me now is that on 151 you have - ...Integer.parseInt( withdrawelJTextField.getText() ) ) );
and yet you have not defined a variable called withdrawelJTextField anywhere in your code.
Are you sure this compiles?
I'm sorry. I guess it does not compile; it gives me that error. But it still runs the weird output. Could this be the reason? You can see on line 104 that the nameJTextField is set to "Sue Purple", and yet this text does not appear anywhere in the output. Instead, the text "Bob Jones" appears. Also, there is no code which sets up a withdrawelJLabel, yet this label appears in the output. I guess the first thing to do is to go ahead and code a withdrawelJLabel, as well as a withdrawelJTextField. But I'm still at a loss to figure out this screwy output. If I could figure out how to post an image in a reply, I would post the output. I guess I should have posted the outputted image in the first place.....
I'm sorry. I guess it does not compile; it gives me that error. But it still runs the weird output. Could this be the reason? You can see on line 104 that the nameJTextField is set to "Sue Purple", and yet this text does not appear anywhere in the output. Instead, the text "Bob Jones" appears. Also, there is no code which sets up a withdrawelJLabel, yet this label appears in the output. I guess the first thing to do is to go ahead and code a withdrawelJLabel, as well as a withdrawelJTextField. But I'm still at a loss to figure out this screwy output. If I could figure out how to post an image in a reply, I would post the output. I guess I should have posted the outputted image in the first place.....
If the code does not compile, then a class file won't be created and you can't run the program. So which program is giving you the strange output?
I guess the code that is running is not the code we're seeing here.
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Roger Shrubber |
last post by:
I have a page with images that the user can drag from one frame to
another. I need them to see a "ghost image" of the image they are
dragging, while the original stays put. I use the onmousemove...
|
by: otisim |
last post by:
I have a test environment that we rebuild servers on a regular basis.
To streamline the process we use ghost. We will be installing SQL on
the servers and want to build a ghost image with that...
|
by: Peter Flickinger |
last post by:
I have been using a label with the TreeView control - to
simulate the ghost image of a node during drag/drop (so
that a ghost of the node appears to be floating next to
the cursor on a drag/drop)....
|
by: Peteroid |
last post by:
When the application I'm working on is run it creates a panel with a Paint
event customized to draw primitives (circles, rectangles, etc.), places the
panel on a form, and then launches the form....
|
by: Tim Marshall |
last post by:
Does anyone else get "ghost" VB editor windows appear on their computers
when developing in Access 2003?
These are VB editor windows with no menu items and a grey empty
background. I usually...
|
by: Howard Kaikow |
last post by:
It was my expectation that a sub using the usual recursive
FindFirstFile/FindNextFile would be able to walk the directory tree on any
logical volume.
I am finding that this may not be the case...
|
by: bbcrock |
last post by:
I do not have a link to point you to at this time, sorry. It's an
internal application.
I have some JS code that hides the current div, sets the tabnumber
passed in as the current tab number,...
|
by: bbcrock |
last post by:
I do not have a link to point you to at this time, sorry. It's an
internal application.
I have some JS code that hides the current div (group1Tab1), sets the
tabnumber
passed in as the current...
|
by: Geolas |
last post by:
Hi, new to this community.I am not really sure if this was the right place, because this community seem to be for developers really.
Well my question is, as the topic states, how to create a...
|
by: buntybutt |
last post by:
Hi!!!
I have the windows Xp proffesional service pack 1 Symentec Ghost edition. I want the service pack 2 Ghost edition.
Help me to get URL.
Thank you very...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |