0

I'm trying to practice a little with Java, and creating something like a calculator for forming verbs in Hebrew. My Exception doesn't work , doesn't matter what I add there, I want to have error message if the first button was pressed and the JTextField is empty. What should I add in catch as an exception? I'm still a very beginner and I teach myself Java, so I don't know about the JFormatted text field and I don't know how to use it, I would appreciate your help to modify my code.

Thank you in advance

Here is my code

import java.awt.*;

public class Grid extends JFrame {

public static void main (String args[]) {
    Grid frame = new Grid();
    frame.setVisible(true);
    frame.setLocationRelativeTo(null);
    frame.setSize(400, 200);
    frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
    frame.setResizable(false);
}

public Grid() {
    setLayout(new GridLayout(4,2));
    JLabel FirstLetter = new JLabel("First Letter");
    final JTextField fl = new JTextField();
    fl.setHorizontalAlignment(SwingConstants.CENTER);
    fl.setFont(new Font("David", Font.PLAIN, 24));
    JLabel SecondLetter = new JLabel("Second Letter");
    final JTextField sl = new JTextField();
    sl.setHorizontalAlignment(SwingConstants.CENTER);
    sl.setFont(new Font("David", Font.PLAIN, 24));
    JLabel ThirdLetter = new JLabel("Second Letter");
    final JTextField tl = new JTextField();
    tl.setHorizontalAlignment(SwingConstants.CENTER);
    tl.setFont(new Font("David", Font.PLAIN, 24));
    JButton btn = new JButton ("Click Here");
    final JTextField ans = new JTextField();
    ans.setEditable(false);
    ans.setHorizontalAlignment(SwingConstants.CENTER);
    ans.setFont(new Font("David", Font.PLAIN, 24));

    add(FirstLetter);
    add(fl);
    add(SecondLetter);
    add(sl);
    add(ThirdLetter);
    add(tl);
    add(btn);
    add(ans);

    btn.addActionListener(new ActionListener() {
        public void actionPerformed (ActionEvent e) {
            String getfl, getsl, gettl;
            String kmts, bth,shva,chereq,dagesh,pastEnding;
            kmts = "ָ";
            bth = "ַ";
            shva = "ְ";
            chereq = "ִ";
            dagesh = "ּ";
            pastEnding = "תִּי";
            String conc, conc1,conc2,conc3;

            try {
                getfl = fl.getText(); // Getting the first letter entered by the user
                getsl = sl.getText(); // Getting the second letter entered by the user
                gettl = tl.getText(); // Getting the third letter entered by the user
                conc = getfl.concat(kmts.concat(dagesh)); // adding kmts and dagest to the first letter
                conc1 = getsl.concat(bth); // adding bth to the second letter
                conc2 = conc.concat(conc1.concat(gettl)); // adding third letter to first and second letters.
                conc3 = conc2.concat(pastEnding);
                ans.setText(conc3); // to show the result
            } catch (Exception e1) {

            }
        }
    });

}

}

0 Answers0