Intro to Java Programming Help!

4 Methods for a Metric Converter

Page 1 of 1

2 Replies - 1236 Views - Last Post: 20 February 2007 - 07:48 AM Rate Topic: -----

#1 zulu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 14-February 07

Intro to Java Programming Help!

Posted 14 February 2007 - 06:15 PM

Any help would be appreciated!

* I have to create a GUI class based on JFrame called Assn3.
* Assn4 (My program) should do the following
o be based on a NULL layout
o has 2 JTextFields, one named inputField, the another outputField,
o has a JLabel beside each JTextField holding the names of the fields for the user
o Buttons
+ Clear - empties each JTextField ( hint use setText("") ; )***DONE***
+ Feet to Meters - converts the value in the input field (feet) to meters and displays in the output field. Calls the method ConvertFeetToMeters.
+ Fahrenheit, to Celsius converts the value in the input field (degrees fahrenheit) to degrees celsius and displays in the output field. Calls the method ConvertFarenheitToCelsius
+ Miles to Kilometers, converts the value in the input field (miles) to kilometers and displays in the output field. Calls the method ConvertMilesToKilometers
+ Mach to Miles per hour.
+ Exit - exits the program***DONE***
o Methods
+ convertFeetToMeters, this method should accept one double value as input and return a double value. meters = .305 * feet
+ convertFahrenheitToCelsius, this method should accept one double value as input and return a double value. celsius = (fahrenheit - 32)*5/9.0
+ convertMilesToKilometers, this method should accept one double value as input and return a double value. kilometers = 1.609*miles
+ convertMachToMPH, this method should accept one double value as input and return a double value. mph = mach*770.

/*
 * Assn4.java
 *
 * Created on February 14, 2007, 6:42 PM
 */

/**
 *
 * @author  Kruger
 */
 import javax.swing.*;
public class Assn4 extends javax.swing.JFrame {
	
	/** Creates new form Assn4 */
	public Assn4() {
		initComponents();
		setSize (600,600);
		setTitle("Assn4");
	}
	
	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
	private void initComponents() {
		inputField = new javax.swing.JTextField();
		outputField = new javax.swing.JTextField();
		jLabel1 = new javax.swing.JLabel();
		jLabel2 = new javax.swing.JLabel();
		clearButton = new javax.swing.JButton();
		exitButton = new javax.swing.JButton();
		feettometersButton = new javax.swing.JButton();
		fahrenheittocelciusButton = new javax.swing.JButton();
		milestokilometersButton = new javax.swing.JButton();
		machtomphButton = new javax.swing.JButton();

		getContentPane().setLayout(null);

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		setBackground(new java.awt.Color(255, 255, 102));
		setForeground(new java.awt.Color(255, 0, 0));
		getContentPane().add(inputField);
		inputField.setBounds(170, 20, 140, 30);

		getContentPane().add(outputField);
		outputField.setBounds(160, 240, 160, 120);

		jLabel1.setText("inputField");
		getContentPane().add(jLabel1);
		jLabel1.setBounds(70, 20, 70, 30);

		jLabel2.setText("outputField");
		getContentPane().add(jLabel2);
		jLabel2.setBounds(80, 280, 80, 40);

		clearButton.setText("Clear");
		clearButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				clearButtonActionPerformed(evt);
			}
		});

		getContentPane().add(clearButton);
		clearButton.setBounds(60, 380, 90, 30);

		exitButton.setText("EXIT");
		exitButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				exitButtonActionPerformed(evt);
			}
		});

		getContentPane().add(exitButton);
		exitButton.setBounds(330, 380, 55, 30);

		feettometersButton.setText("Feet to Meters");
		feettometersButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				feettometersButtonActionPerformed(evt);
			}
		});

		getContentPane().add(feettometersButton);
		feettometersButton.setBounds(10, 60, 150, 30);

		fahrenheittocelciusButton.setText("Fahrenheit to Celcius");
		getContentPane().add(fahrenheittocelciusButton);
		fahrenheittocelciusButton.setBounds(10, 100, 150, 30);

		milestokilometersButton.setText("Miles to Kilometers");
		getContentPane().add(milestokilometersButton);
		milestokilometersButton.setBounds(10, 140, 150, 30);

		machtomphButton.setText("Mach to Miles p / Hour");
		getContentPane().add(machtomphButton);
		machtomphButton.setBounds(10, 180, 150, 30);

		pack();
	}// </editor-fold>

	private void feettometersButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
		String amountstring = inputField.getText();
		double amount = Double.parseDouble(amountstring);
		double answer = amount * Math.pow(1 + yearlyinterestrate,numberofyears); 
		outputField.setText(""+answer);
	}

	private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
		System.exit(0);
		
	}

	private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
		inputField.setText("");
		outputField.setText("");
			  
	}
	
	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new Assn4().setVisible(true);
			}
		});
	}
	
	// Variables declaration - do not modify
	private javax.swing.JButton clearButton;
	private javax.swing.JButton exitButton;
	private javax.swing.JButton fahrenheittocelciusButton;
	private javax.swing.JButton feettometersButton;
	private javax.swing.JTextField inputField;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JButton machtomphButton;
	private javax.swing.JButton milestokilometersButton;
	private javax.swing.JTextField outputField;
	// End of variables declaration
	
}



I am new to Java, so I need a lot of "fill in the blanks" help please.

Thank you
dkruger@eagle.fgcu.edu

Is This A Good Question/Topic? 0
  • +

Replies To: Intro to Java Programming Help!

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Intro to Java Programming Help!

Posted 14 February 2007 - 06:27 PM

What specifically is giving you difficulty?
Was This Post Helpful? 0
  • +
  • -

#3 zulu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 14-February 07

Re: Intro to Java Programming Help!

Posted 20 February 2007 - 07:48 AM

View PostAmadeus, on 14 Feb, 2007 - 06:27 PM, said:

What specifically is giving you difficulty?

Thanks-Figured it out.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1