Hi All,

For my final assignment, I need to create a BookCatalogue and save the data to a file on the disk.

I have created a Book class that get and inserts the fields: Book title, author and type.

public class Book
{
	private String title;
	private String author;

	public Book(String title, String author, String type)
	{
		this.title = title;
		this.author = author;
	}

	public String getTitle()
	{
		return new String(title);
	}

	public String setTitle()
	{
		return title;
	}

	public String getAuthor()
	{
		return new String(author);
	}

	public String setAuthor()
	{
		return author;
	}
}

I have created an Activator interface that implements the method activate()

public interface Activator
{
	public void activate();
}

Then, I created the BookAction interface that implements the actions INSERT = 1, UPDATE = 2, SEARCH = 3, DELETE = 4, DISPLAY = 5

public interface BookAction
{
	public final static int INSERT = 1, UPDATE = 2, SEARCH = 3, DELETE = 4, DISPLAY = 5;
}

Up to this point, it was easy for me and I knew what I wanted to do, but I am still struggling to relate classes to each other. I read about using inner classes on the intranet and it looks like this could make the code less complex. I would like to implement the innerclass system, but I am not exactly sure how to go about it.
I have created two other classes as well: The BookMaintenance class, where the INSERT, UPDATE, SEARCH, DELETE AND DISPLAY actions need to take place. (this code is VERY long ... i dont want to crowd the thread with this.)

Then, finally, to start the application, i have created the class BookMainScreen, which displays the main screen and the buttons for the main screen. And which is supposed to activate the buttons. My ActionPerformed method is not complete, as I am also struggling to wirte the code for the action buttons.

Within this code, i have also created the file to where the code needs to be saved as DataOutputStream.

here is the code of the BookMainScreen:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.*;
import java.util.*;

public class BookMainScreen extends JFrame implements ActionListener, Activator, BookAction
{
	//Declare Output Stream
	DataOutputStream output;

	public BookMainScreen()
	{
		super("BookLibrary Book Catalogue");

		// define GUI components
		JLabel optionLabel = new JLabel("Would you like to: ");
		JPanel btnPanel = new JPanel();

		JButton insertButton = new JButton("INSERT");
		JButton updateButton = new JButton("UPDATE");
		JButton searchButton = new JButton("SEARCH");
		JButton deleteButton = new JButton("DELETE");
		JButton displayButton = new JButton("DISPLAY");
		JButton exitButton = new JButton("EXIT");

		btnPanel.setLayout(new GridLayout(3,2,20,20));
		btnPanel.add(insertButton);
		btnPanel.add(updateButton);
		btnPanel.add(searchButton);
		btnPanel.add(deleteButton);
		btnPanel.add(displayButton);
		btnPanel.add(exitButton);

		// set up GUI
		JPanel contentPanel= new JPanel(new BorderLayout());
		contentPanel.add(optionLabel, BorderLayout.CENTER);
		contentPanel.add(btnPanel, BorderLayout.SOUTH);

		setContentPane(contentPanel);

		// add system date and open file
		Date today = new Date();
		SimpleDateFormat myFormat = new SimpleDateFormat("MMddyyyy");
		String filename = "BookCatalogue" + myFormat.format(today);

		try
		{
			output = new DataOutputStream(new FileOutputStream(filename));
		}
		catch(IOException io)
		{
			JOptionPane.showMessageDialog(null,"The storage location could not be created.  Please check the disk drive and then run the program again.","Error",JOptionPane.INFORMATION_MESSAGE);

			System.exit(1);
		}

		// add listeners
		addWindowListener(
			new WindowAdapter()
			  {
			    public void windowClosing(WindowEvent e)
			    {
					//int answer = JOptionPane.showConfirmDialog(null, "Are you sure you want to exit and submit the file?","File Submission",JOptionPane.YES_NO_OPTION);
						System.exit(0);
			    }
        	  });
	}

  	public void activate()
	{
	    this.setVisible(true);
	}

	public void actionPerformed(ActionEvent e)
    {

	}

	public static void main(String[] argv)
	{
		final BookMainScreen f = new BookMainScreen();
		f.setVisible(true);
		f.setSize(300,300);
		f.setLocation(250,250);
		f.setResizable(true);
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

I would please like some advise as to how to progress further. Mainly on if my thinking of how to relate the classes to each other so that they all work together to form one application is correct.

With regards to the coding of the ActionPerformed method, i am still working on that ... will update it as soon as possible.

Thank You

Im not sure what you are asking for, but this is how you create an inner class:

public class MyClass {

  public MyClass() {
    // Constructor for MyClass
  }
  
  private class MyInnerClass {
    public MyInnerClass() {
      // Constructor for inner class
    }
  }
}

I usually use inner classes when I want to write a private method but need to write a class. If you get how I mean.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.