Thread: Constructive Feed Back (Java Program)

Threaded View

Previous Post Previous Post   Next Post Next Post
  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

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