// Tutorial 26: ATM.java
// ATM application allows users to access an account,
// view the balance and withdraw money from the account.
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.text.*;
import javax.swing.*;
import javax.swing.event.*;
public class ATM extends JFrame
{
// JTextArea to display message
private JTextArea messageJTextArea;
// JTextField to enter PIN or withdrawal amount
private JTextField numberJTextField;
// JPanel for number JButtons
private JPanel buttonsJPanel;
// JButtons for input of PIN or withdrawal amount
private JButton oneJButton;
private JButton twoJButton;
private JButton threeJButton;
private JButton fourJButton;
private JButton fiveJButton;
private JButton sixJButton;
private JButton sevenJButton;
private JButton eightJButton;
private JButton nineJButton;
private JButton zeroJButton;
// JButton to submit PIN or withdrawal amount
private JButton enterJButton;
// JButton to view balance
private JButton balanceJButton;
// JButton to withdraw from account
private JButton withdrawJButton;
// JButton to close the transaction
private JButton doneJButton;
// JPanel to get account numbers
private JPanel accountNumberJPanel;
// JLabel and JComboBox for account numbers
private JLabel accountNumberJLabel;
private JComboBox accountNumberJComboBox;
// constants for user action
private final static int ENTER_PIN = 1;
private final static int WITHDRAWAL = 2;
// instance variables used to store PIN and
// firstName from database
private String pin, firstName;
// instance variable used to distinguish user action
private int action;
// instance variables used to store user selected account number
// and PIN
private String userAccountNumber, userPIN;
// instance variable used to store account balance
private double balance;
// instance variables used to manipulate database
private Connection myConnection;
private Statement myStatement;
private ResultSet myResultSet;
// constructor
public ATM( String databaseDriver, String databaseURL )
{
// establish connection to database
try
{
// load Cloudscape driver
Class.forName( databaseDriver );
// connect to database
myConnection =
DriverManager.getConnection( databaseURL );
// create Statement for executing SQL
myStatement = myConnection.createStatement();
}
catch ( SQLException exception )
{
exception.printStackTrace();
}
catch ( ClassNotFoundException exception )
{
exception.printStackTrace();
}
createUserInterface(); // set up GUI
} // end constructor
// create and position GUI components; register event handler
private void createUserInterface()
{
// get content pane for attaching GUI components
Container contentPane = getContentPane();
// enable explicit positioning of GUI components
contentPane.setLayout( null );
// set up messageJTextArea
messageJTextArea = new JTextArea();
messageJTextArea.setBounds( 40, 16, 288, 88 );
messageJTextArea.setText(
"Please select your account number." );
messageJTextArea.setBorder(
BorderFactory.createLoweredBevelBorder() );
messageJTextArea.setEditable( false );
contentPane.add( messageJTextArea );
// set up numberJTextField
numberJTextField = new JTextField();
numberJTextField.setBounds( 110, 120, 128, 21 );
numberJTextField.setBorder(
BorderFactory.createLoweredBevelBorder() );
numberJTextField.setEditable( false );
contentPane.add( numberJTextField );
// set up buttonsJPanel
buttonsJPanel = new JPanel();
buttonsJPanel.setBounds( 44, 160, 276, 150 );
buttonsJPanel.setBorder( BorderFactory.createEtchedBorder() );
buttonsJPanel.setLayout( null );
contentPane.add( buttonsJPanel );
// set up oneJButton
oneJButton = new JButton();
oneJButton.setBounds( 53, 28, 24, 24 );
oneJButton.setText( "1" );
oneJButton.setBorder(
BorderFactory.createRaisedBevelBorder() );
buttonsJPanel.add( oneJButton );
oneJButton.addActionListener(
new ActionListener() // anonymous inner class
{
// event handler called when oneJButton is clicked
public void actionPerformed( ActionEvent event )
{
oneJButtonActionPerformed( event );
}
} // end anonymous inner class
); // end call to addActionListener
// set up twoJButton
twoJButton = new JButton();
twoJButton.setBounds( 77, 28, 24, 24 );
twoJButton.setText( "2" );
twoJButton.setBorder(
BorderFactory.createRaisedBevelBorder() );
buttonsJPanel.add( twoJButton );
twoJButton.addActionListener(
new ActionListener() // anonymous inner class
{
// event handler called when twoJButton is clicked
public void actionPerformed( ActionEvent event )
{
twoJButtonActionPerformed( event );
}
} // end anonymous inner class
); // end call to addActionListener
// set up threeJButton
threeJButton = new JButton();
threeJButton.setBounds( 101, 28, 24, 24 );
threeJButton.setText( "3" );
threeJButton.setBorder(
BorderFactory.createRaisedBevelBorder() );
buttonsJPanel.add( threeJButton );
threeJButton.addActionListener(
new ActionListener() // anonymous inner class
{
// event handler called when threeJButton is clicked
public void actionPerformed( ActionEvent event )
{
threeJButtonActionPerformed( event );
}
} // end anonymous inner class
); // end call to addActionListener
// set up fourJButton
fourJButton = new JButton();
fourJButton.setBounds( 53, 52, 24, 24 );
fourJButton.setText( "4" );
fourJButton.setBorder(
BorderFactory.createRaisedBevelBorder() );
buttonsJPanel.add( fourJButton );
fourJButton.addActionListener(
new ActionListener() // anonymous inner class
{
// event handler called when fourJButton is clicked
public void actionPerformed( ActionEvent event )
{
fourJButtonActionPerformed( event );
}
} // end anonymous inner class
); // end call to addActionListener
// set up fiveJButton
fiveJButton = new JButton();
fiveJButton.setBounds( 77, 52, 24, 24 );
fiveJButton.setText( "5" );
fiveJButton.setBorder(
BorderFactory.createRaisedBevelBorder() );
buttonsJPanel.add( fiveJButton );
fiveJButton.addActionListener(
new ActionListener() // anonymous inner class
{
// event handler called when fiveJButton is clicked
public void actionPerformed( ActionEvent event )
{
fiveJButtonActionPerformed( event );
}
} // end anonymous inner class
); // end call to addActionListener
// set up sixJButton
sixJButton = new JButton();
sixJButton.setBounds( 101, 52, 24, 24 );
sixJButton.setText( "6" );
sixJButton.setBorder(
BorderFactory.createRaisedBevelBorder() );
buttonsJPanel.add( sixJButton );
sixJButton.addActionListener(
new ActionListener() // anonymous inner class
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
java大学简明教程光盘代码 (1155个子文件)
CarPayment.java.bak 6KB
OfficeSupplies.java.bak 5KB
OddNumbers.java.bak 4KB
SetClasspath.bat 228B
SetClasspath.bat 228B
SetClasspath.bat 228B
SetClasspath.bat 228B
SetClasspath.bat 228B
SetClasspath.bat 228B
TypingApplication.class 13KB
ATM.class 13KB
ShippingHub.class 10KB
MicrowaveOven.class 8KB
FuzzyDiceOrderForm.class 7KB
SecurityPanel.class 7KB
StudentGrades.class 6KB
FuzzyDiceOrderForm.class 6KB
WriteEvent.class 5KB
FuzzyDiceOrderForm.class 5KB
InterestCalculator.class 5KB
TicketInformation.class 5KB
CrapsGame.class 5KB
PresentValue.class 4KB
InterestCalculator.class 4KB
DentalPayment.class 4KB
FlagQuiz.class 4KB
PhoneBook.class 4KB
ScreenScraping.class 4KB
DentalPayment.class 4KB
AccountInformation.class 4KB
CarPayment.class 4KB
InterestCalculator.class 4KB
Inventory.class 4KB
AccountInformation.class 3KB
AccountInformation.class 3KB
SalesCommissionCalculator.class 3KB
CarPayment.class 3KB
ClassAverage.class 3KB
Fundraiser.class 3KB
HypotenuseCalculator.class 3KB
DentalPayment.class 3KB
MortgageCalculator.class 3KB
Average.class 3KB
Maximum.class 3KB
PayRaise.class 3KB
PaintPanel.class 3KB
WageCalculator.class 3KB
DrawingShapes.class 3KB
OddNumbers.class 3KB
WageCalculator.class 3KB
Inventory.class 3KB
GuessNumber.class 3KB
SiblingSurvey.class 3KB
Inventory.class 2KB
CarPayment.class 2KB
Inventory.class 2KB
Factorial.class 2KB
GradeConverter.class 2KB
OfficeSupplies.class 2KB
MovingShape.class 2KB
MovingShapes.class 2KB
PaintJPanel.class 2KB
PaintProgram.class 2KB
SumArray.class 2KB
TemperatureConversion.class 2KB
DrawJPanel.class 2KB
DrawJPanel.class 2KB
ScreenSaver.class 2KB
Counter.class 2KB
Welcome.class 2KB
MovingShape$1.class 1KB
Parcel.class 1KB
Shape.class 1KB
MyShape.class 1KB
PaintProgram$1.class 951B
MovingShapes$1.class 951B
Painter.class 908B
CookingTime.class 801B
CookingTime.class 793B
DrawJPanel$1.class 748B
MyRectangle.class 711B
TypingApplication$5.class 704B
MyRectangle.class 687B
BoundedShape.class 685B
MyOval.class 677B
Inventory$3.class 671B
OddNumbers$1.class 648B
Inventory$1.class 629B
Inventory$2.class 629B
TypingApplication$7.class 629B
Rectangle.class 624B
Oval.class 614B
HypotenuseCalculator$1.class 598B
InterestCalculator$3.class 592B
DrawJPanel$2.class 590B
AccountInformation$1.class 586B
AccountInformation$1.class 586B
InterestCalculator$4.class 586B
AccountInformation$1.class 586B
InterestCalculator$5.class 586B
共 1155 条
- 1
- 2
- 3
- 4
- 5
- 6
- 12
liqingwen201211
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页