可视化atm机java
时间: 2023-12-14 19:05:22 浏览: 32
好的,下面是一个简单的可视化ATM机的Java代码示例:
```java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ATM extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;
private JTextField txtCardNumber;
private JPasswordField txtPin;
private JButton btnLogin;
private JButton btnCancel;
public ATM() {
setTitle("ATM Machine");
setSize(400, 250);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel pnlMain = new JPanel(new BorderLayout());
add(pnlMain);
JPanel pnlTop = new JPanel(new FlowLayout(FlowLayout.CENTER));
pnlMain.add(pnlTop, BorderLayout.NORTH);
JLabel lblTitle = new JLabel("Welcome to our ATM machine");
pnlTop.add(lblTitle);
JPanel pnlCenter = new JPanel(new GridLayout(2, 2, 10, 10));
pnlMain.add(pnlCenter, BorderLayout.CENTER);
JLabel lblCardNumber = new JLabel("Card Number:");
pnlCenter.add(lblCardNumber);
txtCardNumber = new JTextField();
pnlCenter.add(txtCardNumber);
JLabel lblPin = new JLabel("PIN:");
pnlCenter.add(lblPin);
txtPin = new JPasswordField();
pnlCenter.add(txtPin);
JPanel pnlBottom = new JPanel(new FlowLayout(FlowLayout.CENTER));
pnlMain.add(pnlBottom, BorderLayout.SOUTH);
btnLogin = new JButton("Login");
btnLogin.addActionListener(this);
pnlBottom.add(btnLogin);
btnCancel = new JButton("Cancel");
btnCancel.addActionListener(this);
pnlBottom.add(btnCancel);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnLogin) {
String cardNumber = txtCardNumber.getText();
String pin = new String(txtPin.getPassword());
// TODO: 进行登录验证
JOptionPane.showMessageDialog(this, "Login successful");
} else if (e.getSource() == btnCancel) {
dispose();
}
}
public static void main(String[] args) {
ATM atm = new ATM();
atm.setVisible(true);
}
}
```
以上代码实现了一个简单的ATM机界面,包含卡号和密码输入框以及登录和取消按钮。你可以根据你的需求修改代码,添加其他功能。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_lunwen.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)