📄 dentalpayment.java
字号:
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import javax.swing.*;
public class DentalPayment extends JFrame
{
private JLabel dentalPaymentFormJLabel;
private JLabel patientNameJLabel;
private JTextField patientNameJTextField;
private JCheckBox cleaningJCheckBox;
private JLabel cleaningPriceJLabel;
private JCheckBox cavityFillingJCheckBox;
private JLabel cavityFillingPriceJLabel;
private JCheckBox xRayJCheckBox;
private JLabel xRayPriceJLabel;
private JLabel totalJLabel;
private JTextField totalJTextField;
private JButton calculateJButton;
public DentalPayment()
{
createUserInterface();
}
private void createUserInterface()
{
Container contentPane = getContentPane();
contentPane.setLayout(null);
dentalPaymentFormJLabel = new JLabel();
dentalPaymentFormJLabel.setBounds(19,19,235,28);
dentalPaymentFormJLabel.setText("Dental Payment Form");
dentalPaymentFormJLabel.setFont(new Font("Default",Font.PLAIN,22));
dentalPaymentFormJLabel.setHorizontalAlignment(JLabel.CENTER);
contentPane.add(dentalPaymentFormJLabel);
patientNameJLabel = new JLabel();
patientNameJLabel.setBounds(19,65,91,21);
patientNameJLabel.setText("Patient name:");
contentPane.add(patientNameJLabel);
patientNameJTextField = new JTextField();
patientNameJTextField.setBounds(132,65,117,21);
contentPane.add(patientNameJTextField);
cleaningJCheckBox = new JCheckBox();
cleaningJCheckBox.setBounds(16,112,122,24);
cleaningJCheckBox.setText("Cleaning");
contentPane.add(cleaningJCheckBox);
cleaningPriceJLabel = new JLabel();
cleaningPriceJLabel.setBounds(211,112,38,24);
cleaningPriceJLabel.setText("$35");
cleaningPriceJLabel.setHorizontalAlignment(JLabel.RIGHT);
contentPane.add(cleaningPriceJLabel);
cavityFillingJCheckBox = new JCheckBox();
cavityFillingJCheckBox.setBounds(16,159,122,24);
cavityFillingJCheckBox.setText("Cavity Filling");
contentPane.add(cavityFillingJCheckBox);
cavityFillingPriceJLabel = new JLabel();
cavityFillingPriceJLabel.setBounds(211,159,38,24);
cavityFillingPriceJLabel.setText("$150");
cavityFillingPriceJLabel.setHorizontalAlignment(JLabel.RIGHT);
contentPane.add(cavityFillingPriceJLabel);
xRayJCheckBox = new JCheckBox();
xRayJCheckBox.setBounds(16,206,122,24);
xRayJCheckBox.setText("X-Ray");
contentPane.add(xRayJCheckBox);
xRayPriceJLabel = new JLabel();
xRayPriceJLabel.setBounds(211,206,38,24);
xRayPriceJLabel.setText("$85");
xRayPriceJLabel.setHorizontalAlignment(JLabel.RIGHT);
contentPane.add(xRayPriceJLabel);
totalJLabel = new JLabel();
totalJLabel.setBounds(144,256,41,21);
totalJLabel.setText("Total:");
contentPane.add(totalJLabel);
totalJTextField = new JTextField();
totalJTextField.setBounds(192,256,56,21);
totalJTextField.setEditable(false);
totalJTextField.setHorizontalAlignment(JTextField.CENTER);
contentPane.add(totalJTextField);
calculateJButton = new JButton();
calculateJButton.setBounds(155,296,94,24);
calculateJButton.setText("Calculate");
contentPane.add(calculateJButton);
calculateJButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
calculateJButtonActionPerformed(event);
}
}
);
setTitle("Dental Payment");
setSize(272,364);
setVisible(true);
}
private void calculateJButtonActionPerformed(ActionEvent event)
{
String patient = patientNameJTextField.getText();
if((patient.equals(""))||(!cleaningJCheckBox.isSelected()&&!
!cavityFillingJCheckBox.isSelected()&&!xRayJCheckBox.isSelected()))
{
JOptionPane.showMessageDialog(null,"Please fuck.","fuck her"
,JOptionPane.ERROR_MESSAGE);
}
else
{
double total = 0.0;
if(cleaningJCheckBox.isSelected())
{
total += 35 ;
}
if(cavityFillingJCheckBox.isSelected())
{
total += 150 ;
}
if(xRayJCheckBox.isSelected())
{
total += 85 ;
}
DecimalFormat dollars = new DecimalFormat("$0.00");
totalJTextField.setText(dollars.format(total));
}
}
public static void main(String[]args)
{
DentalPayment application = new DentalPayment();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -