I am working on a personal project. It is an L-Band Converter used to convert Satellite Downlink Frequencies from C or Ku-Band to a useable L-Band recognized by receivers. The formula is a simple subtraction formula used for either C-Band or Ku-Band. The problem that I am having is constructing the proper control statement using if/else to allow the user to choose which field he wants to enter the frequency into without having to enter a "0" as a placeholder in the other field in order to calculate the L-Band Frequency.
Here is my code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LBandConverter extends JFrame
{
private JTextField LBandConvertertf,cbandtf,kubandtf, lbandtf;
private JButton calculateButton, exitButton;
private JLabel LBandConverterLabel,cbandlabel,kubandlabel,lbandlabel;
int cbandconstant = 5150;
int kubandconstant = 10750;
int frequency;
// Button Handlers
private calculateButtonHandler cbhandler;
private exitButtonHandler ebhandler;
public LBandConverter()
{
setTitle("Chris' L-Band Converter");
setSize (300, 300);
cbandlabel = new JLabel ("C-BAND Frequency");
kubandlabel = new JLabel ("KU-BAND Frequency");
cbandtf = new JTextField (10);
kubandtf = new JTextField (10);
lbandtf = new JTextField (10);
//Specify Handlers For Each Button and Add Action Listeners
calculateButton = new JButton ("Calculate L-Band");
cbhandler = new calculateButtonHandler();
calculateButton.addActionListener(cbhandler);
exitButton = new JButton ("Exit");
ebhandler = new exitButtonHandler();
exitButton.addActionListener(ebhandler);
add (cbandlabel);
add (cbandtf);
add (kubandlabel);
add (kubandtf);
add (calculateButton);
add (lbandtf);
add (exitButton);
// set the layout manager
setLayout(new FlowLayout());
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private class calculateButtonHandler implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
int cbandfrequency, kubandfrequency = 0 , lbandfrequency = 0;
cbandfrequency = Integer.parseInt(cbandtf.getText());
kubandfrequency = Integer.parseInt(kubandtf.getText());
if (cbandfrequency == 0)
lbandfrequency = kubandfrequency-10750;
else if (kubandfrequency == 0)
lbandfrequency = 5150 - cbandfrequency;
lbandtf.setText("" + lbandfrequency);
}
}
public class exitButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
public static void main(String[] args)
{
LBandConverter lbc = new LBandConverter ();
}
}
I have tried various combinations of if/else statements but this is the best I have come up with so far. The program works only if both fields have a value i.e. C-Band Frequency = 4200 and Ku-Band Frequency = 0. When calculated, the L-Band = 950. I want the user to choose only to enter 1 frequency either C-Band or Ku and get the resulting L-Band.
Thank you,
Chris DeCamp
This post has been edited by n8wxs: 14 July 2011 - 10:42 PM

New Topic/Question
Reply




MultiQuote




|