有人知道如何在鼠标悬停在单选按钮上时显示文字吗?
我尝试了setToolTipText,但它不起作用。
RadioButton的代码
rdbtnPediatric = new JRadioButton("Pediatric");
rdbtnPediatric.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String departmentSelection = "Pediatric";
ChangeBedControl cbcS = new ChangeBedControl();
ArrayList<ChangeBed> bedList = new ArrayList<ChangeBed>();
bedList = cbcS.processGetAvailBedsEdit(bedStatusF, departmentSelection);
comboBoxAllocateBed.removeAllItems();
for (int i = 0; i < bedList.size(); i++) {
comboBoxAllocateBed.addItem(bedList.get(i).getBedID());
}
}
});
department.add(rdbtnPediatric);
rdbtnPediatric.setBounds(229, 219, 81, 25);
rdbtnPediatric.setForeground(colour);
contentPane.add(rdbtnPediatric);
在悬停单选按钮时显示文本的条件代码
ChangeBedControl cbc8 = new ChangeBedControl();
bedList = cbc8.processCountBedsAvailableDpt4();
for (int i = 0; i < bedList.size(); i++) {
bedsAvailPediatric = bedList.get(i).getRowCountAvail();
}
if (bedsAvailPediatric <= 3) {
rdbtnPediatric.setForeground(Color.RED);
//Show a text "bed count low."
}
此课程的完整代码
package Boundary;
public class CreateBedForm extends JFrame {
private JPanel contentPane;
private JTextField textFieldPatientID;
private JTextField textFieldPatientName;
private JComboBox comboBoxAllocateBed;
private JComboBox comboBoxDpt;
private String bedStatusF = "Available";
private String selectedDepartment = "";
private JRadioButton rdbtnCardiothoracic;
private JRadioButton rdbtnOncology;
private JRadioButton rdbtnOrthopaedic;
private JRadioButton rdbtnPediatric;
private int bedsAvailCardio;
private int bedsAvailOncology;
private int bedsAvailOrtho;
private int bedsAvailPediatric;
private Color colour = new Color(0, 204, 0);
private final ButtonGroup department = new ButtonGroup();
private String msgCA = "Beds are running out for Cardiothoracic Department!" + bedsAvailCardio + " beds left!";
private String msgON = "Beds are running out for Oncology Department!" + bedsAvailOncology + " beds left!";
private String msgOR = "Beds are running out for Orthopaedic Department!" + bedsAvailOrtho + " beds left!";
private String msgPE = "Beds are running out for Orthopaedic Department!" + bedsAvailPediatric + " beds left!";
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
CreateBedForm frame = new CreateBedForm("", "", "");
frame.setVisible(true);
frame.setLocationRelativeTo(null);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public CreateBedForm(String val1, String val2, String admissionID) {
setTitle("Assign Bed");
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setBounds(100, 100, 450, 400);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblPatientId = new JLabel("Patient ID:");
lblPatientId.setBounds(42, 52, 71, 16);
contentPane.add(lblPatientId);
JLabel lblPatientName = new JLabel("Patient Name:");
lblPatientName.setBounds(42, 97, 96, 16);
contentPane.add(lblPatientName);
textFieldPatientID = new JTextField();
textFieldPatientID.setEditable(false);
textFieldPatientID.setBounds(138, 49, 116, 22);
contentPane.add(textFieldPatientID);
textFieldPatientID.setColumns(10);
textFieldPatientName = new JTextField();
textFieldPatientName.setEditable(false);
textFieldPatientName.setBounds(138, 94, 116, 22);
contentPane.add(textFieldPatientName);
textFieldPatientName.setColumns(10);
JLabel lblAllocatedBed = new JLabel("Allocated Bed:");
lblAllocatedBed.setBounds(42, 183, 96, 16);
contentPane.add(lblAllocatedBed);
comboBoxAllocateBed = new JComboBox();
comboBoxAllocateBed.setBounds(138, 180, 71, 22);
contentPane.add(comboBoxAllocateBed);
JLabel lblNewLabel = new JLabel("Department:");
lblNewLabel.setBounds(42, 142, 96, 16);
contentPane.add(lblNewLabel);
JButton btnAssignBed = new JButton("Assign Bed");
btnAssignBed.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//Adding
String patientID = textFieldPatientID.getText();
String patientName = textFieldPatientName.getText();
String selectedDepartment = comboBoxDpt.getSelectedItem().toString();
String selectedBed = comboBoxAllocateBed.getSelectedItem().toString();
ChangeBed cb = new ChangeBed(selectedBed, selectedDepartment, patientID, patientName);
ChangeBedControl cbc = new ChangeBedControl();
cbc.processAssignBeds(cb, selectedBed);
//Updating
bedStatusF = "Unavailable";
ChangeBed cb2 = new ChangeBed(selectedBed, selectedDepartment, patientID, patientName);
ChangeBedControl cbc2 = new ChangeBedControl();
cbc2.processAssignBeds2(cb2, selectedBed, bedStatusF);
dispose();
File desktop = new File(System.getProperty("user.home"), "/Desktop");
Document document = new Document(PageSize.A4.rotate());
com.itextpdf.text.Font font1 = FontFactory.getFont("Verdana", 25, Font.BOLD);
com.itextpdf.text.Font font2 = FontFactory.getFont("Verdana", 15, Font.BOLD);
Paragraph p = new Paragraph(("Patient Admission Details"), font1);
Paragraph p1 = new Paragraph(("Admission ID"), font2);
Paragraph p2 = new Paragraph(("Patient ID"), font2);
Paragraph p3 = new Paragraph(("Patient Name"), font2);
Paragraph p4 = new Paragraph(("Date and Time Admitted"), font2);
Paragraph p5 = new Paragraph(("Reason"), font2);
Paragraph p6 = new Paragraph(("Date and Time Discharged"), font2);
Paragraph pp = new Paragraph(("Bed Allocation Details"), font1);
Paragraph p01 = new Paragraph(("Bed ID"), font2);
Paragraph p02 = new Paragraph(("Department"), font2);
try {
PageSize.A4.rotate();
PdfWriter.getInstance(document, new FileOutputStream(desktop + "/" + textFieldPatientName.getText() + " Admission.pdf"));
document.open();
document.add(p);
PdfPTable table = new PdfPTable(6);
table.setWidthPercentage(102);
PdfPCell cell1 = new PdfPCell();
cell1.addElement(p1);
PdfPCell cell2 = new PdfPCell();
cell2.addElement(p2);
PdfPCell cell3 = new PdfPCell();
cell3.addElement(p3);
PdfPCell cell4 = new PdfPCell();
cell4.addElement(p4);
PdfPCell cell5 = new PdfPCell();
cell5.addElement(p5);
PdfPCell cell6 = new PdfPCell();
cell6.addElement(p6);
AdmissionInfoControl aic1 = new AdmissionInfoControl();
ArrayList<AdmissionInfo> admissionList = new ArrayList<AdmissionInfo>();
admissionList = aic1.processGetAdmissionInfoView(admissionID);
PdfPCell ell1;
PdfPCell ell2;
PdfPCell ell3;
PdfPCell ell4;
PdfPCell ell5;
PdfPCell ell6;
for (int i = 0; i < admissionList.size(); i++) {
ell1 = new PdfPCell(new Paragraph(admissionList.get(i).getAdmissionID()));
ell2 = new PdfPCell(new Paragraph(admissionList.get(i).getPatientID()));
ell3 = new PdfPCell(new Paragraph(admissionList.get(i).getPatientName()));
ell4 = new PdfPCell(new Paragraph(admissionList.get(i).getDateAdmitted()));
ell5 = new PdfPCell(new Paragraph(admissionList.get(i).getReason()));
ell6 = new PdfPCell(new Paragraph(admissionList.get(i).getDateDischarged()));
table.setSpacingBefore(30f);
table.addCell(cell1);
table.addCell(cell2);
table.addCell(cell3);
table.addCell(cell4);
table.addCell(cell5);
table.addCell(cell6);
table.addCell(ell1);
table.addCell(ell2);
table.addCell(ell3);
table.addCell(ell4);
table.addCell(ell5);
table.addCell(ell6);
}
document.add(table);
document.add(pp);
PdfPTable table2 = new PdfPTable(2);
table2.setHorizontalAlignment(Element.ALIGN_LEFT);
table2.setWidthPercentage(50);
PdfPCell cell01 = new PdfPCell();
cell01.addElement(p01);
PdfPCell cell02 = new PdfPCell();
cell02.addElement(p02);
ArrayList<ChangeBed> bedList = new ArrayList<ChangeBed>();
bedList = cbc.processGetBedsEdit(textFieldPatientID.getText());
PdfPCell ell01;
PdfPCell ell02;
for (int i = 0; i < bedList.size(); i++) {
ell01 = new PdfPCell(new Paragraph(bedList.get(i).getBedID()));
ell02 = new PdfPCell(new Paragraph(bedList.get(i).getDepartment()));
table2.setSpacingBefore(30f);
table2.addCell(cell01);
table2.addCell(cell02);
table2.addCell(ell01);
table2.addCell(ell02);
}
document.add(table2);
document.close();
JOptionPane.showMessageDialog(null, "Admission PDF has been successfully created.");
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Error: " + ex);
}
}
});
btnAssignBed.setBounds(288, 303, 116, 25);
contentPane.add(btnAssignBed);
comboBoxDpt = new JComboBox();
comboBoxDpt.setModel(new DefaultComboBoxModel(new String[] {"--Select Department--", "Cardiothoracic", "Oncology", "Orthopaedic", "Pediatric"}));
comboBoxDpt.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String departmentSelection = comboBoxDpt.getSelectedItem().toString();
ChangeBedControl cbcS = new ChangeBedControl();
ArrayList<ChangeBed> bedList = new ArrayList<ChangeBed>();
bedList = cbcS.processGetAvailBedsEdit(bedStatusF, departmentSelection);
comboBoxAllocateBed.removeAllItems();
for (int i = 0; i < bedList.size(); i++) {
comboBoxAllocateBed.addItem(bedList.get(i).getBedID());
}
}
});
comboBoxDpt.setBounds(62, 256, 153, 22);
contentPane.add(comboBoxDpt);
rdbtnCardiothoracic = new JRadioButton("Cardiothoracic");
rdbtnCardiothoracic.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String departmentSelection = "Cardiothoracic";
ChangeBedControl cbcS = new ChangeBedControl();
ArrayList<ChangeBed> bedList = new ArrayList<ChangeBed>();
bedList = cbcS.processGetAvailBedsEdit(bedStatusF, departmentSelection);
comboBoxAllocateBed.removeAllItems();
for (int i = 0; i < bedList.size(); i++) {
comboBoxAllocateBed.addItem(bedList.get(i).getBedID());
}
}
});
department.add(rdbtnCardiothoracic);
rdbtnCardiothoracic.setBounds(138, 138, 111, 25);
rdbtnCardiothoracic.setForeground(colour);
contentPane.add(rdbtnCardiothoracic);
rdbtnOncology = new JRadioButton("Oncology");
rdbtnOncology.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String departmentSelection = "Oncology";
ChangeBedControl cbcS = new ChangeBedControl();
ArrayList<ChangeBed> bedList = new ArrayList<ChangeBed>();
bedList = cbcS.processGetAvailBedsEdit(bedStatusF, departmentSelection);
comboBoxAllocateBed.removeAllItems();
for (int i = 0; i < bedList.size(); i++) {
comboBoxAllocateBed.addItem(bedList.get(i).getBedID());
}
}
});
department.add(rdbtnOncology);
rdbtnOncology.setBounds(253, 138, 81, 25);
rdbtnOncology.setForeground(colour);
contentPane.add(rdbtnOncology);
rdbtnOrthopaedic = new JRadioButton("Orthopaedic");
rdbtnOrthopaedic.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String departmentSelection = "Orthopaedic";
ChangeBedControl cbcS = new ChangeBedControl();
ArrayList<ChangeBed> bedList = new ArrayList<ChangeBed>();
bedList = cbcS.processGetAvailBedsEdit(bedStatusF, departmentSelection);
comboBoxAllocateBed.removeAllItems();
for (int i = 0; i < bedList.size(); i++) {
comboBoxAllocateBed.addItem(bedList.get(i).getBedID());
}
}
});
department.add(rdbtnOrthopaedic);
rdbtnOrthopaedic.setBounds(229, 179, 127, 25);
rdbtnOrthopaedic.setForeground(colour);
contentPane.add(rdbtnOrthopaedic);
rdbtnPediatric = new JRadioButton("Pediatric");
rdbtnPediatric.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String departmentSelection = "Pediatric";
ChangeBedControl cbcS = new ChangeBedControl();
ArrayList<ChangeBed> bedList = new ArrayList<ChangeBed>();
bedList = cbcS.processGetAvailBedsEdit(bedStatusF, departmentSelection);
comboBoxAllocateBed.removeAllItems();
for (int i = 0; i < bedList.size(); i++) {
comboBoxAllocateBed.addItem(bedList.get(i).getBedID());
}
}
});
department.add(rdbtnPediatric);
rdbtnPediatric.setBounds(229, 219, 81, 25);
rdbtnPediatric.setForeground(colour);
contentPane.add(rdbtnPediatric);
/*comboBoxDpt = new JComboBox(departments);
ComboBoxRenderer renderer = new ComboBoxRenderer(comboBoxDpt);
renderer.setColorsForMain(colorsForMain);
renderer.setDepartments(departments);
comboBoxDpt.setRenderer(renderer);*/
ChangeBedControl cbc = new ChangeBedControl();
ArrayList<AdmissionInfo> admissionList = new ArrayList<AdmissionInfo>();
admissionList = cbc.processGetChangeBedCreate(val1, val2);
for (int i = 0; i < admissionList.size(); i++) {
textFieldPatientID.setText(admissionList.get(i).getPatientID());
textFieldPatientName.setText(admissionList.get(i).getPatientName());
}
//=============Distinct Feature=============
ArrayList<ChangeBed> bedList = new ArrayList<ChangeBed>();
/*int selectedIndex = comboBoxDpt.getSelectedIndex() ;
String departmentComboBox;*/
ChangeBedControl cbc2 = new ChangeBedControl();
bedList = cbc2.processCountBedsAvailableDpt1();
for (int i = 0; i < bedList.size(); i++) {
bedsAvailCardio = bedList.get(i).getRowCountAvail();
}
if (bedsAvailCardio <= 3) {
rdbtnCardiothoracic.setForeground(Color.RED);
}
ChangeBedControl cbc4 = new ChangeBedControl();
bedList = cbc4.processCountBedsAvailableDpt2();
for (int i = 0; i < bedList.size(); i++) {
bedsAvailOncology = bedList.get(i).getRowCountAvail();
}
if (bedsAvailOncology <= 3) {
rdbtnOncology.setForeground(Color.RED);
}
ChangeBedControl cbc6 = new ChangeBedControl();
bedList = cbc6.processCountBedsAvailableDpt3();
for (int i = 0; i < bedList.size(); i++) {
bedsAvailOrtho = bedList.get(i).getRowCountAvail();
}
if (bedsAvailOrtho <= 3) {
rdbtnOrthopaedic.setForeground(Color.RED);
}
ChangeBedControl cbc8 = new ChangeBedControl();
bedList = cbc8.processCountBedsAvailableDpt4();
for (int i = 0; i < bedList.size(); i++) {
bedsAvailPediatric = bedList.get(i).getRowCountAvail();
}
if (bedsAvailPediatric <= 3) {
rdbtnPediatric.setForeground(Color.RED);
//Show a text "bed count low."
}
}
}