0 Replies - 1406 Views - Last Post: 10 April 2010 - 05:54 PM Rate Topic: -----

#1 _marlon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 03-March 09

Jlabel Author array loop, plus storage to secondary drive

Posted 10 April 2010 - 05:54 PM

So what i am having problems with is creating an array for author less than or equal to 4 authors. I've tried many ways but cannot seem to get the damn thing to work. Also, When i print my output, i want to just use 1 jpane call and not all the ones i've listed in my program. Tried converting the files to string and then assigning them to a String var then printing them on one jpane but doesn't seem to work. Lastly i would like to grab the data and save it to secondary story like my flash to be able to pull it out wheneven i need it in another program or to just print it out to the user. Been working on this sh*** for a while, hopefully someone can help !!! TY I'm including my code below:



import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.JOptionPane;


public class Book  extends JFrame
{														                                // <-----------4 Authors---------->
    private JLabel title , publisher , ISBN, price, copyRight, authorCount, author1, author2, author3, author4;
			                                                                              // <-----------4 Authors------------------->
    private JTextField titleTF, publisherTF, ISBNTF, priceTF, copyRightTF,authorCountTF, author1TF, author2TF, author3TF, author4TF;

    private JButton enterDataB;
	 private enterDataHandler edHandler;
	
	 private JButton exitB;
    private ExitButtonHandler ebHandler;

    private static final int WIDTH = 500;
    private static final int HEIGHT = 600;

    public Book ()
    {

	 
		 // Create four labels
	    title  = new JLabel("Enter the title: ",
 	                          SwingConstants.RIGHT);
	    publisher = new JLabel("Enter the publisher: ",
		 							SwingConstants.RIGHT);
	    ISBN  = new JLabel("Enter the ISBN: ",
 		                       	SwingConstants.RIGHT);
		 price  = new JLabel("Enter the Price: ",
 		                       	SwingConstants.RIGHT);								
		 copyRight  = new JLabel("Enter the Copy Right: ",
 		                       	SwingConstants.RIGHT);	
		 authorCount  = new JLabel("Enter the Author Count <=4 Authors!: ",
 		                   SwingConstants.RIGHT);	 
	    // i want to create loop here using author count to populate the authortf as many times as author count.					 
		 /*for(i=10; i>= i--)
		 author[]= new JLabel("Enter the author name: ",
		                     SwingConstants.RIGHT);
		*/							 
		
		
																						
		 // 4 Authors
		 author1 = new JLabel("Enter the author name: ",
		                     SwingConstants.RIGHT); 								
	    author2 = new JLabel("Enter the author 2: ",
		                     SwingConstants.RIGHT);								
		 author3 = new JLabel("Enter the author 3: ",
		                     SwingConstants.RIGHT);								
	    author4 = new JLabel("Enter the author 4: ",
		                     SwingConstants.RIGHT);								
		 //
		 
		 
		 								

		 //Create four textfields
	    titleTF = new JTextField(10);
	    publisherTF = new JTextField(10);
	    ISBNTF = new JTextField(10);
		 priceTF = new JTextField(10);		 
		 copyRightTF = new JTextField(10);
		 authorCountTF = new JTextField(10); // want to add a if loop after authorcount is given
		 // 4 Authors 
       author1TF = new JTextField(10);
		 author2TF = new JTextField(10);
		 author3TF = new JTextField(10);
		 author4TF = new JTextField(10);		 
		 //
		 
		 
		 
		 
		 //create Calculate Button
	    enterDataB = new JButton("Enter Data");
	    edHandler = new enterDataHandler();
	    enterDataB.addActionListener(edHandler);

		//Create Exit Button
	    exitB = new JButton("Exit");
	    ebHandler = new ExitButtonHandler();
	    exitB.addActionListener(ebHandler);

		 //Set the title of the window
	    setTitle("Book Inventory:");

		 //Get the container
		 Container pane = getContentPane();

		 //Set Grid layout
		 pane.setLayout(new GridLayout(11,2));

		 //Place all items created
		 pane.add(title);
	    pane.add(titleTF);
	    pane.add(publisher);
	    pane.add(publisherTF);
	    pane.add(ISBN );
	    pane.add(ISBNTF);
		 pane.add(price);
	    pane.add(priceTF);
		 pane.add(copyRight);
	    pane.add(copyRightTF);
		 pane.add(authorCount);
	    pane.add(authorCountTF);		 
		 // 4 Authors
		 pane.add(author1);
	    pane.add(author1TF);
		 pane.add(author2);
	    pane.add(author2TF);		 
		 pane.add(author3);
	    pane.add(author3TF);
		 pane.add(author4);
	    pane.add(author4TF);
		 //
		 pane.add(enterDataB);
	    pane.add(exitB);

		 //set the size of the window and display it
		 setSize(WIDTH,HEIGHT);
	    setVisible(true);
		 setDefaultCloseOperation(EXIT_ON_CLOSE);
	}
	 
	    // class to call on the data that was inputed into the text boxes.
public class enterDataHandler implements 
	 						     ActionListener
 {
    public void actionPerformed(ActionEvent e)
	 	{
// would like to combine all these joptionpanes to 1 to print all data at once .... then story it to secondary drive.

		
	    // String stTitle; -----not sure why this does not work. 

	    // stTitle = String.parse.String(titleTF.getText()); 
			
		  JOptionPane.showMessageDialog(null,titleTF, "This is your Book Title",
                                   JOptionPane.INFORMATION_MESSAGE);
		  JOptionPane.showMessageDialog(null,publisherTF, "This is your Publisher",
                                   JOptionPane.INFORMATION_MESSAGE);
		  JOptionPane.showMessageDialog(null,ISBNTF, "This is your ISBN",
                                   JOptionPane.INFORMATION_MESSAGE);	
		  JOptionPane.showMessageDialog(null,priceTF, "This is your Price",
                                   JOptionPane.INFORMATION_MESSAGE);									  
		  JOptionPane.showMessageDialog(null,copyRightTF, "This is your Copy Right",
                                   JOptionPane.INFORMATION_MESSAGE); 									  
		  JOptionPane.showMessageDialog(null,authorCountTF, "This is your Author Count",
                                   JOptionPane.INFORMATION_MESSAGE);									  
		 // <----------4 Authors-------------->									  
		  JOptionPane.showMessageDialog(null,author1TF, "This is your author 1",// want to add a if loop
                                   JOptionPane.INFORMATION_MESSAGE);									  
		  JOptionPane.showMessageDialog(null,author2TF, "This is your author 2",
                                   JOptionPane.INFORMATION_MESSAGE);
		  JOptionPane.showMessageDialog(null,author3TF, "This is your author 3",
                                   JOptionPane.INFORMATION_MESSAGE);
		  JOptionPane.showMessageDialog(null,author4TF, "This is your author 4",
                                   JOptionPane.INFORMATION_MESSAGE);
		  //
		  
		  
 			
							  									  									  						  
		}
	}

		 // class to exit the program
private class ExitButtonHandler implements ActionListener
	{
    public void actionPerformed(ActionEvent e)
	 	{
		    System.exit(0);
	   }
	}

    public static void main(String[] args)
	{
	    Book  rectObject = new Book ();
	}
}



Is This A Good Question/Topic? 0
  • +

Page 1 of 1