1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
bija089 [108]
3 years ago
12

Import java.awt.GridLayout;

Computers and Technology
1 answer:
Vikki [24]3 years ago
8 0

Answer:

public class ConversionCalculator extends JFrame {

  private JLabel inch_Label, meter_Label, cm_Label, yard_Label;

  private JButton clear, calculate, exit;

  private JTextField inch_tf, cm_tf, meters_tf, yards_tf;

 

  public ConversionCalculator()

  {

     

      exitButtonHandler exitB;

      clearButtonHandler clearB;

      calcButtonHandler calcB;

     

      setTitle("Conversion Calculator");

      setSize(600,200);

      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

     

      //The first layout we use will be 1 row with three columns

      setLayout(new GridLayout(1,3));

     

      //initialize all the components

      inch_Label = new JLabel("Inches");

      meter_Label = new JLabel("Meters");

      cm_Label = new JLabel("Centimeters");

      yard_Label = new JLabel("Yards");

      clear = new JButton("Clear");

      calculate = new JButton("Calculate");

      exit = new JButton("Exit");

      inch_tf = new JTextField("0.00");

      cm_tf = new JTextField("0.00");

      meters_tf = new JTextField("0.00");

      yards_tf = new JTextField("0.00");

 

      JPanel panel1 = new JPanel();

      panel1.setLayout(new GridLayout(2,2));

      JPanel panel2 = new JPanel();

      panel2.setLayout(new GridLayout(2,2));

      JPanel panel3 = new JPanel();

      panel3.setLayout(new GridLayout(3,1));

      panel1.add(cm_Label);

      panel1.add(cm_tf);

      panel1.add(meter_Label);

      panel1.add(meters_tf);

     

      panel2.add(inch_Label);

      panel2.add(inch_tf);

      panel2.add(yard_Label);

      panel2.add(yards_tf);

     

      panel3.add(clear);

      panel3.add(calculate);

      panel3.add(exit);

     

      add(panel1);

      add(panel2);

      add(panel3);

     

     

      exitB = new exitButtonHandler();

      exit.addActionListener(exitB);

     

      clearB = new clearButtonHandler();

      clear.addActionListener(clearB);

     

      calcB = new calcButtonHandler();

      calculate.addActionListener(calcB);

     

      setVisible(true);

  }

 

  //public static void main(String[] args)

     // {

       // new ConversionCalculator();

      //}

 

  private class exitButtonHandler implements ActionListener

  {

      public void actionPerformed(ActionEvent e)

      {

          //exits program

          System.exit(0);

      }

  }

 

  private class clearButtonHandler implements ActionListener

  {

      public void actionPerformed(ActionEvent e)

      {

          //clear button sets all text fields to 0

          inch_tf.setText("0.00");

          meters_tf.setText("0.00");

          yards_tf.setText("0.00");

          cm_tf.setText("0.00");

      }

  }

 

  private class calcButtonHandler implements ActionListener

  {

      public void actionPerformed(ActionEvent e)

      {

          double inches, yards, meters, cms;

          DecimalFormat df = new DecimalFormat("0.00");

         

          //parse strings in textbox into doubles

          inches = Double.parseDouble(inch_tf.getText());

          yards = Double.parseDouble(yards_tf.getText());

          meters = Double.parseDouble(meters_tf.getText());

          cms = Double.parseDouble(cm_tf.getText());

         

          //we check which value has been tampered with and base our conversion off this

          //because of this it is important that the user clears, or else it will do inch conversion

          if(inches != 0.00)

          {

              cms = inches * 2.54;

              meters = cms / 100;

              yards = inches / 36;

             

              cm_tf.setText(df.format(cms));

              meters_tf.setText(df.format(meters));

              yards_tf.setText(df.format(yards));

             

          }

          else if(yards != 0.00)

          {

              inches = yards / 36;

              cms = inches * 2.54;

              meters = cms / 100;

             

              cm_tf.setText(df.format(cms));

              meters_tf.setText(df.format(meters));

              inch_tf.setText(df.format(inches));

          }

          else if(meters != 0.00)

          {

              cms = meters * 100;

              inches = cms / 2.54;

              yards = inches / 36;

             

              cm_tf.setText(df.format(cms));

              inch_tf.setText(df.format(inches));

              yards_tf.setText(df.format(yards));

          }

          else if(cms != 0.00)

          {

              inches = cms / 2.54;

              yards = inches / 36;

              meters = cms / 100;

             

              meters_tf.setText(df.format(meters));

              inch_tf.setText(df.format(inches));

              yards_tf.setText(df.format(yards));

          }

      }

  }

}

Explanation:

  • Inside the action performed method, pass the strings in text box.
  • check if the value has been modified then do the relevant conversions inside the conditional statement.
  • When the user clears, it will not do to the inch conversion.
You might be interested in
A variable is assigned a value on line 328 of a program. Which of the following must be true in order for the variable to work?
Ivanshal [37]

Answer:

the answer is A

Explanation:

I just did this

3 0
3 years ago
Read 2 more answers
Word processing, presentation, photo editing, and video games are all types of what?
AnnZ [28]
They're all types of software.
5 0
3 years ago
Read 2 more answers
Your organization network diagram is shown in the figure below. Your company has the class C address range of 199.11.33.0. You n
user100 [1]

Answer:

aaaa

Explanation:

6 0
2 years ago
Mention one application of AI from the real world and describe the use of of this application what is the type of learning used
gayaneshka [121]

Answer:

The real world AI application is Google Duplex. It is able to receive orders for making reservations. Then it calls the shop or the place and deals with the person and talks to him very fluently and informs you about the reservation. Some other general types of AI application are Google Assistant, Siri , Amazon Alexa and so on. But google Duplex is lot more advanced than them.

4 0
2 years ago
if a hacker wants to exploit the TCP three-way handshake, what is the most effective way to go about it?
goldfiish [28.3K]

The most effective way to exploit TCP three-way handshake is TCP SYN flood.

  • SYN flood attack is simply a kind of computer attack that begins with 3-way TCP handshake.
  • TCP SYN flood is also called SYN flood and it is a type of distributed Denial of Service (DDoS) attack that uses every part of the normal TCP three-way handshake to eat up resources on the known server and render it non-functional
  • With TCP SYN flood, a hacker can eat up resources of target's computer and makes it unresponsive.

From the above, we can therefore say that the most effective way to exploit TCP three-way handshake is TCP SYN flood.

Learn more from:

brainly.com/question/14739766

7 0
2 years ago
Other questions:
  • A _________ consists of a set of computers that interconnect by means of a relatively unsecure network and makes use of encrypti
    5·1 answer
  • The ____ function sums the numbers in the specified range and then divides the sum by the number of cells with numeric values in
    14·1 answer
  • What are ways to enter a formula in Excel? Check all that apply. Click on the Function Library group and select a function from
    10·2 answers
  • You need to delegate AD RMS responsibilities to a junior administrator. You don't want to give the administrator more permission
    14·1 answer
  • What is the name of the program file that you can enter in the Windows search or Run box to execute Event Viewer? What process i
    12·1 answer
  • If you have a document that is relevant to more than one folder in your computer what should you do?
    8·1 answer
  • Create a file named homework_instructions.txt using VI editor and type in it all the submission instructions from page1 of this
    7·1 answer
  • Given the following array definition, write a constant declaration named ArraySize that automatically calculates the size in byt
    5·1 answer
  • Through the use of computational thinking techniques, models and algorithms can be created. A(n)
    11·1 answer
  • Write a function magicCheck that takes a one-dimensional array of size 16, a two-dimensional array of four rows and four columns
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!