résumé  |   play  |   contact  |   email  |   links     homepage  |   Thursday, September 9th

 

JWebCast Application

Introducing JWebCast v2.0! Rather than re-writing the whole HTML page every time a change is made (like WebCast), JWebCast merely creates an include file. This is then used by an Active Server Page to pull the data from the include file. This allows the desgin of the webcast page to change. The designer needs to only include tags for the score, time, roster, etc. For the JWebCast application and its code please contact me. Please note that this applet is not fully functional and will not operate in the same fashion as the application (security issues). If you are experiencing problems viewing this Applet (status bar displays "class def not found"), please visit Sun's website and download the latest Java plug-in for your browser.


© Gfuss


import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.event.*;
import java.io.*;

/* Version: 1.6
 * WebCast.java - 13 Dec 2002 - Cory J. Goldfuss
 * Swing version of WebCast v0.3
 -------------------------------------------------
 * Modified 6 Jan 2003:
 * Changed save location
 -------------------------------------------------
 * Modified 9 Jan 2003:
 * Added menus, ability to load rosters, ability 
 * to enter file path location by hand.
 -------------------------------------------------
 * Modified 10 Jan 2003:
 * Added better roster handling with add in front of
 * a name and delete a person from the roster.  
 * To do: 
 * Fix rebuilding of JComboBoxes after inserting 
 * in front of on roster.
  -------------------------------------------------
 * Modified 13 Jan 2003:
 * Fixed JComboBox problem.  Removed ActionListener, 
 * modify the list, re-added ActionListener.  Prevents
 * NullPointerException being thrown.  Added dialog setup
 * boxes to allow user to enter file name, school abbrev
 * and so on.  Removed static defined home abbrev of BC.
 * User can now specify home and visitor abbrev.  This means
 * I can sell it to other schools.
 */
public class WebCast extends JApplet implements ActionListener
{
    private static String saveLocation = "C:\\";
    private String oppScore, homeScore, fileName, time, inGameNotes, versus = "VX", home = "HX";
    private String selectedPlayer = "", addPlayer = "  ";
    private boolean bcFlag = false, oppFlag = false;
    private JList bcRosterLst, oppRosterLst;
    private DefaultListModel bcListModel, oppListModel;
    private LineBorder myBorder = new LineBorder( new Color(255, 255, 128), 2 );
    private TitledBorder rosterBorder = new TitledBorder( myBorder, "  Roster Management  " );
    // Declare menu items
    private static JMenuBar ourMenu = new JMenuBar(); //made static to add to frame
    private JMenu fileMenu = new JMenu("File");
    private JMenu helpMenu = new JMenu("Help");
    private JMenuItem aboutProg = new JMenuItem("About");
    private JMenu clearMenu = new JMenu("Clear Rosters");
    private JMenuItem clearHomeRoster = new JMenuItem("Home Roster");
    private JMenuItem clearOppRoster = new JMenuItem("Visitor Roster");
    private JMenu loadMenu = new JMenu("Load Rosters");
    private JMenuItem openHomeRoster = new JMenuItem("Home Roster");
    private JMenuItem openOppRoster = new JMenuItem("Visitor Roster");
    private JMenuItem exitProg = new JMenuItem("Exit");    
	
	public void init()
	{
		// This line prevents the "Swing: checked access to system event queue" message seen in some browsers.
		getRootPane().putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
		
        bcListModel = new DefaultListModel();
        oppListModel = new DefaultListModel();
        bcRosterLst = new JList( bcListModel );
        oppRosterLst = new JList( oppListModel );
        
	    bcRosterScroll = new JScrollPane( bcRosterLst );
	    oppRosterScroll = new JScrollPane( oppRosterLst );
		
		// This code is automatically generated by Visual Cafe when you add
		// components to the visual environment. It instantiates and initializes
		// the components. To modify the code, only use code syntax that matches
		// what Visual Cafe can generate, or Visual Cafe may be unable to back
		// parse your Java file into its visual environment.
		//{{INIT_CONTROLS
		getContentPane().setLayout(null);
		setSize(744,524);
		onePointBtn.setText("1pt");
		onePointBtn.setActionCommand("1pt");
		onePointBtn.setToolTipText("Free Throw");
		onePointBtn.setFocusPainted(false);
		getContentPane().add(onePointBtn);
		onePointBtn.setBackground(new java.awt.Color(255,255,128));
		onePointBtn.setBounds(84,168,68,24);
		foulBtn.setText("foul");
		foulBtn.setActionCommand("foul");
		foulBtn.setToolTipText("Foul");
		foulBtn.setFocusPainted(false);
		getContentPane().add(foulBtn);
		foulBtn.setBackground(new java.awt.Color(255,255,128));
		foulBtn.setBounds(168,168,68,24);
		twoPointBtn.setText("2pts");
		twoPointBtn.setActionCommand("2pts");
		twoPointBtn.setToolTipText("Field Goal");
		twoPointBtn.setFocusPainted(false);
		getContentPane().add(twoPointBtn);
		twoPointBtn.setBackground(new java.awt.Color(255,255,128));
		twoPointBtn.setBounds(168,132,68,24);
		threePointBtn.setText("3pts");
		threePointBtn.setActionCommand("3pts");
		threePointBtn.setToolTipText("Three pointer");
		threePointBtn.setFocusPainted(false);
		getContentPane().add(threePointBtn);
		threePointBtn.setBackground(new java.awt.Color(255,255,128));
		threePointBtn.setForeground(java.awt.Color.black);
		threePointBtn.setFont(new Font("Dialog", Font.BOLD, 12));
		threePointBtn.setBounds(84,132,72,24);
		bcPlayerChoice.setToolTipText("Home Players");
		bcPlayerChoice.setMaximumRowCount(25);
		getContentPane().add(bcPlayerChoice);
		bcPlayerChoice.setBackground(new java.awt.Color(255,255,128));
		bcPlayerChoice.setBounds(12,84,144,25);
		oppPlayerChoice.setToolTipText("Visiting Players");
		oppPlayerChoice.setMaximumRowCount(25);
		getContentPane().add(oppPlayerChoice);
		oppPlayerChoice.setBackground(new java.awt.Color(255,255,128));
		oppPlayerChoice.setBounds(168,84,144,25);
		bcScoreFld.setText("0");
		bcScoreFld.setAutoscrolls(false);
		bcScoreFld.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
		bcScoreFld.setToolTipText("Home Score");
		getContentPane().add(bcScoreFld);
		bcScoreFld.setFont(new Font("Dialog", Font.PLAIN, 24));
		bcScoreFld.setBounds(12,132,60,36);
		oppScoreFld.setText("0");
		oppScoreFld.setAutoscrolls(false);
		oppScoreFld.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
		oppScoreFld.setToolTipText("Visitor Score");
		getContentPane().add(oppScoreFld);
		oppScoreFld.setFont(new Font("Dialog", Font.PLAIN, 24));
		oppScoreFld.setBounds(252,132,60,36);
		gnScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		gnScrollPane.setOpaque(true);
		getContentPane().add(gnScrollPane);
		gnScrollPane.setBounds(12,216,300,216);
		inGameNotesTxt.setSelectionColor(new java.awt.Color(204,204,255));
		inGameNotesTxt.setAutoscrolls(false);
		inGameNotesTxt.setToolTipText("In Game Notes");
		gnScrollPane.getViewport().add(inGameNotesTxt);
		inGameNotesTxt.setBounds(0,0,297,213);
		timeFld.setText("20:00");
		timeFld.setSelectionColor(new java.awt.Color(204,204,255));
		timeFld.setSelectedTextColor(java.awt.Color.black);
		timeFld.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
		timeFld.setToolTipText("Time Remaining");
		getContentPane().add(timeFld);
		timeFld.setFont(new Font("Dialog", Font.PLAIN, 24));
		timeFld.setBounds(120,24,85,37);
		bcRadioBtn.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
		bcRadioBtn.setText("Home");
		bcRadioBtn.setActionCommand("BC");
		bcRadioBtn.setSelected(true);
		bcRadioBtn.setToolTipText("Add player for BC");
		bcRadioBtn.setFocusPainted(false);
		getContentPane().add(bcRadioBtn);
		bcRadioBtn.setBounds(384,432,60,24);
		oppRadioBtn.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
		oppRadioBtn.setText("Visitor");
		oppRadioBtn.setActionCommand("Opp");
		oppRadioBtn.setToolTipText("Add player for opp");
		oppRadioBtn.setFocusPainted(false);
		getContentPane().add(oppRadioBtn);
		oppRadioBtn.setBounds(384,456,60,24);
		fileNameFld.setText("filename.inc");
		fileNameFld.setToolTipText("File Name");
		getContentPane().add(fileNameFld);
		fileNameFld.setBounds(216,468,120,24);
		createBtn.setText("Cast");
		createBtn.setActionCommand("Cast");
		createBtn.setToolTipText("Write File");
		createBtn.setFocusPainted(false);
		createBtn.setMnemonic((int)'C');
		getContentPane().add(createBtn);
		createBtn.setBackground(new java.awt.Color(255,255,128));
		createBtn.setBounds(24,24,60,36);
		bcRosterScroll.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		getContentPane().add(bcRosterScroll);
		bcRosterScroll.setBounds(384,36,151,384);
		rosterPanel.setLayout(null);
		getContentPane().add(rosterPanel);
		rosterPanel.setBounds(372,12,330,480);
		oppRosterScroll.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		rosterPanel.add(oppRosterScroll);
		oppRosterScroll.setBounds(168,24,151,384);
		addPlayerBtn.setText("Add");
		addPlayerBtn.setActionCommand("Add");
		addPlayerBtn.setToolTipText("Add Player");
		addPlayerBtn.setFocusPainted(false);
		addPlayerBtn.setMnemonic((int)'A');
		rosterPanel.add(addPlayerBtn);
		addPlayerBtn.setBackground(new java.awt.Color(255,255,128));
		addPlayerBtn.setBounds(72,420,72,24);
		addPlayerFld.setToolTipText("Enter a player # and Name");
		rosterPanel.add(addPlayerFld);
		addPlayerFld.setBounds(156,420,160,24);
		deletePlayerBtn.setText("Delete");
		deletePlayerBtn.setActionCommand("Add");
		deletePlayerBtn.setToolTipText("Delete Player");
		deletePlayerBtn.setFocusPainted(false);
		rosterPanel.add(deletePlayerBtn);
		deletePlayerBtn.setBackground(new java.awt.Color(255,255,128));
		deletePlayerBtn.setBounds(72,444,72,24);
		fileLocationFld.setText("C:\\");
		fileLocationFld.setToolTipText("File Location");
		getContentPane().add(fileLocationFld);
		fileLocationFld.setBounds(12,468,192,24);
		pathLbl.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
		pathLbl.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
		pathLbl.setText("File path");
		getContentPane().add(pathLbl);
		pathLbl.setBackground(new java.awt.Color(255,255,128));
		pathLbl.setForeground(java.awt.Color.black);
		pathLbl.setBounds(12,444,60,21);
		fileNameLbl.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
		fileNameLbl.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
		fileNameLbl.setText("File name");
		getContentPane().add(fileNameLbl);
		fileNameLbl.setBackground(java.awt.Color.lightGray);
		fileNameLbl.setForeground(java.awt.Color.black);
		fileNameLbl.setBounds(216,444,60,21);
		//}}
		
	    
	    rosterBorder.setTitleColor( Color.black );
	    rosterPanel.setBorder( rosterBorder );
	    

		// setup our menu
		setJMenuBar( ourMenu ); //comment out for app
        ourMenu.setBackground( new Color( 255, 255, 128 ) );
		ourMenu.add(fileMenu);
		ourMenu.add(helpMenu);
		helpMenu.add( aboutProg );
		fileMenu.add(loadMenu);
		loadMenu.add(openHomeRoster);
		loadMenu.add(openOppRoster);
		//fileMenu.add(clearMenu);
		//clearMenu.add(clearHomeRoster);
		//clearMenu.add(clearOppRoster);
		fileMenu.add(new JSeparator());
		fileMenu.add(exitProg);
		fileMenu.setBackground( new Color( 255, 255, 128 ) );
		loadMenu.setBackground( new Color( 255, 255, 128 ) );
		clearMenu.setBackground( new Color( 255, 255, 128 ) );
		openHomeRoster.setBackground( new Color( 255, 255, 128 ) );
		openOppRoster.setBackground( new Color( 255, 255, 128 ) );
		clearHomeRoster.setBackground( new Color( 255, 255, 128 ) );
		clearOppRoster.setBackground( new Color( 255, 255, 128 ) );
		exitProg.setBackground( new Color( 255, 255, 128 ) );
		helpMenu.setBackground( new Color( 255, 255, 128 ) );
		aboutProg.setBackground( new Color( 255, 255, 128 ) );

		ButtonGroup group = new ButtonGroup();
        group.add(bcRadioBtn);
        group.add(oppRadioBtn);
        
		createBtn.addActionListener( this );
		bcPlayerChoice.addActionListener( this );
		oppPlayerChoice.addActionListener( this );
        
		addPlayerBtn.addActionListener( this );
		deletePlayerBtn.addActionListener( this );
		addPlayerFld.addActionListener( this );
		threePointBtn.addActionListener( this );
		twoPointBtn.addActionListener( this );
		onePointBtn.addActionListener( this );
		foulBtn.addActionListener( this );
		exitProg.addActionListener( this );
		aboutProg.addActionListener( this );
		openHomeRoster.addActionListener( this );
		openOppRoster.addActionListener( this );
		
		
		home = JOptionPane.showInputDialog( null, "Enter home team's abbreviation:", "Game Setup 1 of 4", JOptionPane.INFORMATION_MESSAGE );
		versus = JOptionPane.showInputDialog( null, "Enter visitor's abbreviation:", "Game Setup 2 of 4", JOptionPane.INFORMATION_MESSAGE );
        saveLocation = JOptionPane.showInputDialog( null, "Enter file path:", "Game Setup 3 of 4", JOptionPane.INFORMATION_MESSAGE );
        fileName = JOptionPane.showInputDialog( null, "Enter file name:", "Game Setup 4 of 4", JOptionPane.INFORMATION_MESSAGE );
		
		if ( home.trim().equalsIgnoreCase("") ){
		    home = "HX";
		}
		
		if ( versus.trim().equalsIgnoreCase("") ){
		    versus = "VX";
		}
		
		if ( fileName.trim().equalsIgnoreCase("") ){
		    fileNameFld.setText( "fileName.inc" );
		}
		else{
		    fileNameFld.setText( fileName.trim() );
		}
		if ( saveLocation.trim().equalsIgnoreCase("") ){
		    fileLocationFld.setText( "C:\\" );
		}
		else{
		    fileLocationFld.setText( saveLocation.trim() );
		}
		
	}
/*		public static void main( String[] args ){
        
        try {
            UIManager.setLookAndFeel(
                UIManager.getCrossPlatformLookAndFeelClassName());
        } catch (Exception e) {}
		JFrame f = new JFrame();
                WebCast myApplet = new WebCast();
		myApplet.setSize(741, 525);
		f.setContentPane( myApplet.getContentPane() );
		
		f.addWindowListener( new java.awt.event.WindowAdapter(){
			public void windowClosing( java.awt.event.WindowEvent e ){
				System.exit(0);
				};
			});

		f.pack();
		myApplet.init();
		f.setTitle( "WebCast v2.0" );
                f.setJMenuBar( ourMenu );
		f.setSize(755, 555);
		f.setVisible( true );
	}
*/
	//{{DECLARE_CONTROLS
	javax.swing.JButton onePointBtn = new javax.swing.JButton();
	javax.swing.JButton foulBtn = new javax.swing.JButton();
	javax.swing.JButton twoPointBtn = new javax.swing.JButton();
	javax.swing.JButton threePointBtn = new javax.swing.JButton();
	javax.swing.JComboBox bcPlayerChoice = new javax.swing.JComboBox();
	javax.swing.JComboBox oppPlayerChoice = new javax.swing.JComboBox();
	javax.swing.JTextField bcScoreFld = new javax.swing.JTextField();
	javax.swing.JTextField oppScoreFld = new javax.swing.JTextField();
	javax.swing.JScrollPane gnScrollPane = new javax.swing.JScrollPane();
	javax.swing.JTextPane inGameNotesTxt = new javax.swing.JTextPane();
	javax.swing.JTextField timeFld = new javax.swing.JTextField();
	javax.swing.JRadioButton bcRadioBtn = new javax.swing.JRadioButton();
	javax.swing.JRadioButton oppRadioBtn = new javax.swing.JRadioButton();
	javax.swing.JTextField fileNameFld = new javax.swing.JTextField();
	javax.swing.JButton createBtn = new javax.swing.JButton();
	javax.swing.JScrollPane bcRosterScroll = new javax.swing.JScrollPane();
	javax.swing.JPanel rosterPanel = new javax.swing.JPanel();
	javax.swing.JButton addPlayerBtn = new javax.swing.JButton();
	javax.swing.JScrollPane oppRosterScroll = new javax.swing.JScrollPane();
	javax.swing.JTextField addPlayerFld = new javax.swing.JTextField();
	javax.swing.JButton deletePlayerBtn = new javax.swing.JButton();
	javax.swing.JTextField fileLocationFld = new javax.swing.JTextField();
	javax.swing.JLabel pathLbl = new javax.swing.JLabel();
	javax.swing.JLabel fileNameLbl = new javax.swing.JLabel();
	//}}
	
	public void actionPerformed( ActionEvent e ){
	   if ( e.getSource() == bcPlayerChoice ){
	       selectedPlayer = home + bcPlayerChoice.getModel().getSelectedItem().toString().trim().substring( 2 );
	       bcFlag = true;
	       oppFlag = false;
	   }
	   
	   if ( e.getSource() == oppPlayerChoice ){
           selectedPlayer = versus + oppPlayerChoice.getModel().getSelectedItem().toString().trim().substring( 2 );
           oppFlag = true;
	       bcFlag = false;
	   }
	   
	   if ( e.getSource() == deletePlayerBtn ){
         String removePlayer = addPlayerFld.getText().trim();
           
         if( bcRadioBtn.isSelected() == true ){ //bc roster
           if ( removePlayer.length() > 0 ) {
            bcListModel.removeElement( "  " + removePlayer );
            bcPlayerChoice.removeItem( "  " + removePlayer );
           }
         }
         else{ //opp roster
           if ( removePlayer.length() > 0 ) {
            oppListModel.removeElement( "  " + removePlayer );
            oppPlayerChoice.removeItem( "  " + removePlayer );
           }
	     }
        addPlayerFld.setText( "" );
        addPlayerFld.requestFocus();
	   }
	   
       if ( e.getSource() == addPlayerFld ){ //append only option for speed
          if( !addPlayerFld.getText().trim().equalsIgnoreCase( "" ) ){
	        if( bcRadioBtn.isSelected() == true ){
	            addPlayer = "  " + addPlayerFld.getText().trim();
	            bcListModel.addElement( addPlayer );
	            bcPlayerChoice.addItem( addPlayer );
	        }
	        else{
	            addPlayer = "  " + addPlayerFld.getText().trim();
	            oppListModel.addElement( addPlayer );
	            oppPlayerChoice.addItem( addPlayer );
	        }
	      }
	    addPlayerFld.setText("");
	    addPlayerFld.requestFocus();
	    }
	   
       if ( e.getSource() == addPlayerBtn ){//must click button if doing special insert
          if( !addPlayerFld.getText().trim().equalsIgnoreCase( "" ) ){
	        if( bcRadioBtn.isSelected() == true ){//homeRoster
	            int selected = bcRosterLst.getSelectedIndex();
	            addPlayer = "  " + addPlayerFld.getText().trim();
	            if ( selected >= 0 ){//someone is selected so insert before the selection
	                bcListModel.add( selected, addPlayer );
	                bcPlayerChoice.removeActionListener( this );//prevent error when calling removeAllItems()
	                 bcPlayerChoice.removeAllItems();
	                for ( int i = 0; i < bcRosterLst.getModel().getSize(); i++ ){
	                  String rebuildList;
	                  rebuildList = bcListModel.getElementAt( i ).toString();
	                  bcPlayerChoice.addItem( rebuildList );
	                }
	                bcPlayerChoice.addActionListener( this );//replace actionListener
	            }
	            else{//other wise no one was selected prior to adding so append
	                bcListModel.addElement( addPlayer );
	                bcPlayerChoice.addItem( addPlayer );
	            }
	            
	        }
	        else{//visitor roster same procedure and checking as above
	            int selected = oppRosterLst.getSelectedIndex();
	            addPlayer = "  " + addPlayerFld.getText().trim();
	            if ( selected >=0 ){
	                oppListModel.add( selected, addPlayer );
	                oppPlayerChoice.removeActionListener( this );
	                oppPlayerChoice.removeAllItems();
	                
	                for ( int i = 0; i < oppRosterLst.getModel().getSize(); i++ ){
	                    String rebuildList;
	                    rebuildList = oppListModel.getElementAt( i ).toString();
	                    oppPlayerChoice.addItem( rebuildList );
	                }
	                oppPlayerChoice.addActionListener( this );
	            }
	            else{
	                oppListModel.addElement( addPlayer );
	                oppPlayerChoice.addItem( addPlayer );
	            }
	        }
	      }
	   
	      addPlayerFld.setText("");
	      addPlayerFld.requestFocus();
	        
	    }
	    Code truncated becasue it contains HTML and ASP code.