I've been trying to separate my button functions from my main GUI class The code works but as an programming beginner i want to hear if i'm doing things the 'proper' way. Point out what am i doing properly and what not. Thanks in advance.
Frame class:
GuiFrame() {
setTitle("Aplikacija (bez imena) v1.0.1");
setSize(800, 600);
setLocationRelativeTo(null);
setContentPane(new GuiPanel());
setDefaultCloseOperation(EXIT_ON_CLOSE);
setResizable(false);
setLocationRelativeTo(null);
setVisible(true);
}
GUI main Panel class :
JLabel title = new JLabel("Aplikacija za dijagnozu bolesti");
JLabel diagnose = new JLabel("Preliminarna dijagnoza : ");
private final String[] listS1 = {"-Odaberi-", "Akutni", "Hronicni"};
JComboBox comboS1 = new JComboBox();
private int counterS1 = 0;
private final String[] listS2 = {"-Odaberi-", "Abdomen", "Udovi", "Glava"};
JComboBox comboS2 = new JComboBox();
private int counterS2 = 0;
private final ComboBoxModel[] models = new ComboBoxModel[5];
private final JComboBox comboS3 = new JComboBox();
JLabel simptom1 = new JLabel("Vrsta bola koju osecate : ");
JLabel simptom2 = new JLabel("U kom delu tela osecate taj bol :");
JLabel simptom3 = new JLabel("Vas bol osecate u (vidi sliku) : ");
public final ImageIcon rep = new ImageIcon(getClass().getResource("/images/rsz_flag_of_the_red_cross.png"));
public final ImageIcon rep2 = new ImageIcon(getClass().getResource("/images/rsz_s13.jpg"));
JLabel picture01 = new JLabel(rep);
JLabel picture02 = new JLabel(rep2);
JTextField diagnoseField = new JTextField();
Font font = new Font("Times new Roman", Font.BOLD, 14);
JButton reset = new JButton();
JButton calculate = new JButton();
public GuiPanel() {
setLayout(null);
models[0] = new DefaultComboBoxModel(new String[]{"-Odaberi-"});
models[1] = new DefaultComboBoxModel(new String[]{"-Odaberi-", "1", "2", "3", "4", "5", "6", "7", "8", "9"});
title.setBounds(90, 40, 200, 100);
title.setFont(font);
add(title);
picture01.setBounds(400, 40, 350, 400);
add(picture01);
picture02.setBounds(400, 40, 350, 400);
picture02.setVisible(false);
add(picture02);
simptom1.setBounds(10, 100, 200, 100);
add(simptom1);
simptom2.setBounds(10, 200, 200, 100);
add(simptom2);
simptom3.setBounds(10, 300, 200, 100);
add(simptom3);
comboS1.setBounds(245, 135, 90, 30);
for (int i = 0; i < 3; i++) {
comboS1.addItem(listS1[counterS1++]);
}
add(comboS1);
comboS2.setBounds(245, 235, 90, 30);
for (int i = 0; i < 4; i++) {
comboS2.addItem(listS2[counterS2++]);
}
add(comboS2);
comboS3.setBounds(245, 335, 90, 30);
comboS3.setModel(models[0]);
comboS3.disable();
add(comboS3);
diagnose.setBounds(10, 420, 200, 100);
add(diagnose);
diagnoseField.setBounds(10, 490, 350, 30);
diagnoseField.setEditable(false);
add(diagnoseField);
reset.setText("Ponovo");
reset.setBounds(640, 470, 110, 50);
add(reset);
calculate.setText("Dijagnoza");
calculate.setBounds(400, 470, 110, 50);
calculate.addActionListener(comboS1);
add(calculate);
CalculateButton c = new CalculateButton(calculate, comboS1, comboS2, comboS3, diagnoseField);
AgainButton a = new AgainButton(reset, comboS1, comboS2, comboS3, diagnoseField, picture01);
again();
whenAkutniAbdomen();
//diagnose();
}
The Calculate button class
public class CalculateButton implements ActionListener {
private final JComboBox comboS1;
private final JComboBox comboS2;
private final JComboBox comboS3;
private final JTextField diagnoseField;
public CalculateButton(JButton calculate, JComboBox comboS1, JComboBox comboS2, JComboBox comboS3, JTextField diagnoseField) {
this.comboS1 = comboS1;
this.comboS2 = comboS2;
this.comboS3 = comboS3;
this.diagnoseField = diagnoseField;
calculate.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
if (comboS1.getSelectedIndex() == 1 && comboS2.getSelectedIndex() == 1 && comboS3.getSelectedIndex() == 1) {
diagnoseField.setText("Rak na pluca");
}
}
}
The second AgainButton class is the same as the calculate class. Only the code which is in "" is in my native language and should be viewed as plain strings, everything else should be understandable.
guipanel extends JPanel
andGuiFrame extends JFrame
\$\endgroup\$