Thread: Constructive Feed Back (Java Program)

  1. #1
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589

    Constructive Feed Back (Java Program)

    I wrote a Java program and want opinions on what I can do to improve the interface. I understand it is a minor and inconsiquential program, but I feel it would be good for my developement to get other opinions on it. Remember this is my first program ever with Java. I also just have a command text field that shows action executions only no other functionality.

    Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    public class CleanedUp extends JFrame 
    { 
    final int SIZE = 100;
    Container container;
    GridBagLayout layout;
    GridBagConstraints c; 
    Box box1;
    Box box2;
    Box box3;
     
    JTextField commands;
    JLabel GeneraLabel;
    JLabel RatingLabel;
    JLabel outputArea1Label; 
    JLabel picture;
     
    JMenuBar bar;
    JMenu fileMenu;
    JMenu editMenu;
    JMenuItem OpenItem;
    JMenuItem CloseItem;
    JMenuItem SearchItem;
    JMenuItem CutItem;
    JMenuItem CopyItem;
    JMenuItem PasteItem;
    JComboBox GeneraCB;
    JComboBox RatingCB;
     
    JTable jt;
    JScrollPane scrollableTable;
    String DetailS[][] = new String[SIZE][SIZE];
    String TableLabelS[] = {"Title","Genera","Rating","Discription"};
    String GeneraS[] = new String[SIZE];
    String RatingS[] = new String[SIZE];
    File GeneraInputFile;
    File RatingInputFile;
    File DetailsInputFile;
    public CleanedUp()
    {
    	 super("DVD Database");
    	 SetProgramIcon(); 
    	 InitializeFiles();
    	 readData(GeneraInputFile,GeneraS);	
    	 readData(RatingInputFile,RatingS); 
    	 readData(DetailsInputFile,DetailS); 
    	 UpdatePicture();
    	 InitializeBoxs();
    	 InitializeLabels();
    	 InitializeTextFields();
    	 InitializeMenu();
    	 InitializeComboBox();
    	 InitializeTable();
    	 InitializeContainerAndConstraints();
    	 setSize(350,380);
    	 setVisible(true); 
    } 
    public static void main(String args[])
    {
    	 homeworkJava application = new homeworkJava();
    	 application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    public void SetProgramIcon()
    {
    	 setIconImage
    	 (
    		Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("sun.png"))
    	 ); 
    }
    public void InitializeFiles()
    {
    	 GeneraInputFile = new File("/home/buddha/code/homeworkJava","GeneraFile.txt");
    	 RatingInputFile = new File("/home/buddha/code/homeworkJava","RatingFile.txt");
    	 DetailsInputFile = new File("/home/buddha/code/homeworkJava","DetailsFile.txt");
    }
    public void InitializeTable()
    {
    	 jt = new JTable(DetailS,TableLabelS);
    	 scrollableTable = new JScrollPane(jt);
    }
    public void InitializeBoxs()
    {
    	 box1 = Box.createVerticalBox();
    	 box2 = Box.createVerticalBox();
    	 box3 = Box.createVerticalBox();
    	 box1.add(GeneraLabel);
    	 box1.add(GeneraCB);
    	 box1.add(RatingLabel);
    	 box1.add(RatingCB);
    	 box2.add(picture);
    	 box3.add(outputArea1Label);
    	 box3.add(scrollableTable);
    	 box1.setBackground(Color.white);
    	 box2.setBackground(Color.white);
    	 box3.setBackground(Color.white);
    }
    public void InitializeLabels()
    {
    	 GeneraLabel = new JLabel("Genera", JLabel.RIGHT);
    	 RatingLabel = new JLabel("Rating", JLabel.RIGHT);
    	 outputArea1Label = new JLabel("Details",JLabel.RIGHT); 
    	 picture = new JLabel();
    	 GeneraLabel.setLabelFor(GeneraCB); 
    	 RatingLabel.setLabelFor(RatingCB); 
    }
    public void InitializeTextFields()
    {
    	 commands = new JTextField(18);
    	 commands.setText("COMMANDS"); 
    }
    public void InitializeContainerAndConstraints()
    {
    	 container = getContentPane();
    	 layout = new GridBagLayout();
    	 c = new GridBagConstraints(); 
    	 container.setLayout(layout); 
    	 container.setBackground(Color.white); 
     
    	 c.fill=GridBagConstraints.HORIZONTAL;
    	 c.weightx=1;
    	 c.weighty=1;
    	 c.gridx=0;
    	 c.gridy=0;
    	 c.gridwidth=3;
    	 container.add(commands,c);	
    	 c.fill=GridBagConstraints.NONE;
    	 c.gridx=0;
    	 c.gridy=1;
    	 c.gridwidth=1;
    	 container.add(box1,c);
    	 c.gridx=2;
    	 c.gridy=1;
    	 c.gridwidth=0;
    	 container.add(box2,c);	 
     
    	 c.fill=GridBagConstraints.BOTH;
    	 c.gridx=0;
    	 c.gridy=2;
    	 c.gridheight=6;
    	 c.gridwidth=3;
    	 container.add(box3,c);
    }
    public void InitializeComboBox()
    {
    	 GeneraCB = new JComboBox(GeneraS);
    	 RatingCB = new JComboBox(RatingS);
    	 GeneraCB.setSelectedIndex(0);
    	 RatingCB.setSelectedIndex(0);
    	 GeneraCB.addActionListener
    	 (
    	 new ActionListener()
    		{
    		 public void actionPerformed( ActionEvent event1)
    		 {
    			JComboBox gcb = (JComboBox)event1.getSource();
    			String GeneraSelection = (String)gcb.getSelectedItem();
    			commands.setText(GeneraSelection);
    		 }
    		}
    	 );
    	 RatingCB.addActionListener
    	 (
    	 new ActionListener()
    		{
    		 public void actionPerformed( ActionEvent event2)
    		 {
    			JComboBox rcb = (JComboBox)event2.getSource();
    			String RatingSelection = (String)rcb.getSelectedItem();
    			commands.setText(RatingSelection);
    		 }
    		}
    	 );
    }
    public void InitializeMenu()
    {
    	 bar = new JMenuBar();
    	 fileMenu = new JMenu("File");
    	 fileMenu.setMnemonic('F');
    	 editMenu = new JMenu("Edit");
    	 editMenu.setMnemonic('E');
    	 OpenItem = new JMenuItem("Open");
    	 OpenItem.setMnemonic('O');
    	 OpenItem.setAccelerator
    	 (
    	 KeyStroke.getKeyStroke
    	 (
    		 'O',Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false
    	 )
    	 );
    	 fileMenu.add(OpenItem);
    	 OpenItem.addActionListener
    	 (
    	 new ActionListener()
    	 {
    		 public void actionPerformed( ActionEvent event)
    		 {
    		 commands.setText("Open Executed");
    		 }
    	 }
    	 );		
    	 CloseItem = new JMenuItem("Close");
    	 CloseItem.setMnemonic('C');
    	 CloseItem.setAccelerator
    	 (
    	 KeyStroke.getKeyStroke('L',Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false)
    	 );
    	 fileMenu.add(CloseItem);
    	 CloseItem.addActionListener
    	 (
    	 new ActionListener()
    	 {
    		 public void actionPerformed( ActionEvent event)
    		 {
    		 commands.setText("Close Executed");
    		 }
    	 }
    	 ); 
    	 SearchItem = new JMenuItem("Search");
    	 SearchItem.setMnemonic('S');
    	 SearchItem.setAccelerator
    	 (
    	 KeyStroke.getKeyStroke('S',Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false)
    	 );
    	 fileMenu.add(SearchItem);
    	 SearchItem.addActionListener
    	 (
    	 new ActionListener()
    	 {
    		 public void actionPerformed( ActionEvent event)
    		 {
    		 commands.setText("Search Executed");
    		 }
    	 }
    	 ); 
     
    	 CutItem = new JMenuItem("Cut");
    	 CutItem.setMnemonic('t');
    	 CutItem.setAccelerator
    	 (
    	 KeyStroke.getKeyStroke('T',Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false)
    	 );
    	 editMenu.add(CutItem);
    	 CutItem.addActionListener
    	 (
    	 new ActionListener()
    	 {
    		 public void actionPerformed( ActionEvent event)
    		 {
    		 commands.setText("Cut Executed");
    		 }
    	 }
    	 ); 
    	 CopyItem = new JMenuItem("Copy");
    	 CopyItem.setMnemonic('y');
    	 CopyItem.setAccelerator
    	 (
    	 KeyStroke.getKeyStroke('Y',Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false)
    	 );
    	 editMenu.add(CopyItem); 
    	 CopyItem.addActionListener
    	 (
    	 new ActionListener()
    	 {
    		 public void actionPerformed( ActionEvent event)
    		 {
    		 commands.setText("Copy Executed");
    		 }
    	 }
    	 ); 
     
    	 PasteItem = new JMenuItem("Paste");
    	 PasteItem.setMnemonic('P');
    	 PasteItem.setAccelerator
    	 (
    	 KeyStroke.getKeyStroke('P',Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false)
    	 );
    	 editMenu.add(PasteItem);
    	 PasteItem.addActionListener
    	 (
    	 new ActionListener()
    	 {
    		 public void actionPerformed( ActionEvent event)
    		 {
    		 commands.setText("Paste Executed");
    		 }
    	 }
    	 ); 
    	 bar.add(fileMenu);
    	 bar.add(editMenu);
    	 bar.setBackground(Color.white);
    	 setJMenuBar(bar);
    }
    public void readData(File inputFile,String[] DataStorage)
    {
    		int Count1=0;
    		try
    		{
    		 BufferedReader in = new BufferedReader(new FileReader(inputFile));
    		 String line;
    		 while((line = in.readLine())!=null)
    		 {
    			StringTokenizer tokens = new StringTokenizer(line);
     
    			while(tokens.hasMoreTokens())
    			 DataStorage[Count1++]=tokens.nextToken();
    		 }
    		}
    		catch(FileNotFoundException e)
    		{
    		 System.out.println("File is not accessable");
    		}
    		catch(IOException ioe)
    		{
    		 System.out.println(ioe);
    		}
    	}
    	public void readData(File inputFile, String[][] DataStorage)
    	{
    		int Count1=0,Count2=0;
    		try
    		{
    		 BufferedReader in = new BufferedReader(new FileReader(inputFile));
    		 String line;
    		 while((line = in.readLine())!=null)
    		 {
    			StringTokenizer tokens = new StringTokenizer(line," ",false);
     
    			while(tokens.hasMoreTokens())
    			 DataStorage[Count2][Count1++]=tokens.nextToken();
    	 Count1=0; 
    	 Count2++;
    		 }
    		}
    		catch(FileNotFoundException e)
    		{
    		 System.out.println("File is not accessable");
    		}
    		catch(IOException ioe)
    		{
    		 System.out.println(ioe);
    		}
    	}
    	public void UpdatePicture()//pass the string we will use for the .gif
    	{
    	 ImageIcon icon = new ImageIcon("/home/buddha/code/homeworkJava/picture.gif");
    	 //ImageIcon icon = createImageIcon("/"+name+".gif");
    	 picture.setIcon(icon);
     
    	 if (icon != null)
    	 {
    		picture.setText(null);
    	 }
    	 else
    	 {
    		picture.setText("Image not found");
    	 }
    	}
    }
    Last edited by xviddivxoggmp3; 07-31-2004 at 04:58 PM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  2. #2
    meow nbk's Avatar
    Join Date
    Jul 2004
    Posts
    45
    For the extremely little stuff, discription is spelled description, and genera is spelled genre. (I know you aren't worried about that, just pointion it out ^-^ )

  3. #3
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Your class is called "CleanedUp" but your main method tries to create a "homeworkJava" object. Even after fixing that and removing the hard-coded paths to input files in your home directory, the program crashes with a null pointer exception. you need to provide the input files and you should really make them read in from a directory relative to the program execution directory.

  4. #4
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    Thanks for the details.
    I didn't notice that.
    I revamped the working version to reorganize everything.
    I guess I created some bugs when doing this.
    I'm trying to find the exception now.
    If anyone has any ideas.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  5. #5
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    ever heard about comments?

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  6. #6
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    Are you trying to suggest i comment out each individual line until I find it?
    I'm already doing this.
    Or are you trying to say that I have commented incorrectly in the code?
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  7. #7
    meow nbk's Avatar
    Join Date
    Jul 2004
    Posts
    45
    I think he means since you don't have (m)any comments... well, add some!

  8. #8
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    Quote Originally Posted by nbk
    I think he means since you don't have any comments... well, add some!
    YES THAT IS EXACTLY what I mean

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  9. #9
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    Here you go corrected and commented.
    Please give me some constructive feedback.
    I will post the resulting code as a text file later tonight.
    Code:
    /*
    **File Name**
    CleanedUp.java
    
    **Needed Files**
    
    GenreFile.txt
    RatingFile.txt
    DetailsFile.txt
    picture.gif
    sun.png
    
    **Operating System**
    
    Non-dependent
    
    **Compiled On**
    
    Linux Redhat 9
    
    **Special Instructions**
    Make sure all files are in the same directory as CleanedUp.java
    
    **Compile Instructions**
    javac CleanedUp.java
    java CleanedUp
    */
    
    //Imported Packages
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    
    ///////////////////Start of Class Definition/////////////////////////////
    
    public class CleanedUp extends JFrame 
    { 
    
    //////////////////Object Libraries///////////////////////////////////////
    
       final int SIZE = 100;//Array Sizes
    
       Container container;//Container reference
       GridBagLayout layout;//Layout reference
       GridBagConstraints c; //Constraint reference
    
       Box box1;//Box1 reference
       Box box2;//Box2 reference
       Box box3;//Box3 reference
    		   
       JTextField commands;//Execution Confirmation Field
    
       JLabel GenreLabel;//Label to Genre ComboBox
       JLabel RatingLabel;//Label to Rating ComboBox
       JLabel outputArea1Label; //Label to DetailsTabel
       JLabel picture;//Label that hold picture.gif
    
       JMenuBar bar;//Menu bar reference
       JMenu fileMenu;//File Menu Item holder
       JMenu editMenu;//Edit Menu Item holder
       JMenuItem OpenItem;//Open Menu Item Reference
       JMenuItem CloseItem;//Close Menu Item Reference
       JMenuItem SearchItem;//Search Menu Item Reference
       JMenuItem CutItem;//Cut Menu Item Reference
       JMenuItem CopyItem;//Copy Menu Item Reference
       JMenuItem PasteItem;//Paste Menu Item Reference
    
       JComboBox GenreCB;//Genre Combobox holds GenreFile.txt
       JComboBox RatingCB;//Rating Combobox holds RatingFile.txt
    	
       JTable jt;//Table Details reference
       JScrollPane scrollableTable;//Scroll bar creation for Tabel Details
    
       String DetailS[][] = new String[SIZE][SIZE];
       //Multi Demensional Array for Table Data (DetailsFile.txt) 
       
       String TableLabelS[] = {"Title","Genre","Rating","Discription"};
       //Details Table Labels
    
       String GenreS[] = new String[SIZE];
       //Genre String used for reading the GenreFile.txt   
    
       String RatingS[] = new String[SIZE];
       //Rating String used for reading the RatingFile.txt 
    
       File GenreInputFile;//GenreFile reference
       File RatingInputFile;//RatingFile reference
       File DetailsInputFile;//DetailsFile reference
    
    /////////////////////End Object Libraries////////////////////////////////
    
    /////////////////////Constructor Start///////////////////////////////////
       /*
       Name:
    	 CleanedUp()
    
       Type:
    	 Constructor
    
       PreCondition:
    	 Objects have been instansiated and the constructor call was made 
    	 by the Main().  
    
       PostCondition:
    	 Objects have been initialized and the interface has been created.
    
       Future Methods Remaining:
    	 N/A
       */
       public CleanedUp()//CleanedUp Class Constructor
       {
    	  super("DVD Database");//Creates Title 
    
    	  SetProgramIcon();//Method Call to Set Program Icon 
    
    	  InitializeFiles();//Method Call to Initialize File References
    
    	  readData(GenreInputFile,GenreS);
    	  //Method Call to read GenreFile Overloaded to accept array[] 
     
    	  readData(RatingInputFile,RatingS);
    	  //Method Call to read RatingFile Overloaded to accept array[]
    
    	  readData(DetailsInputFile,DetailS);
    	  //Method Call to read DetailsFile Overloaded to accept array[][]
    
    	  InitializeLabels();//Method Call to Initialize Labels
    	  UpdatePicture();//Method Call to Update Picture Labels
    	  InitializeTextField();//Method Call to Initialize Execution Field
    	  InitializeMenu();//Method Call to Initialize Menu
    	  InitializeComboBox();//Method Call to Initialize ComboBoxs
    	  InitializeTable();//Method Call to Initialize Details Table
    	  InitializeBoxs();//Method Call to Initialize Boxs
    	  InitializeContainerAndConstraints();
    	  //Method Call that Initializes and sets Container and Constraints 
    
    	  setSize(350,380);//Sets Size of Frame
    	  setVisible(true);//Makes Frame Visible 
       } 
    ////////////////////////End Constructor//////////////////////////////////
    
    ////////////////////////Start Main()/////////////////////////////////////
       /*
       Name:
    	 main(String args[])
    
       Type:
    	 Main()
    
       PreCondition:
    	 Global objects have been initialized.
    
       PostCondition:
    	 Interface has been created, then execution has then completed.
    
       Future Methods Remaining:
    	 SetProgramIcon();
    	 InitializeFiles();
    	 readData(GenreInputFile,GenreS); 
    	 readData(RatingInputFile,RatingS);
    	 readData(DetailsInputFile,DetailS);
    	 InitializeLabels();
    	 UpdatePicture();
    	 InitializeTextField();
    	 InitializeMenu();
    	 InitializeComboBox();
    	 InitializeTable();
    	 InitializeBoxs();
    	 InitializeContainerAndConstraints();
       */
       public static void main(String args[])
       {
    	  CleanedUp application = new CleanedUp();//Insansiates Class and Calls Constructor
    	  application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//Sets Exit Functionality
       }
    //////////////////End Main()/////////////////////////////////////////////
    
    /////////////////Method Members//////////////////////////////////////////
       /*
       Name:
    	 SetProgramIcon()
    
       Type:
    	 Member Method
    
       PreCondition:
    	 Objects have been instansiated, and Program has been titled.
    
       PostCondition:
    	 Alt-Tab Icon, and Top left Icon Next to the Title has been updated
    
       Future Methods Remaining:
    
    	 InitializeFiles();
    	 readData(GenreInputFile,GenreS); 
    	 readData(RatingInputFile,RatingS);
    	 readData(DetailsInputFile,DetailS);
    	 InitializeLabels();
    	 UpdatePicture();
    	 InitializeTextField();
    	 InitializeMenu();
    	 InitializeComboBox();
    	 InitializeTable();
    	 InitializeBoxs();
    	 InitializeContainerAndConstraints();
       */
       public void SetProgramIcon()
       {
    	  setIconImage
    	  (
    		Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("sun.png"))
    	  );//Sets Image Program Icon  
       }
    
       /********************************************************************/
       /*
       Name:
    	 InitializeFiles()
    
       Type:
    	 Member Method
    
       PreCondition:
    	 Objects have been instansiated, and Program has been titled.
    
       PostCondition:
    	 File Objects have been linked to the inputstream.
    
       Future Methods Remaining:
    
    	 readData(GenreInputFile,GenreS); 
    	 readData(RatingInputFile,RatingS);
    	 readData(DetailsInputFile,DetailS);
    	 InitializeLabels();
    	 UpdatePicture();
    	 InitializeTextField();
    	 InitializeMenu();
    	 InitializeComboBox();
    	 InitializeTable();
    	 InitializeBoxs();
    	 InitializeContainerAndConstraints();
       */
       public void InitializeFiles()
       {
    	 GenreInputFile = new File("GenreFile.txt");//Sets GenreInputFile to GenreFile.txt
    	 RatingInputFile = new File("RatingFile.txt");//Sets RatingInputFile to RatingFile.txt
    	 DetailsInputFile = new File("DetailsFile.txt");//Sets DetailsInputFile to DetailsFile.txt
       }
       /********************************************************************/
       /*
       Name:
    	 InitializeTable()
    
       Type:
    	 Member Method
    
       PreCondition:
    	 References have been declared globally
       PostCondition:
    	 References have been initialized by calling constructors
    
       Future Methods Remaining:
    	 InitializeBoxs();
    	 InitializeContainerAndConstraints();
       */
       public void InitializeTable()
       {
    	 jt = new JTable(DetailS,TableLabelS);
    	 //calls JTable Constructor to initialize tabel reference
    
    	 scrollableTable = new JScrollPane(jt);
    	 //Initializes the scroll bar reference with the JTable
       }
       /********************************************************************/
       /*
       Name:
    	 InitializeBoxs()
    
       Type:
    	 Member Method
    
       PreCondition:
    	 References have been instansiated.
       PostCondition:
    	 Boxes have been initialized as Vertical Boxes.
    	 Components have been added to boxes.
    	 Background color has been set.
    
       Future Methods Remaining:
    	 InitializeContainerAndConstraints();
       */
       public void InitializeBoxs()
       {
    	 box1 = Box.createVerticalBox();//sets box to vertical
    	 box2 = Box.createVerticalBox();//sets box to vertical
    	 box3 = Box.createVerticalBox();//sets box to vertical
    
    	 box1.add(GenreLabel);//adds component to box
    	 box1.add(GenreCB);//adds component to box
    	 box1.add(RatingLabel);//adds component to box
    	 box1.add(RatingCB);//adds component to box
    	 box2.add(picture);//adds component to box
    	 box3.add(outputArea1Label);//adds component to box
    	 box3.add(scrollableTable);//adds component to box
    
    	 box1.setBackground(Color.white);//updates color to white
    	 box2.setBackground(Color.white);//updates color to white
    	 box3.setBackground(Color.white);//updates color to white
       }
       /********************************************************************/
       /*
       Name:
    	 InitializeLabels()
    
       Type:
    	 Member Method
    
       PreCondition:
    	 References have been instansiated.
    
       PostCondition:
    	 Labels have been initialized with values and labels 
    	 for combo boxes have been set.
    
       Future Methods Remaining:
    	 UpdatePicture();
    	 InitializeTextField();
    	 InitializeMenu();
    	 InitializeComboBox();
    	 InitializeTable();
    	 InitializeBoxs();
    	 InitializeContainerAndConstraints();
       */
       public void InitializeLabels()
       {
    	 GenreLabel = new JLabel("Genre", JLabel.RIGHT);//initializes label
    	 RatingLabel = new JLabel("Rating", JLabel.RIGHT);//initializes label
    	 outputArea1Label = new JLabel("Details",JLabel.RIGHT);//initializes label 
    
    	 picture = new JLabel();//initializes label
    
    	 GenreLabel.setLabelFor(GenreCB);//sets label to component
    	 RatingLabel.setLabelFor(RatingCB);//sets label to component
       }
       /********************************************************************/
       /*
       Name:
    	 InitializeTextField()
    
       Type:
    	 Member Method
    
       PreCondition:
    	 References have been instansiated.
    
       PostCondition:
      Text Field has been initialized and the 
      text in the field was set to Command.
       Future Methods Remaining:
    
    	 InitializeMenu();
    	 InitializeComboBox();
    	 InitializeTable();
    	 InitializeBoxs();
    	 InitializeContainerAndConstraints();
    
       */
       public void InitializeTextField()
       {
    	 commands = new JTextField(18);//initializes textfield
    	 commands.setText("COMMANDS");//sets text to textfield
       }
       /********************************************************************/
       /*
       Name:
    	 InitializeContainerAndConstraints()
    
       Type:
    	 Member Method
    
       PreCondition:
    	 References have been instansiated.
    
       PostCondition:
    	 The constraints have been initialized and set
    	 for each individual component. The Container 
    	 was also initialized and the components
    	 have been added to the container.
    
       Future Methods Remaining:
    	 N/A
       */
       public void InitializeContainerAndConstraints()
       {
    	 container = getContentPane();//initializes container
    	 layout = new GridBagLayout();//initializes gridbaglayout
    	 c = new GridBagConstraints();//initializes constraints
    
    	 container.setLayout(layout);//sets container layout
    
    	 container.setBackground(Color.white);//sets container color
    	  
    	 c.fill=GridBagConstraints.HORIZONTAL;//sets grid fill to horizontal
    	 c.weightx=1;//sets grid cell weight
    	 c.weighty=1;//sets grid cell weight
    	 c.gridx=0;//sets grid cell location
    	 c.gridy=0;//sets grid cell location
    	 c.gridwidth=3;//sets grid cell span
    	 container.add(commands,c);//adds component to container
    
    	 c.fill=GridBagConstraints.NONE;//sets grid fill to none
    	 c.gridx=0;//sets grid cell location
    	 c.gridy=1;//sets grid cell location
    	 c.gridwidth=1;//sets grid cell span
    	 container.add(box1,c);//adds component to container
    
    	 c.gridx=2;//sets grid cell location
    	 c.gridy=1;//sets grid cell location
    	 c.gridwidth=0;//sets grid cell span
    	 container.add(box2,c);//adds component to container	   
    	  
    	 c.fill=GridBagConstraints.BOTH;//sets grid fill to both (horizontal and vertical)
    	 c.gridx=0;//sets grid cell location
    	 c.gridy=2;//sets grid cell location
    	 c.gridheight=6;//sets grid cell span
    	 c.gridwidth=3;//sets grid cell span
    	 container.add(box3,c);//adds component to container
       }
       /********************************************************************/
       /*
       Name:
    	 InitializeComboBox()
    
       Type:
    	 Member Method
    
       PreCondition:
    	 References have been instansiated.
    
       PostCondition:
      The combo boxes have been initialized,
      and the action listeners have been 
      created.
       Future Methods Remaining:
    	 InitializeTable();
    	 InitializeBoxs();
    	 InitializeContainerAndConstraints();
       */
       public void InitializeComboBox()
       {
    	  GenreCB = new JComboBox(GenreS);//initializes comboboxes
    	  RatingCB = new JComboBox(RatingS);//initializes comboboxes
    
    	  GenreCB.setSelectedIndex(0);//sets default combobox selection
    	  RatingCB.setSelectedIndex(0);//sets default combobox selection
    
    	  GenreCB.addActionListener//creates action listener for combo box
    	  (
    	   new ActionListener()
    		{
    		  public void actionPerformed( ActionEvent event1)
    		  {
    			JComboBox gcb = (JComboBox)event1.getSource();
    			String GenreSelection = (String)gcb.getSelectedItem();//collects item selected
    			commands.setText(GenreSelection);//prints execution proof
    		  }
    		}
    	  );
    
    	  RatingCB.addActionListener//creates action listener for combo box
    	  (
    	   new ActionListener()
    		{
    		  public void actionPerformed( ActionEvent event2)
    		  {
    			JComboBox rcb = (JComboBox)event2.getSource();
    			String RatingSelection = (String)rcb.getSelectedItem();//collects item selected
    			commands.setText(RatingSelection);//prints execution proof
    		  }
    		}
    	  );
       }
       /********************************************************************/
       /*
       Name:
    	 InitializeMenu()
    
       Type:
    	 Member Method
    
       PreCondition:
    	 References have been instansiated.
    
       PostCondition:
    	 Menu Bar and Menu Items are initialized.
    	 Menu Item Action Listeners have been 
    	 created. Mnemonics and shortcut keys have
    	 also been created.
    
       Future Methods Remaining:
    	 InitializeComboBox();
    	 InitializeTable();
    	 InitializeBoxs();
    	 InitializeContainerAndConstraints();
       */
       public void InitializeMenu()
       {
    	 bar = new JMenuBar();//initializes menubar
    
    	 fileMenu = new JMenu("File");//initializes menu item
    	 fileMenu.setMnemonic('F');//sets mnemonics for item
    
    	 editMenu = new JMenu("Edit");//initializes menu item
    	 editMenu.setMnemonic('E');//sets mnemonics for item
    
    	 OpenItem = new JMenuItem("Open");//initializes menu item
    	 OpenItem.setMnemonic('O');//sets mnemonics for item
    	 OpenItem.setAccelerator//sets shortcut key 
    	 (
    	   KeyStroke.getKeyStroke
    	   (
    		 'O',Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false
    	   )
    	 );
    	 fileMenu.add(OpenItem);//adds item to menu
    	 OpenItem.addActionListener
    	 (
    	   new ActionListener()//adds action listener
    	   {
    		 public void actionPerformed( ActionEvent event)
    		 {
    		   commands.setText("Open Executed");
    		 }
    	   }
    	 );		
    
    	 CloseItem = new JMenuItem("Close");//initializes menu item
    	 CloseItem.setMnemonic('C');//sets mnemonics for item
    	 CloseItem.setAccelerator//sets shortcut key
    	 (
    	   KeyStroke.getKeyStroke('L',Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false)
    	 );
    	 fileMenu.add(CloseItem);//adds item to menu
    	 CloseItem.addActionListener
    	 (
    	   new ActionListener()//adds action listener
    	   {
    		 public void actionPerformed( ActionEvent event)
    		 {
    		   commands.setText("Close Executed");
    		 }
    	   }
    	 ); 
    
    	 SearchItem = new JMenuItem("Search");//initializes menu item
    	 SearchItem.setMnemonic('S');//sets mnemonics for item
    	 SearchItem.setAccelerator//sets shortcut key
    	 (
    	   KeyStroke.getKeyStroke('S',Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false)
    	 );
    	 fileMenu.add(SearchItem);//adds item to menu
    	 SearchItem.addActionListener//adds action listener
    	 (
    	   new ActionListener()
    	   {
    		 public void actionPerformed( ActionEvent event)
    		 {
    		   commands.setText("Search Executed");
    		 }
    	   }
    	 ); 
    	  
    	 CutItem = new JMenuItem("Cut");//initializes menu item
    	 CutItem.setMnemonic('t');//sets mnemonics for item
    	 CutItem.setAccelerator//sets shortcut key
    	 (
    	   KeyStroke.getKeyStroke('T',Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false)
    	 );
    	 editMenu.add(CutItem);//adds item to menu
    	 CutItem.addActionListener//adds action listener
    	 (
    	   new ActionListener()
    	   {
    		 public void actionPerformed( ActionEvent event)
    		 {
    		   commands.setText("Cut Executed");
    		 }
    	   }
    	 ); 
    
    	 CopyItem = new JMenuItem("Copy");//initializes menu item
    	 CopyItem.setMnemonic('y');//sets mnemonics for item
    	 CopyItem.setAccelerator//sets shortcut key
    	 (
    	   KeyStroke.getKeyStroke('Y',Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false)
    	 );
    	 editMenu.add(CopyItem);//adds item to menu
    	 CopyItem.addActionListener//adds action listener
    	 (
    	   new ActionListener()
    	   {
    		 public void actionPerformed( ActionEvent event)
    		 {
    		   commands.setText("Copy Executed");
    		 }
    	   }
    	 ); 
    		  
    	 PasteItem = new JMenuItem("Paste");//initializes menu item
    	 PasteItem.setMnemonic('P');//sets mnemonics for item
    	 PasteItem.setAccelerator//sets shortcut key
    	 (
    	   KeyStroke.getKeyStroke('P',Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false)
    	 );
    	 editMenu.add(PasteItem);//adds item to menu
    	 PasteItem.addActionListener//adds action listener
    	 (
    	   new ActionListener()
    	   {
    		 public void actionPerformed( ActionEvent event)
    		 {
    		   commands.setText("Paste Executed");
    		 }
    	   }
    	 ); 
    
    	 bar.add(fileMenu);//adds menu item to menu bar
    	 bar.add(editMenu);//adds menu item to menu bar
    
    	 bar.setBackground(Color.white);//sets background color to menubar
    
    	 setJMenuBar(bar);//adds menubar to container
       }
       /********************************************************************/
       /*
       Name:
    	 readData(File inputFile,String[] DataStorage)
    
       Type:
    	 Overloaded Member Method
    
       PreCondition:
    	 References have been instansiated.
    
       PostCondition:
    	 Data in the .txt files have been read into 
    	 a string array for storage purposes.
    
       Future Methods Remaining:
    	 readData(DetailsInputFile,DetailS);
    	 InitializeLabels();
    	 UpdatePicture();
    	 InitializeTextField();
    	 InitializeMenu();
    	 InitializeComboBox();
    	 InitializeTable();
    	 InitializeBoxs();
    	 InitializeContainerAndConstraints();
    
       */
       public void readData(File inputFile,String[] DataStorage)
       {
    		int Count1=0;//instansiates and initializes count1
    
    		try//exception catcher try block starter
    		{//the folllowing creats a file stream
    		  BufferedReader in = new BufferedReader(new FileReader(inputFile));
    		  String line;//instansiates a string 
    
    		  while((line = in.readLine())!=null)//while not null process file stream
    		  {
    			StringTokenizer tokens = new StringTokenizer(line);
    			//instansiates and initializes tokenizer
    		
    			while(tokens.hasMoreTokens())
    			  DataStorage[Count1++]=tokens.nextToken();//inputs tokens in array
    		  }
    		}
    		catch(FileNotFoundException e)//catchs file not found exception
    		{
    		  System.out.println("File is not accessable");
    		}
    		catch(IOException ioe)//catchs input stream exceptoins
    		{
    		  System.out.println(ioe);
    		}
    	}
       /********************************************************************/
       /*
       Name:
    	 readData(File inputFile, String[][] DataStorage)
    
       Type:
    	 Overloaded Member Method
    
       PreCondition:
    	 References have been instansiated.
    
       PostCondition:
    	 Data in the .txt file has been read into 
    	 a multidemensional string array for storage 
    	 purposes.
    		  
       Future Methods Remaining:
    	 InitializeLabels();
    	 UpdatePicture();
    	 InitializeTextField();
    	 InitializeMenu();
    	 InitializeComboBox();
    	 InitializeTable();
    	 InitializeBoxs();
    	 InitializeContainerAndConstraints();
       */
    	public void readData(File inputFile, String[][] DataStorage)
    	{
    		int Count1=0,Count2=0;//instansiates and initializes count1 and count2
    
    		try//try block used to check for exception errors
    		{
    		  BufferedReader in = new BufferedReader(new FileReader(inputFile));
    		  //creates input stream file object
    		  
    		  String line;//instansiates string
    
    		  while((line = in.readLine())!=null)//read all data in the .txt file 
    		  {
    			StringTokenizer tokens = new StringTokenizer(line," ",false);
    			//instansiates and initializes tokenizer
    		
    			while(tokens.hasMoreTokens())//places tokens in array[][]
    			  DataStorage[Count2][Count1++]=tokens.nextToken();
    
    	   Count1=0;//reset counter  
    	   Count2++;//increment counter
    		  }
    		}
    		catch(FileNotFoundException e)//catch file not found exception
    		{
    		  System.out.println("File is not accessable");
    		}
    		catch(IOException ioe)//catch input file stream exception.
    		{
    		  System.out.println(ioe);
    		}
    	}
       /********************************************************************/
       /*
       Name:
    	 UpdatePicture()
    
       Type:
    	 Member Method
    
       PreCondition:
    	 References have been instansiated.
    
       PostCondition:
    	 Updates the picture label to reflect
    	 the pic that is either passed to it, 
    	 or the one that is hardcoded.
       Future Methods Remaining:
    	 InitializeTextField();
    	 InitializeMenu();
    	 InitializeComboBox();
    	 InitializeTable();
    	 InitializeBoxs();
    	 InitializeContainerAndConstraints();
       */
    	public void UpdatePicture()//pass the string we will use for the .gif
    	{
    	  ImageIcon icon = new ImageIcon("picture.gif");
    	  //instansiates and initializes imageicon 
    	  //ImageIcon icon = createImageIcon("/"+name+".gif");
    
    	  picture.setIcon(icon);//sets label to icon image
    		 
    	  if (icon != null)//tests icon for valid image.
    	  {
    		picture.setText(null);
    	  }
    	  else
    	  {
    		picture.setText("Image not found");
    	  }
    	}
    ///////////////////////End Of Methods////////////////////////////////////
    
    /////////////////////End Of Class Definition/////////////////////////////
    }
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  10. #10
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    hey can you post all the files neede to compile this thing...I would like to see how this thing looks....on first glance it is an awful lot of code for something that seems not too complicated.

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  11. #11
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    sorry it took so long, but here are the files.
    again this is just a stupid starter project.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  12. #12
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    one thing about the comments...it usully helps if you do something that allows them to be easily seen...I dont know if your ide highlights comments, but just out of good practice you should tab over after the code or do it on the previous or next line. Pushing it right up against the code makes it easy to skip over so people like us still don't know whats going on at first glance.
    PHP and XML
    Let's talk about SAX

  13. #13
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589

    here is my most recent java program.

    I feel that it has improved a little more than before. please tell me what i can do to improve.
    thank you.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is it possible to call a java program in C?
    By xilum68 in forum C++ Programming
    Replies: 1
    Last Post: 12-05-2003, 01:26 AM
  2. Date program starts DOS's date
    By jrahhali in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2003, 05:23 PM
  3. Replies: 2
    Last Post: 05-10-2002, 04:16 PM
  4. im back and agghh java!
    By iain in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 09-26-2001, 11:15 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM