wind angle correction calculator help
I need help trying create an interface for the wind angle correction calculator I know what im doing wrong but I just cant seem fix it, I already emailed my prof but he hasnt even reply and it's been 2 days already. Yes, its a homework problem but it seems difficult.
Also where it says "E6B e6b = new E6B( int dc, int vt, int wd, int vw);" thats the problem and the error is "error: '.class' expected. Do I just add something like public class or something? One more thing, anything with the // that I havent filled out yet, any hints on what I should do?
Here is what I've already did so far:
import java.awt.*; // specifies how components are arranged
import javax.swing.*;
import java.awt.event.*;
public class E6BComputer extends JFrame implements ActionListener
{
private JLabel slblDC, slblWD, slblVT, slblVW, slblDA, lblDeltaA;
private JButton btnCalcDeltaA;
private JTextField tfDC, tfWD, tfVT, tfVW;
public E6BComputer()
{
super( "E6B Computer Wind Correction" );
setLayout( new GridLayout(5,2) ); // set frame layout
slblDC = new JLabel("desired course");
add( slblDC );
tfDC = new JTextField("0");
add( tfDC );
slblDA = new JLabel("delta a");
add( slblDA );
lblDeltaA = new JLabel("0");
add(lblDeltaA);
// Create remaining labels and textfields
slblDC = new JLabel("desired course");
add( slblDC );
tfDC = new JTextField("0");
add( tfDC );
slblWD = new JLabel("Wind Direction");
add( slblWD );
tfWD = new JTextField("0");
add(tfWD);
// Create JButton
btnCalcDeltaA = new JButton("Get Angle");
add( btnCalcDeltaA );
// add action listener to JButton
btnCalcDeltaA.addActionListener( this );
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
setSize( 275, 400 ); // set frame size
setVisible( true );
}
public void actionPerformed(ActionEvent e)
{
int dc = Integer.parseInt(tfDC.getText() );
int wd = 0;
int vt = 0;
int vw = 0;
// instantiate the e6b model, send it the info from the text fields
// public E6B (int dc, int vt, int wd, int vw)
E6B e6b = new E6B( int dc, int vt, int wd, int vw);
// get the wind correction angle
// public int deltaA()
int da = e6b.deltaA();
// put it in the wind correction label
lblDeltaA.setText( Intege.toString( da ) );
}
public static void main(String[] args)
{
E6BComputer e6bView = new E6BComputer();
}
}
Re: wind angle correction calculator help
yes, create a class E6B in another file called E6B.class. Put both files in the same directory.
Also, what IDE are you working with, i.e. Netbeans, Eclipse or etc. I'm working with Netbeans and I find it very easy to use - much easier than Eclipse.
If you want the program to just display the window for now, comment out all code in the actionPerformed function.
Re: wind angle correction calculator help
The Netbean IDE is located at http://netbeans.org/downloads/index.html. Just download the one under the "all" column.
You'll be able to automatically format your code using alt-shift-f and the IDE will put little light bulbs next to the lines that have problems. right clicking on the lightbulbs will "most of the time" give you the option to auto-correct the problem. I'm pretty impressed with the IDE.
Re: wind angle correction calculator help
Quote:
Originally Posted by
shall
yes, create a class E6B in another file called E6B.class. Put both files in the same directory.
Also, what IDE are you working with, i.e. Netbeans, Eclipse or etc. I'm working with Netbeans and I find it very easy to use - much easier than Eclipse.
If you want the program to just display the window for now, comment out all code in the actionPerformed function.
I use jGRASP cuz my prof recommend me to use it but I'll try to use Netbeans and see how that goes.
Re: wind angle correction calculator help
Interesting IDE - it lets you do UML diagram and access your code from the diagram. Reminds me of Rational Rose. I'll try it sometime.
Did you create the class yet?
Re: wind angle correction calculator help
class as in the E6B.class, then yes I created it but it seems to compiled it correctly (I think) but from my previous code above Im still getting the same error.
Here's the E6B.class:
public class E6B
{
private double desiredCourse; // degrees
private double vTrue; // true airspeed in knots
private double windDirection; // degrees
private double vWind; // knots
public E6B()
{
desiredCourse=0;
vTrue=0;
windDirection=0;
vWind=0;
}
public E6B( int dc, int vt, int wd, int vw )
{
desiredCourse=dc;
vTrue=vt;
windDirection=wd;
vWind=vw;
}
//
//
//
public int deltaA()
{
return (int) (180/Math.PI * Math.asin( (vWind/vTrue) *
Math.sin((Math.PI * (windDirection - desiredCourse))/180)));
}
public static void main(String[] args)
{
// E6B( int dc, int vt, int wd, int vw )
E6B e6b = new E6B(0, 110, 270, 20);
System.out.println( e6b.deltaA() );
}
}
Re: wind angle correction calculator help
Did you put the EB6 class into a separate file? The E6BComputer class will have the main function and the file that contains the E6B class won't.
You'll have the correct Intege.toString( da ) to Integer.toString(da).
Re: wind angle correction calculator help
Yes, I've put the E6B class in a different file, saved as E6B.Java while E6BComputer class is E6BComputer.java. Sorry Im just a bit confused and lost.
Re: wind angle correction calculator help
In post #6, I noticed main was in the E6B class. You can only have one main. Probably keep main in the E6BComputer class and create the E6B and E6BComputer object in that class.
Re: wind angle correction calculator help
Quote:
Originally Posted by
shall
You can only have one main.
Wrong.
db
Re: wind angle correction calculator help
Quote:
Originally Posted by
DarrylBurke
Wrong.
db
I was wrong.
But as stated at Using Multiple Main Classes, the situation of using multiple mains in not usual in stadard Java applications:
Quote:
Multiple Main Classes
NetBeans projects can have more than one main class and it's easy to specify the main class an application should run. This allows a programmer to switch between any number of main classes within the same application. Only the code in one of the main classes will be executed, effectively making each class independent of each other.
Note: This is not usual in a standard Java application. All it needs is one main class as a starting point for the execution of the code. Remember this is a tip for running multiple code examples within one project.