/** * This method is called from within the constructor to initialize the form. WARNING: Do NOT * modify this code. The content of this method is always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jButton2 = new javax.swing.JButton(); jSeparator1 = new javax.swing.JSeparator(); jLabel2 = new javax.swing.JLabel(); teamOneScore = new javax.swing.JLabel(); teamTwoScore = new javax.swing.JLabel(); Team1Name = new javax.swing.JLabel(); Team2Name = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); team1GoalsArea = new javax.swing.JTextArea(); jScrollPane2 = new javax.swing.JScrollPane(); team2GoalsArea = new javax.swing.JTextArea(); jSeparator2 = new javax.swing.JSeparator(); jLabel1 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); setBackground(new java.awt.Color(255, 255, 255)); setPreferredSize(new java.awt.Dimension(632, 432)); jButton2.setText("Start..."); jButton2.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jLabel2.setFont(new java.awt.Font("Lucida Grande", 0, 36)); // NOI18N jLabel2.setText(":"); teamOneScore.setFont(new java.awt.Font("Lucida Grande", 0, 64)); // NOI18N teamOneScore.setText("0"); teamTwoScore.setFont(new java.awt.Font("Lucida Grande", 0, 64)); // NOI18N teamTwoScore.setText("0"); Team1Name.setFont(new java.awt.Font("Lucida Grande", 0, 48)); // NOI18N Team1Name.setText("Team 1"); Team2Name.setFont(new java.awt.Font("Lucida Grande", 0, 48)); // NOI18N Team2Name.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); Team2Name.setText("Team 2"); team1GoalsArea.setColumns(20); team1GoalsArea.setRows(5); jScrollPane1.setViewportView(team1GoalsArea); team2GoalsArea.setColumns(20); team2GoalsArea.setRows(5); jScrollPane2.setViewportView(team2GoalsArea); jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL); jLabel1.setText("Name"); jLabel3.setText("Name"); jLabel4.setText("Time"); jLabel5.setText("Time"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout .createSequentialGroup() .addContainerGap() .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jSeparator1) .addGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton2) .addComponent( Team1Name, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(teamOneScore) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel2) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(teamTwoScore) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent( Team2Name, javax.swing.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE))) .addContainerGap()) .addGroup( layout .createSequentialGroup() .addGap(35, 35, 35) .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup( layout .createSequentialGroup() .addComponent(jLabel1) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel4)) .addComponent( jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(125, 125, 125) .addComponent( jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout .createSequentialGroup() .addComponent(jLabel3) .addGap(75, 75, 75) .addComponent(jLabel5)) .addComponent( jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(28, 28, 28))); layout.setVerticalGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout .createSequentialGroup() .addContainerGap() .addComponent(jButton2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(teamOneScore) .addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout .createSequentialGroup() .addComponent( jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(16, 16, 16)) .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(teamTwoScore) .addComponent(Team1Name) .addComponent(Team2Name))) .addComponent( jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE) .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(jLabel4)) .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(jLabel5))) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(0, 0, Short.MAX_VALUE)) .addComponent( jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(54, 54, 54))); } // </editor-fold>//GEN-END:initComponents
private void parseXML(URL url) { /* Here I am parsing from an XML File, using Dom4J framework. the file (test.xml) is setup so it holds info for the current game On parsing from the file I will populate the fields for: Teams, scores, goals scored and players who scored. Running tight on time, this will be fully implemented next week. This file will not be a local file, but a downloaded stream from server */ String team1G = "", team2G = ""; try { SAXReader reader = new SAXReader(); Document document = reader.read(url); Element rootElement = document.getRootElement(); System.out.println("Root Element: " + rootElement.getName()); for (Iterator i = rootElement.elementIterator(); i.hasNext(); ) { Element element = (Element) i.next(); System.out.println(element.getName()); for (Iterator i2 = element.elementIterator(); i2.hasNext(); ) { Element element2 = (Element) i2.next(); // Node is a game - parse game if ("isLive".equals(element2.getName())) { if ("false".equals((String) element2.getData())) { // If its not live dont show System.out.println("Game is not live, revert to Sim"); revertToSimulation(); break; } } if ("team1".equals(element2.getName())) { // Node is Team 1 - parse info for (Iterator team1Iterator = element2.elementIterator(); team1Iterator.hasNext(); ) { Element team1 = (Element) team1Iterator.next(); if ("name".equals((String) team1.getName())) { Team1Name.setText((String) team1.getData()); } if ("score".equals((String) team1.getName())) { teamOneScore.setText((String) team1.getData()); } if ("goals".equals((String) team1.getName())) { /* Parse the goals scored by this team */ for (Iterator team1GoalsIterator = team1.elementIterator(); team1GoalsIterator.hasNext(); ) { Element goals = (Element) team1GoalsIterator.next(); if ("goal".equals((String) goals.getName())) { for (Iterator t1gIgoalIterator = goals.elementIterator(); t1gIgoalIterator.hasNext(); ) { Element goal = (Element) t1gIgoalIterator.next(); if ("player".equals((String) goal.getName())) { // Parse the Player team1G = team1G + (String) goal.getData(); } if ("time".equals((String) goal.getName())) { // Parse the Time of Score team1G = team1G + " : " + (String) goal.getData() + "\n"; } } } } } } } if ("team2".equals(element2.getName())) { // Node is Team 2 - parse info for (Iterator team2Iterator = element2.elementIterator(); team2Iterator.hasNext(); ) { Element team2 = (Element) team2Iterator.next(); if ("name".equals((String) team2.getName())) { Team2Name.setText((String) team2.getData()); } if ("score".equals((String) team2.getName())) { teamTwoScore.setText((String) team2.getData()); } if ("goals".equals((String) team2.getName())) { /* Parse the goals scored by thie team */ for (Iterator team2GoalsIterator = team2.elementIterator(); team2GoalsIterator.hasNext(); ) { Element goals = (Element) team2GoalsIterator.next(); if ("goal".equals((String) goals.getName())) { /* Parse a Goal */ for (Iterator t2gIgoalIterator = goals.elementIterator(); t2gIgoalIterator.hasNext(); ) { Element goal = (Element) t2gIgoalIterator.next(); if ("player".equals((String) goal.getName())) { /* Parse the Player */ team2G = team2G + (String) goal.getData(); } if ("time".equals((String) goal.getName())) { /* Parse the time of score */ team2G = team2G + " : " + (String) goal.getData() + "\n"; } } } } } } } } } } catch (DocumentException e) { System.out.print(e.getMessage()); } team1GoalsArea.setText(team1G); team2GoalsArea.setText(team2G); }