Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Must be in java!! You dont have to add the code for the json api. I just need th

ID: 3835564 • Letter: M

Question

Must be in java!!

You dont have to add the code for the json api. I just need the gui built and if you could please comment on the code where and how i would implement the api code.

Display a GUl where the user can type in a zip code. Access the weather underground API to retrieve the current conditions for the Zip Code. Display the city, state, current temperature (F), and weather (e.g. "Partly Cloudy"). If the temperature is above 70 degrees, then display an image of the sun somewhere on the window, if it is less, display an image of someone who is shivering somewhere on the screen The GUI is simple: A text field where the user enters the ZIP code. A button to make the query go. Four un editable text fields for displaying the weather information. o txtField set Editable (false), Labels for each of the text fields. Image of the type of weather o Create a JLabel object o Create an imagelcon object o Put the image inside the label using setlcon Here is an example JLabel my Label, Image con picture, picture new Imagelcon(new URL ("http://someplace/someimage.jpg"), myLabel setlcon (picture), X Enter Zip: 95678 Get weather Roseville City State California Conditions: Clear Tempo 86.2 F o c a F

Explanation / Answer

Here is the code to for the UI.

import java.awt.BorderLayout;

import java.awt.Container;

import java.awt.Dimension;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.net.MalformedURLException;

import java.net.URL;

import javax.swing.BorderFactory;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JRadioButton;

import javax.swing.JTextField;

public class WeatherAPPUI extends JFrame {

   private JTextField txtZip, txtCity, txtState, txtCondition, txtTemp;

   private JRadioButton radCenti,radFaren;

   private JLabel imageLabel;

   private JButton butGet;

  

   public WeatherAPPUI()

   {

       super("Weather App");

       setSize(500,250);

       setDefaultCloseOperation(EXIT_ON_CLOSE);

      

       createUI();

       setVisible(true);

   }

  

   private void createUI()

   {

       JPanel top,left, right;

      

       top = new JPanel();

       top.add( new JLabel("Enter zip"));

       top.add(txtZip = new JTextField());

       txtZip.setPreferredSize(new Dimension(100,40) );

       top.add(butGet = new JButton("Get Weather"));

       top.setPreferredSize(new Dimension(400,50));

      

       left = new JPanel(new GridLayout(5,2));

      

       left.add(new JLabel("City:" ));

       left.add(txtCity = new JTextField());

      

       left.add(new JLabel("State:"));

       left.add(txtState = new JTextField());

       left.add(new JLabel("Conditions:"));

       left.add(txtCondition = new JTextField());

      

       left.add(new JLabel("Temperature:"));

       left.add(txtTemp = new JTextField());

      

       left.add(radCenti = new JRadioButton("C"));

       left.add(radFaren = new JRadioButton("F"));

      

      

       imageLabel = new JLabel();

       imageLabel.setBorder(BorderFactory.createEmptyBorder(30,30,30,30));

       imageLabel.setPreferredSize(new Dimension(100,100));

      

      

       Container c = getContentPane();

       c.setLayout(new BorderLayout());

       c.add(top, BorderLayout.NORTH);

       c.add(left, BorderLayout.CENTER);

       c.add(imageLabel, BorderLayout.EAST);

      

       butGet.addActionListener(new ActionListener() {

          

           @Override

           public void actionPerformed(ActionEvent e) {

               fetchWeather();

              

           }

       });

      

      

      

   }

  

   private void fetchWeather()

   {

       //make api call to get the weather details here ....

      

       //then set teh data into the appropriate fields

      

       txtCity .setText("Roseville");

       txtState.setText("California");

       txtCondition.setText("Clear");

       txtTemp.setText("86.2 F");

      

       radFaren.setSelected(true);

      

       //set the url based on temperature value

       String url = "http://wallpaper-gallery.net/images/sun/sun-7.jpg";

      

       ImageIcon picture;

       try {

           picture = new ImageIcon(new URL(url));

           imageLabel.setIcon(picture);

       } catch (MalformedURLException e) {

           System.out.println("Icon url not valid");

       }

      

   }

  

   public static void main(String[] args) {

       WeatherAPPUI ui = new WeatherAPPUI();

      

   }

}