Joachim Schaaf wrote:

> Steve Cohen wrote:
> >
> >   I am getting my feet wet with java-linux.
> > As a first step, I am simply copying code from the disk included with
> > the book
> > "Java for C/C++ Programmers" by Michael C. DaConta.
> > The first "Hello World" program worked okay but the second one,
> > attached, does not.
> > On my RedHat 5.0 systems (yes, I've upgraded glibc and ld) the dialog
> > comes up but no keyboard input shows up.  Any idea why?
>
> > // our book class
> > import book;
>
> I guess without this package (book) noone can compile it ...
>
> Joachim
> --
> Joachim Schaaf
> IoS - Gesellschaft fuer innovative Softwareentwicklung mbH
> Donatusstrasse 127-129, 50259 Pulheim, Tel/Fax: ++49-2234-986432/3
> Email: [EMAIL PROTECTED], WWW: http://www.ios-online.de/

Sorry about that.  Okay, it's all there now.  src1-7.java is a new version
incorporating Juergen Kreileder's code fix.  It still doesn't work.
src1-4.java has the book class.


// gui classes
import java.awt.Frame;
import java.awt.TextField;
import java.awt.Panel;
import java.awt.Button;
import java.awt.GridLayout;
import java.awt.Event;
import java.awt.Color;
import java.awt.Label;

// our book class
import book;

// a utility class
import java.util.Vector;

class bookWindow extends Frame {
    TextField title;
    TextField author;
    TextField publisher;
    Vector theBooks;
    int currentIdx;

    bookWindow() {
        super("Book Shelf");

        // initialize the growable array
        theBooks = new Vector(3);
        currentIdx = 0;

        Panel centerPanel = new Panel();
        centerPanel.setLayout(new GridLayout(0, 2));

        centerPanel.add(new Label("               Title"));
        centerPanel.add(title = new TextField(20));

        centerPanel.add(new Label("               Author"));
        centerPanel.add(author = new TextField(20));

        centerPanel.add(new Label("               Publisher"));
        centerPanel.add(publisher = new TextField(20));

        add("Center", centerPanel);

        Panel bottomPanel = new Panel();
        bottomPanel.add(new Button("store"));
        bottomPanel.add(new Button("clear"));
        bottomPanel.add(new Button("prev"));
        bottomPanel.add(new Button("next"));
        bottomPanel.add(new Button("exit"));
        add("South", bottomPanel);

        move(200, 100);
        pack();
        show();
    }

    public boolean handleEvent(Event evt) {
        if (evt.id == Event.ACTION_EVENT)
        {
            if ("store".equals(evt.arg))
            {
                book aBook = new book(title.getText(),
                                      author.getText(),
                                      publisher.getText());                

                theBooks.addElement(aBook);
                currentIdx = theBooks.size();
                return true;
            }
            if ("clear".equals(evt.arg))
            {
                title.setText("");
                author.setText("");
                publisher.setText("");
                return true;
            }
            if ("prev".equals(evt.arg))
            {
                if (currentIdx > 0)
                {
                        book aBook = (book) theBooks.elementAt(--currentIdx);
                        title.setText(aBook.getTitle());
                        author.setText(aBook.getAuthor());
                        publisher.setText(aBook.getPublisher()); 
                }
                return true;
            }
            if ("next".equals(evt.arg))
            {
                if (currentIdx < (theBooks.size()-1))
                {
                        book aBook = (book) theBooks.elementAt(++currentIdx);
                        title.setText(aBook.getTitle());
                        author.setText(aBook.getAuthor());
                        publisher.setText(aBook.getPublisher()); 
                }
                return true;
            }
            if ("exit".equals(evt.arg))
            {
                System.exit(0);
            }
        }
        return super.handleEvent(evt);
    }
}

class bookGUI {
    public static void main(String args[])
    {
        new bookWindow();
    }
}
// books.java
import java.lang.String;
import java.io.DataInputStream;
import java.lang.System;
import java.io.IOException;

class book {
        protected String title;
        protected String author;
        protected String publisher;
        book next;

        book()
        {
                title = author = publisher = " ";
                next = null;
        }

        book(book other)
        {
                title = other.title;
                author = other.author;
                publisher = other.publisher;
                next = null;
        }

        book(String aTitle, String anAuthor, String aPublisher)
        {
                title = aTitle;
                author = anAuthor;
                publisher = aPublisher;
                next = null;
        }

        void getBook()
        {
            try {
                DataInputStream dis = new DataInputStream(System.in);
                System.out.print("Enter title    : ");
                System.out.flush();
                title = dis.readLine();
                if (title.equals("done"))
                        return;
                System.out.print("Enter author   : ");
                System.out.flush();
                author = dis.readLine();
                System.out.print("Enter publisher: ");
                System.out.flush();
                publisher = dis.readLine();
                next = null;
            } catch (IOException ioe)
              {
                System.out.println(ioe.toString());
                System.out.println("Unable to get the book data.");
                return;
              }
        }

        void showBook()
        {
                System.out.println("Title    : " + title);
                System.out.println("Author   : " + author);
                System.out.println("Publisher: " + publisher);
        }

        // accessor
        String getTitle() { return title; }
        String getAuthor() { return author; }
        String getPublisher() { return publisher; }

        // mutator
        void setTitle(String aTitle) { title = aTitle; }
        void setAuthor(String anAuthor) { author = anAuthor; }
        void setPublisher(String aPublisher) { publisher = aPublisher; }
}

Reply via email to