-
Notifications
You must be signed in to change notification settings - Fork 0
/
assignmentNine.java
115 lines (110 loc) · 5.51 KB
/
assignmentNine.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
* Assignment - question nine. Blood Type App
*
* @author (Jack Churchill)
* @version (Version 1 - 05/02/18)
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class BloodTypeApp extends JFrame
{
public BloodTypeApp()// constructor
{
BloodTypeDecesion();
}
public void BloodTypeDecesion()// method
{
// setting title for the JFrame
setTitle ("Blood Type Application");
// setting container so it is visable
setVisible(true);
// setting the size of the container
setBounds(10, 80, 440, 200);
// make sure the programs closes if container closes
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// set container so the user is unable to resize it
setResizable(false);
setLocationRelativeTo(null);
// Create and define new panel and its variable
JPanel mainPanel = new JPanel();
// setting layout for panel
mainPanel.setLayout(null);
// setting background colour for panel
mainPanel.setBackground(new Color(142, 164, 237));
// assigning font variable for first and second label
Font mylabelFont = new Font("Serif", Font.BOLD, 12);
// setting font size
Font newFont = mylabelFont.deriveFont(16F);
// Create and define third label and its variable
JLabel firstLabel = new JLabel("Select your blood type from the drop down.");
// setting the position for the first label
firstLabel.setBounds(30, 8,290, 50);
// assigning font variable to third label text
firstLabel.setFont(newFont);
// Create and define third label and its variable
JLabel secondLabel = new JLabel("The compatible blood will display below. ");
// setting the position for the second label
secondLabel.setBounds(30, 70,350, 20);
// assigning font variable to second label text
secondLabel.setFont(newFont);
// Create and define third label and its variable
JLabel thirdLabel = new JLabel();
// setting the position for the third label
thirdLabel.setBounds(30, 100,500, 30);
// assigning font variable for third label
Font myfinalFont = new Font("Serif", Font.ITALIC | Font.BOLD, 12);
// setting font size
Font newNowFont = myfinalFont.deriveFont(25F);
// assigning font variable to third label text
thirdLabel.setFont(newNowFont);
// setting foreground colour for third label
thirdLabel.setForeground(new Color(132, 10, 16));
// creatig array for bloodtype choices
String[] comboBoxArrayForBloodTypes = { "", "O-", "O+", "A-", "A+", "B-", "B+", "AB-", "AB+"};
// creating combobox and inseting array variable
JComboBox bloodTypeScroll = new JComboBox(comboBoxArrayForBloodTypes);
// setting the position for the combobox
bloodTypeScroll.setBounds(310, 62, 100, 35);
//adding actionlistener for combobox
bloodTypeScroll.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
// initialising logic if the combo box reaches a certain condition
// if a certain attribute is selected from the combobox, the corresponding matched blood type is printed
if (bloodTypeScroll.getSelectedItem().toString().equals(comboBoxArrayForBloodTypes[0]))
thirdLabel.setText(" ");
else if (bloodTypeScroll.getSelectedItem().toString().equals(comboBoxArrayForBloodTypes[1]))
thirdLabel.setText("O- ");
else if (bloodTypeScroll.getSelectedItem().toString().equals(comboBoxArrayForBloodTypes[2]))
thirdLabel.setText("O-, O+");
else if (bloodTypeScroll.getSelectedItem().toString().equals(comboBoxArrayForBloodTypes[3]))
thirdLabel.setText("O-, A-");
else if (bloodTypeScroll.getSelectedItem().toString().equals(comboBoxArrayForBloodTypes[4]))
thirdLabel.setText("O-, O+, A-, A+ ");
else if (bloodTypeScroll.getSelectedItem().toString().equals(comboBoxArrayForBloodTypes[5]))
thirdLabel.setText("O-, B-");
else if (bloodTypeScroll.getSelectedItem().toString().equals(comboBoxArrayForBloodTypes[6]))
thirdLabel.setText("O-, O+, B-, B+");
else if (bloodTypeScroll.getSelectedItem().toString().equals(comboBoxArrayForBloodTypes[7]))
thirdLabel.setText("O-, A-, B-, AB-");
else if (bloodTypeScroll.getSelectedItem().toString().equals(comboBoxArrayForBloodTypes[8]))
thirdLabel.setText(" O-, O+, A-, A+, B-, B+, AB-, AB+");
}
});
// Connecting the first label feature to the main panel.
mainPanel.add(firstLabel);
// Connecting the second label feature to the main panel.
mainPanel.add(secondLabel);
// Connecting the combobox feature to the main panel.
mainPanel.add(bloodTypeScroll);
// Connecting the third label feature to the main panel.
mainPanel.add(thirdLabel);
// Connecting the main panel feature to the container.
add(mainPanel);
}
// initiating the main method, of which runs the programs
public static void main(String [] args){
new BloodTypeApp();
}
}