-4

I am new to Java I created a conversion software for metric units and now I want to create new window for logging the output of converted units from one Window text areas into one text area in another window Picture of the application Both Windows are one application

What code would I need to put in there to display this in another window text area

JButton btnConvert = new JButton("Convert");
    btnConvert.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            double numCM,sumCM;
            double numKM,sumKM;
            double numMIL,sumMIL;

            try {

                //startCM//
                numCM = Double.parseDouble(textFieldenter.getText());
                sumCM = numCM*100;
                textFieldcm.setText(Double.toString(sumCM));

                //endCM//

                //startKILOMETERS//
                numKM = Double.parseDouble(textFieldenter.getText());
                sumKM = numKM*0.001;
                textFieldkm.setText(Double.toString(sumKM));
                //endKILOMETERS//

                //startMILES//
                numMIL = Double.parseDouble(textFieldenter.getText());
                sumMIL = numMIL*0.000621;
                textFieldmil.setText(Double.toString(sumMIL));
                //endMILES//


            }

            catch (Exception e1) {

                JOptionPane.showInternalMessageDialog(btnConvert, "Value etered is incorrect");

            }


        }
    });

1 Answers1

0

You can use the method JTextField.getText() over your JTextFields and store its value into a String variable, then pass it to the JTextArea using the method append(String str) and put a line break at the end with /n

Read the API for these classes to learn more about its methods and how to use them Java API

It would be something like this

String record = "";

record = textFieldcm.getText()+" "+textFieldkm.getText()+" "+textFieldmil.getText();

JTextArea.append(record+"\n");
Daniel
  • 1
  • 4