i need a java program. please help please! the code needed is here: public stati
ID: 656414 • Letter: I
Question
i need a java program. please help please!
the code needed is here:
public static void main(String[] args) {
// create and style a frame
Converter frame = new Converter();
frame.setTitle("Meters / Feet Converter");
frame.setSize(325,225);
frame.setLocation(100, 100);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
} // end main
public class Converter extends JFrame {
// default constructor
public Converter() {
// create 2 panels
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
// set layouts for the 2 panels
p1.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 10));
p2.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 10));
// ******************* p1 *******************
// create label, textfield, & button components
JLabel lblMetersToFeet = new JLabel("Enter a distance in meters: ");
JTextField txtMetersToFeet = new JTextField(10);
JButton btnMetersToFeet = new JButton("Convert to Feet");
// style the components
p1.setBackground(new Color(255,255,224));
lblMetersToFeet.setForeground(new Color(0,0,128));
btnMetersToFeet.setBackground(new Color(0,0,128));
btnMetersToFeet.setForeground(Color.WHITE);
btnMetersToFeet.setMnemonic('f');
// add components to p1 panel
p1.add(lblMetersToFeet);
p1.add(txtMetersToFeet);
p1.add(btnMetersToFeet);
// ******************* p2 *******************
// create label, textfield, & button components
JLabel lblFeetToMeters = new JLabel("Enter a distance in feet: ");
JTextField txtFeetToMeters = new JTextField(10);
JButton btnFeetToMeters = new JButton("Convert to Meters");
// style the components
p2.setBackground(new Color(250,240,230));
lblFeetToMeters.setForeground(new Color(128,0,0));
btnFeetToMeters.setBackground(new Color(128,0,0));
btnFeetToMeters.setForeground(Color.WHITE);
btnFeetToMeters.setMnemonic('m');
// add components to p2 panel
p2.add(lblFeetToMeters);
p2.add(txtFeetToMeters);
p2.add(btnFeetToMeters);
// set frame layout & add both panels
setLayout(new GridLayout(2, 1, 5, 5));
add(p1);
add(p2);
} // end default constructor
} // end class
Create a GUI program to convert meters to feet and feet to meters. As a beginning point, you may use either the GUI you created for Lab 05 or the program included below (note that imported Java classes are not included). Use the following formulas to calculate the conversions: meters = 0.305 * feet feet = (1 / 0.305) * meter When the user enters the distance either in meters or in feet, the results should be displayed in a dialog box. When the dialog box is closed, the user input should be cleared from the text field. For 4 points extra credit, in addition to displaying results in a dialog box, also write the results to a file of the user's choice using JFileChooser. Be sure to use the try/catch structure if you need to handle errors.Explanation / Answer
See and follow the program below.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.