Best writers. Best papers. Let professionals take care of your academic papers

Order a similar paper and get 15% discount on your first order with us
Use the following coupon "FIRST15"
ORDER NOW

Hello,I am working on a program that calculates million

Hello,<br/><br/><br/>I am working on a program that calculates million

gallons per day to gallons per minute. I am trying to center my title and description in the GUI, but they end up on the left. Also, for some reason it does not want to calculate anymore. Any help would be appreciated.

package waterflow; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.DecimalFormat; public class WaterCalGUI extends JFrame implements ActionListener { private JTextField mgdInput = new JTextField(); private JTextArea gpmOutput = new JTextArea(); private JButton conversionButton = new JButton(“Convert”); private JButton clearFormButton = new JButton(“Clear Form”); private JLabel title = new JLabel(“MGD to GPM”); private JLabel description = new JLabel(“Convert millions of gallons per day to gallons per minute”); private double gpm; private double mgd; public WaterCalGUI(){ // Set output to not be editable and wrap lines gpmOutput.setEditable(false); gpmOutput.setWrapStyleWord(true); gpmOutput.setLineWrap(true); // Build buttons conversionButton.addActionListener(this); //Settings for JFrame this.setSize(500, 300); this.setLayout(new GridLayout(0, 1)); title.setLayout(new GridLayout(0, 1)); description.setLayout(new GridLayout(0, 1)); mgdInput.setLayout(new GridLayout(0, 1)); conversionButton.setLayout(new GridLayout(0, 1)); gpmOutput.setLayout(new GridLayout(0, 1)); this.setTitle(“Water Calculator”); this.add(title); this.add(description); this.add(mgdInput); this.add(gpmOutput); this.add(conversionButton); this.add(gpmOutput); this.setResizable(false); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLocationRelativeTo(null); } @Override public void actionPerformed(ActionEvent e) { // Decide which button the action event came from if(e.getSource().equals(clearFormButton)) { this.clearForm(); } else { // Validate input before calculating if (this.isValid(mgdInput.getText())) { double gpd = Double.parseDouble(mgdInput.getText()); double gpm = WaterCalculator.convertMGDtoGPM(mgd); // Format doubles before displaying them in the text area DecimalFormat formatter = new DecimalFormat(“###, ###.##”); String formattedGpd = formatter.format(gpd); String formattedGpm = formatter.format(gpm); // Display output gpmOutput.setText(formattedGpm + ” gallons per minute”); } } } public boolean isValid(String input) { // First check if input field is blank or empty, then if it contains commas, then check if it is numeric if(input.isBlank() || input.isEmpty()) { JOptionPane.showMessageDialog(null, “Input is required”); this.clearForm(); return false; } else if(input.contains(“,”)) { JOptionPane.showMessageDialog(null, “Input must not contain commas”); return false; } else { try{ Double.parseDouble(input); return true; } catch(NumberFormatException e) { JOptionPane.showMessageDialog(null, “Input must be numeric”); this.clearForm(); return false; } } } public void clearForm() { this.mgdInput.setText(“”); this.gpmOutput.setText(“”); mgdInput.requestFocus(); } }

package waterflow; public class WaterCalculator { public static double convertMGDtoGPM(double mgd) { double gpm = mgd * 694.44; return gpm; } }

package waterflow; import javax.swing.*; public class Main { public static void main(String[] args) { try { for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if (“Nimbus”.equals(info.getName())) { UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (Exception e) { } new WaterCalGUI(); } }

Discussion GUI Layout.PNG

Step

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"