Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are required to make a car registration form. You will takethe values from t

ID: 3618813 • Letter: Y

Question

You are required to make a car registration form. You will takethe values from the user and same these into a text file“Car.txt”.

First your program will display a GUI form. As shownbelow    

Then user will enter the information related to his car.

Then user will click save, and the data will be saved totext file named “Car.txt”

Note1: You can use null layout and the place labels and textfields accordingly.

Note2: No need to worry if you are unable to make the GUIof the form 100% according to the about figure. But all theelements should be there.

Explanation / Answer

import java.awt.*; import java.awt.event.ActionEvent; import java.io.File; import java.io.FileWriter; import java.io.IOException; import javax.swing.*; public class CRegistration {     private static JTextField eNumberTxt ;     private static   JTextField modelTxt;     private static   JTextField makerTxt;     private static   JTextFieldownerTxt;     private static void createAndShowGUI() {         //Create and set up thewindow.         JFrame frame = newJFrame("Car Regtistration");        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        JFrame.setDefaultLookAndFeelDecorated(true);                 //textfields andlabels          eNumberTxt = newJTextField();          modelTxt = newJTextField();          makerTxt = newJTextField();          ownerTxt = newJTextField();         JLabel eNumberLabel =new JLabel("Engine Number");         JLabel modelLabel = newJLabel("Model");         JLabel makerLabel = newJLabel("Maker");         JLabel ownerLabel = newJLabel("Owner");         JButton saveButton = newJButton("Save");         Container contentPane =frame.getContentPane();        contentPane.setLayout(new GridLayout(5,2,5,5));        frame.add(eNumberLabel);        frame.add(eNumberTxt);        frame.add(modelLabel);         frame.add(modelTxt);        frame.add(makerLabel);         frame.add(makerTxt);        frame.add(ownerLabel);         frame.add(ownerTxt);        frame.add(saveButton);        saveButton.addActionListener(new java.awt.event.ActionListener(){            public void actionPerformed(java.awt.event.ActionEvent evt) {                try{                    saveButtonActionPerformed(evt);                }catch(Exception e){                   e.printStackTrace();                }            }            private void saveButtonActionPerformed(ActionEvent evt) throwsIOException{            File f = new File("C:/File.txt");            // FileOutputStream fos = new FileOutputStream(f);            FileWriter fw = new FileWriter(f);            String datawrite = "Engine Number : " + eNumberTxt.getText() +                               " Model        : " +modelTxt.getText() +                               " Maker         : " +makerTxt.getText() +                               " Owner         : " +ownerTxt.getText() ;            for (int i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote