#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    5
    Rep Power
    0

    Angry Java app w/textfield & image problems


    Hi there -

    I'm trying to develop a regular Java program that has a window with a textfield and an image. When the user types something in the textbox, it is stored and then a new image replaces the old one.

    I'm having issues with just getting the text field on:

    a snippet of code:

    import javax.swing.*;
    import javax.swing.border.*;

    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;

    public class TryIO extends JFrame implements ActionListener
    {

    static JFrame aWindow = new JFrame("This is the Window Title");

    public TryIO()
    {
    Container content = getContentPane();
    JPanel panel = JPanel();
    JTextField textField = new JTextField("Default input", 20);
    panel.add(textField);
    content.add(panel, "test");

    }


    and then when i use JDK to compile i get:

    TryIO.java:16: cannot resolve symbol
    symbol : method JPanel ()
    location: class TryIO
    JPanel panel = JPanel();


    plus i'm using the:

    DataInputStream imagesIn = new DataInputStream(new FileInputStream(myImages));

    images[index] = imagesIn.readLine();


    and when that compiles I get:

    java.io.DataInputStream has been deprecated.

    What does that mean and does anyone know how I can get my app to work?

    - A
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    Finland
    Posts
    0
    Rep Power
    0
    I think the problem is here:

    Code:
    JPanel panel = JPanel();
    You should create new instance of the JPanel class using it's constructor:

    Code:
    JPanel panel = new JPanel();
    Check out the JPanel class from http://java.sun.com/apis.html.

    Something what is deprecated doesn't exist anymore in new releases of API-packages, although it has been part of the API-package. In this case, DataInputStream's readLine()-method is deprecated since JDK 1.1.

    To fix out this problem, replace

    Code:
    DataInputStream imagesIn = new DataInputStream(new FileInputStream(myImages));
    with

    Code:
    BufferedReader imagesIn = new BufferedReader(new InputStreamReader(new FileInputStream(myImages)));

IMN logo majestic logo threadwatch logo seochat tools logo