// MedicalRecord类,包含了病历信息 public class main { private String patientName; private String visitRecord; private String checkRecord; private String medicalAdvice; public main(String patientName, String visitRecord, String checkRecord, String medicalAdvice) { this.patientName = patientName; this.visitRecord = visitRecord; this.checkRecord = checkRecord; this.medicalAdvice = medicalAdvice; } public String getPatientName() { return patientName; } public String getVisitRecord() { return visitRecord; } public void setVisitRecord(String visitRecord) { this.visitRecord = visitRecord; } public String getCheckRecord() { return checkRecord; } public void setCheckRecord(String checkRecord) { this.checkRecord = checkRecord; } public String getMedicalAdvice() { return medicalAdvice; } public void setMedicalAdvice(String medicalAdvice) { this.medicalAdvice = medicalAdvice; }帮我根据这个写一个通过图形化界面运行的main函数
时间: 2024-01-09 10:03:38 浏览: 50
好的,以下是一个基本的通过图形化界面运行的main函数:
```
import javax.swing.*;
public class MedicalRecordGUI extends JFrame {
private JTextField patientNameField;
private JTextArea visitRecordArea;
private JTextArea checkRecordArea;
private JTextArea medicalAdviceArea;
public MedicalRecordGUI() {
initComponents();
}
private void initComponents() {
JLabel patientNameLabel = new JLabel();
JLabel visitRecordLabel = new JLabel();
JLabel checkRecordLabel = new JLabel();
JLabel medicalAdviceLabel = new JLabel();
JScrollPane visitRecordScrollPane = new JScrollPane();
JScrollPane checkRecordScrollPane = new JScrollPane();
JScrollPane medicalAdviceScrollPane = new JScrollPane();
JButton saveButton = new JButton();
patientNameLabel.setText("Patient Name:");
patientNameField = new JTextField();
visitRecordLabel.setText("Visit Record:");
visitRecordArea = new JTextArea(5, 20);
visitRecordScrollPane.setViewportView(visitRecordArea);
checkRecordLabel.setText("Check Record:");
checkRecordArea = new JTextArea(5, 20);
checkRecordScrollPane.setViewportView(checkRecordArea);
medicalAdviceLabel.setText("Medical Advice:");
medicalAdviceArea = new JTextArea(5, 20);
medicalAdviceScrollPane.setViewportView(medicalAdviceArea);
saveButton.setText("Save");
saveButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
saveButtonActionPerformed(evt);
}
});
GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(patientNameLabel)
.addComponent(visitRecordLabel)
.addComponent(checkRecordLabel)
.addComponent(medicalAdviceLabel))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(patientNameField)
.addComponent(visitRecordScrollPane, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
.addComponent(checkRecordScrollPane)
.addComponent(medicalAdviceScrollPane))
.addContainerGap())
.addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(saveButton)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(patientNameLabel)
.addComponent(patientNameField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(visitRecordLabel)
.addComponent(visitRecordScrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(checkRecordLabel)
.addComponent(checkRecordScrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(medicalAdviceLabel)
.addComponent(medicalAdviceScrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(saveButton)
.addContainerGap())
);
pack();
}
private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {
String patientName = patientNameField.getText();
String visitRecord = visitRecordArea.getText();
String checkRecord = checkRecordArea.getText();
String medicalAdvice = medicalAdviceArea.getText();
MedicalRecord record = new MedicalRecord(patientName, visitRecord, checkRecord, medicalAdvice);
// 进行保存操作
}
public static void main(String[] args) {
MedicalRecordGUI gui = new MedicalRecordGUI();
gui.setVisible(true);
}
}
```
需要注意的是,这个GUI只是一个演示,具体的保存操作需要根据实际需求进行实现。
阅读全文