Question

I'm writing a simple-ish program to look up movie information, and I'm having a bit of an issue making the GUI appear. I appreciate any help anyone might be able to offer.

package guiprojj;
import java.io.BufferedReader;
import java.io.Console;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
import java.net.UnknownHostException;
import java.util.Scanner;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import guiprojj.gui;

import javax.swing.JFrame;

@SuppressWarnings("unused")
public class Test {

    public static void main(String args[]) throws IOException {
        BufferedReader rd;
        OutputStreamWriter wr;
        String movie = null;
        //Scanner s = new Scanner(System.in);
        //System.out.println("Enter input:");
        //movie = s.nextLine();
        //movie = movie.replaceAll(" ", "%20");
        while (movie != null)
            {
            try {
            URL url = new URL("http://www.imdbapi.com/?i=&t=" + movie);
            URLConnection conn = url.openConnection();
            conn.setDoOutput(true);
            wr = new OutputStreamWriter(conn.getOutputStream());
            wr.flush();

            // Get the response
            rd = new BufferedReader(
                    new InputStreamReader(conn.getInputStream()));
            String line;
            line = rd.readLine();
            if (line != null) {
                System.out.println(line);
            } else {

                System.out.println("Sorry! That's not a valid URL.");
            }
        } catch (UnknownHostException codeyellow) {
             System.err.println("Caught UnknownHostException: " + codeyellow.getMessage());
        }
        catch (IOException e)
        {
            System.out.println("Caught IOException:" + e.getMessage());
        }

            }
    }
}

and

package guiprojj;

import javax.swing.*;

public class gui {
    public static void main()
    {
        JFrame maingui = new JFrame("Gui");
        JPanel pangui = new JPanel();
        JTextField movie = new JTextField(16);
        maingui.add(pangui);
        pangui.add(movie);
        maingui.setVisible(true);
        maingui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

are my two classes!

Was it helpful?

Solution

Add a String array argument to the main method of gui so that the application has a valid entry point

public static void main(String[] args)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top