⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 源代码.java

📁 利用JAVA语言实现对NBA信息的管理系统。里面有完整的英文说明功能及文档。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
      
      //set selectJComboBox
      // set up eventJComboBox
      selectJComboBox = new JComboBox();
      selectJComboBox.setBounds( 135, 30, 150, 20 );
      //selectJComboBox.addItem( "----" );
      windowJPanel1.add( selectJComboBox );
      selectJComboBox.addActionListener(      
         new ActionListener() // anonymous inner class
         {
            // event handler called when eventJComboBox is changed
            public void actionPerformed( ActionEvent event )
            {
               selectJComboActionPerformed( event );
            }            
         } // end anonymous inner class
         
      ); // end call to addActionListener     
      
      // set up a1IconJLabel
      logoJLabel = new JLabel();
      logoJLabel.setIcon( new ImageIcon( "images/NBA.png"));
      logoJLabel.setBounds( 20, 65, 420, 280 );
      windowJPanel1.add( logoJLabel );


      descriptionJLabel = new JLabel();
      descriptionJLabel.setBounds(300,65,100,20);
      descriptionJLabel.setText("Description");
      windowJPanel1.add(descriptionJLabel);
      
      
      // set up descriptionJTextArea
      descriptionJTextArea = new JTextArea();
      descriptionJTextArea.setText("");
      descriptionJScrollPane = new JScrollPane( 
         descriptionJTextArea );
      descriptionJScrollPane.setBounds( 290, 85, 160, 250 );
      descriptionJScrollPane.setVerticalScrollBarPolicy( 
         JScrollPane.VERTICAL_SCROLLBAR_ALWAYS );
      descriptionJTextArea.setLineWrap( true );
      descriptionJTextArea.setWrapStyleWord( true );
      descriptionJTextArea.setEditable( false );
      windowJPanel1.add( descriptionJScrollPane );
      
      //set rankListJButton to show the rankList ( Using the sort Algorithm)
      rankListJButton = new JButton();
      rankListJButton.setBounds( 20, 350, 340, 20 );
      rankListJButton.setText( "All Teams RankList" );
      windowJPanel1.add( rankListJButton );
      rankListJButton.addActionListener(
         new ActionListener() // anonymous inner class
         {
            // event handler called when previousJButton is clicked
            public void actionPerformed( ActionEvent event )
            {
               rankListJButtonActionPerformed(event);
            }

         } // end anonymous inner class
      ); // end call to addActionListener
      
      //set windowJPanel2 
      windowJPanel2 = new JPanel();
      windowJPanel2.setBounds( 10, 450, 460, 250 );
      windowJPanel2.setBorder( new TitledBorder( "Games Information" ) );
      windowJPanel2.setLayout( null );
      contentPane.add( windowJPanel2 );  
      
      queryResultJPanel = new JPanel();
      queryResultJPanel.setBounds( 10, 30, 220, 200 );
      queryResultJPanel.setBorder( new TitledBorder( new LineBorder( Color.GRAY ) ) );
      queryResultJPanel.setLayout( null );
      windowJPanel2.add( queryResultJPanel );  
      
      
       //set queryResultJLabel 
      queryResultJLabel = new JLabel();
      queryResultJLabel.setBounds(60,10,120,20);
      queryResultJLabel.setText("Add Result");
      queryResultJPanel.add(queryResultJLabel); 
      
      //set timeJLabel
      timeJLabel = new JLabel();
      timeJLabel.setBounds(10,30,50,10);
      timeJLabel.setText("Date:");
      queryResultJPanel.add(timeJLabel); 
      
      //set yearJLabel 
      yearJLabel = new JLabel();
      yearJLabel.setBounds(10,50,30,10);
      yearJLabel.setText("Y:");
      queryResultJPanel.add(yearJLabel); 
      
      // set up yearJSpinner
      yearJSpinner = new JSpinner( 
         new SpinnerNumberModel( 2008,2000 , 2999, 1 ) );
      yearJSpinner.setBounds( 25, 45, 50, 20 );
      queryResultJPanel.add( yearJSpinner );
      
      //set monthJLabel
      monthJLabel = new JLabel();
      monthJLabel .setBounds(80,50,20,10);
      monthJLabel .setText("m:");
      queryResultJPanel.add(monthJLabel ); 
      
      // set up monthJSpinner
      monthJSpinner = new JSpinner( 
         new SpinnerNumberModel( 1,1 , 12, 1 ) );
      monthJSpinner.setBounds( 100, 45, 45, 20 );
      queryResultJPanel.add( monthJSpinner );
      
      //set dateJLabel 
      dateJLabel = new JLabel();
      dateJLabel .setBounds(150,50,20,10);
      dateJLabel .setText("d:");
      queryResultJPanel.add(dateJLabel ); 
      
      // set up dateJSpinner
      dateJSpinner = new JSpinner( 
         new SpinnerNumberModel( 1,1 , 31, 1 ) );
      dateJSpinner.setBounds( 165, 45, 45, 20 );
      queryResultJPanel.add( dateJSpinner );
            
      //set selectJComboBox
      teamAJComboBox = new JComboBox();
      teamAJComboBox.setBounds( 10, 75, 90, 20 );
      queryResultJPanel.add( teamAJComboBox );
      teamAJComboBox.addActionListener(      
         new ActionListener() // anonymous inner class
         {
            // event handler called when eventJComboBox is changed
            public void actionPerformed( ActionEvent event )
            {
               teamAJComboBoxActionPerformed( event );
            }
            
         } // end anonymous inner class
         
      ); // end call to addActionListener 
      //set up vsJLabel
      vsJLabel = new JLabel();
      vsJLabel .setBounds(103,80,20,10);
      vsJLabel .setText("VS");
      queryResultJPanel.add(vsJLabel );
      
      // set up teamBJComboBox
      teamBJComboBox = new JComboBox();
      teamBJComboBox.setBounds( 120, 75, 90, 20 );
      queryResultJPanel.add( teamBJComboBox );
      teamBJComboBox.addActionListener(      
         new ActionListener() // anonymous inner class
         {
            // event handler called when eventJComboBox is changed
            public void actionPerformed( ActionEvent event )
            {
               teamBJComboBoxActionPerformed( event );
            }
            
         } // end anonymous inner class
         
      ); // end call to addActionListener 
      
      //set scoreJLabel 
      scoreJLabel = new JLabel();
      scoreJLabel .setBounds(10,120,40,10);
      scoreJLabel .setText("Score:");
      queryResultJPanel.add(scoreJLabel );
      
      // set up scoreAJTextField
      scoreAJTextField = new JTextField();
      scoreAJTextField.setText( "0" );
      scoreAJTextField.setBounds( 50, 115, 50, 20 );
      scoreAJTextField.setHorizontalAlignment( JTextField.CENTER );
      queryResultJPanel.add( scoreAJTextField );
      
      //set vssJLabel 
      vssJLabel = new JLabel();
      vssJLabel .setBounds(103,120,20,10);
      vssJLabel .setText("VS");
      queryResultJPanel.add(vssJLabel );
      
      // set up scoreBJTextField
      scoreBJTextField = new JTextField();
      scoreBJTextField.setText( "0" );
      scoreBJTextField.setBounds( 120, 115, 50, 20 );
      scoreBJTextField.setHorizontalAlignment( JTextField.CENTER );
      queryResultJPanel.add( scoreBJTextField );
      
      
      
      enterGameJButton = new JButton();
      enterGameJButton.setBounds( 20, 170, 150, 20 );
      enterGameJButton.setText( "Enter" );
      queryResultJPanel.add( enterGameJButton );
      enterGameJButton.addActionListener(
         new ActionListener() // anonymous inner class
         {
            // event handler called when previousJButton is clicked
            public void actionPerformed( ActionEvent event )
            {
               enterGameJButtonActionPerformed(event);
            }

         } // end anonymous inner class

      ); // end call to addActionListener
      
      addResultJPanel = new JPanel();
      addResultJPanel.setBounds( 250, 30, 200, 200 );
      addResultJPanel.setBorder( new TitledBorder( new LineBorder( Color.GRAY ) ) );
      addResultJPanel.setLayout( null );
      windowJPanel2.add( addResultJPanel );  
      
      //set adddateJLabel 
      adddateJLabel = new JLabel();
      adddateJLabel.setBounds(40,10,150,20);
      adddateJLabel.setText("Query Result");
      addResultJPanel.add( adddateJLabel );
      
      // setaddYear JLabel
      addYearJLabel = new JLabel();
      addYearJLabel.setBounds(10,30,80,20);
      addYearJLabel.setText("Selete Year:");
      addResultJPanel.add( addYearJLabel );
      
      // set up dateJSpinner
      addYearJSpinner = new JSpinner( 
         new SpinnerNumberModel( 2008,2000 , 2999, 1 ) );
      addYearJSpinner.setBounds( 85, 30, 80, 20 );
      addResultJPanel.add( addYearJSpinner );
      
      // set up JLabel
      addMonthJLabel = new JLabel();
      addMonthJLabel.setBounds(10,50,80,20);
      addMonthJLabel.setText("Selete Month:");
      addResultJPanel.add( addMonthJLabel );
      
      // set up dateJSpinner
      addMonthJSpinner = new JSpinner( 
         new SpinnerNumberModel( 1,1 , 12, 1 ) );
      addMonthJSpinner.setBounds( 85, 50, 80, 20 );
      addResultJPanel.add( addMonthJSpinner );
      
      // set up JLabel
      addDateJLabel = new JLabel();
      addDateJLabel.setBounds(10,70,80,20);
      addDateJLabel.setText("Selete Month:");
      addResultJPanel.add( addDateJLabel );
      
      // set up dateJSpinner
      addDateJSpinner = new JSpinner( 
         new SpinnerNumberModel( 1,1 , 31, 1 ) );
      addDateJSpinner.setBounds( 85, 70, 80, 20 );
      addResultJPanel.add( addDateJSpinner );
      
      // set up enterQueryJButton
      enterQueryJButton = new JButton();
      enterQueryJButton.setBounds( 20, 95, 150, 20 );
      enterQueryJButton.setText( "Enter" );
      addResultJPanel.add( enterQueryJButton );
      enterQueryJButton.addActionListener(
         new ActionListener() // anonymous inner class
         {
            // event handler called when previousJButton is clicked
            public void actionPerformed( ActionEvent event )
            {
               enterQueryJButtonActionPerformed(event);
            }

         } // end anonymous inner class

      ); // end call to addActionListener
      
      // set up descriptionJTextArea
      addDescriptionJTextArea = new JTextArea();
      addDescriptionJTextArea.setText("");
      addDescriptionJScrollPane = new JScrollPane( 
         addDescriptionJTextArea );
      addDescriptionJScrollPane.setBounds( 10, 120, 180, 75 );
      addDescriptionJScrollPane.setVerticalScrollBarPolicy( 
         JScrollPane.VERTICAL_SCROLLBAR_ALWAYS );
      addDescriptionJTextArea.setLineWrap( true );
      addDescriptionJTextArea.setWrapStyleWord( true );
      addDescriptionJTextArea.setEditable( false );
      addResultJPanel.add( addDescriptionJScrollPane );
   
      // set up readFromFileJButton 
      saveToFileJButton = new JButton();
      saveToFileJButton.setBounds(10,720,300,20);
      saveToFileJButton.setText("Save to File");
      contentPane.add(saveToFileJButton);       
      saveToFileJButton.addActionListener(
      	new ActionListener() // anonymous inner class
         {
            // event handler called when previousJButton is clicked
            public void actionPerformed( ActionEvent event )
            {            	
               saveToFileJButtonActionPerformed(event);
            }

         } // end anonymous inner class

      ); // end call to addActionListener
      
      quitJButton = new JButton();
      quitJButton.setBounds(320,720,150,20);
      quitJButton.setText("Quit");
      contentPane.add(quitJButton);       
      quitJButton.addActionListener(
      	new ActionListener() // anonymous inner class
         {
            // event handler called when previousJButton is clicked
            public void actionPerformed( ActionEvent event )
            {            	
               quitJButtonActionPerformed(event);
            }

         } // end anonymous inner class

      ); // end call to addActionListener        
      
      setTitle( "Sports Result DataBase -- NBA" ); // set title bar string
      setSize( 500, 780 );       // set window size
      setVisible( true );        // display window   
   } // end method createUserInterface

   // read event information from a file for a given data
   private void readFromFileJButtonActionPerformed(ActionEvent event)
   {
   	database.readFromFile(); 
   	selectJComboBox.removeAllItems();
   	teamAJComboBox.removeAllItems();
   	teamBJComboBox.removeAllItems();
   	TeamDetails tmp;   	
   	descriptionJTextArea.setText("");
   	for(int i = 0; i < database.getTeamsNumber(); i++)
   	{
   		tmp = new TeamDetails();
   		tmp = database.getTeam(i);
   		selectJComboBox.addItem(tmp.getName());
   		teamAJComboBox.addItem(tmp.getName());
   		teamBJComboBox.addItem(tmp.getName());
   	}
   	descriptionJTextArea.setText("");
   	logoJLabel.setIcon( new ImageIcon( "images/NBA.png"));
   	JOptionPane.showMessageDialog(null, "Read File Success!");
   } // end method 
   
   // action when click the button selectJComboActionPerformed
   private void selectJComboActionPerformed(ActionEvent event)
   {   	
   	int selectEvent = selectJComboBox.getSelectedIndex();
    TeamDetails tmp = new TeamDetails();
   	tmp = database.getTeam(selectEvent);
   	String content = database.queryTeamsDetails(tmp.getName());
   	descriptionJTextArea.setText(content);
   	logoJLabel.setIcon( new ImageIcon("images/" + tmp.getPhotoId()));
   	logoJLabel.setBounds( 20, 65, 320, 280 );   	
   } // end method of selectJComboActionPerformed
   
   // action when click the button rankListJButton
   private void rankListJButtonActionPerformed(ActionEvent event)
   {
   	database.update();
   	String contents = "Rank      Team" + "\n";
   	for(int i = 0; i < database.getTeamsNumber(); i++)
   	{
   		contents = contents + String.valueOf(i + 1) + "               " + database.getTeam(i).getName() + "\n";
   	}
   	descriptionJTextArea.setText(contents);
   	logoJLabel.setIcon( new ImageIcon("images/NBA.png"));
   }
   
   private void enterGameJButtonActionPerformed(ActionEvent event)
   {
   	GameResult tmp = new GameResult();
   	String contents;
   	int score1, score2, y, m, d;
   	y = (Integer)yearJSpinner.getValue();
   	m = (Integer)monthJSpinner.getValue();
   	d = (Integer)dateJSpinner.getValue();
   	contents = scoreAJTextField.getText();
   	score1 = Integer.parseInt(contents);
   	contents = scoreBJTextField.getText();
   	score2 = Integer.parseInt(contents);
   	if( !(m == 1 || m == 3 ||m == 5 ||m == 7 ||m == 9 ||m == 10 ||m == 12) &&(d == 31)) 
   	{
   		JOptionPane.showMessageDialog(null, "The date is illegal!");
   		return ;
   	}
   	if(m == 2 && d >= 29)
   	{
   		if(y %4 != 0 || (y % 100 == 0 && y %400 != 0))
   		{
   			JOptionPane.showMessageDialog(null, "There is only 28 days on February in " + y);
   			return ;
   		}
   		else if(d >= 30)
   		{
   			JOptionPane.showMessageDialog(null, "There is only 29 days on February in " + y);
   			return ;
   		}
   	}   	
   	tmp.setResult(str1,str2,score1,score2,y,m,d);
   	database.addNewGameResult(tmp);
   	JOptionPane.showMessageDialog(null, "Add Success!");   	
   }
   
   // action when click the teamAJComboBox
   private void teamAJComboBoxActionPerformed(ActionEvent enent)
   {
   	int selectEvent = teamAJComboBox.getSelectedIndex();
   	TeamDetails tmp = new TeamDetails();
   	tmp = database.getTeam(selectEvent);
   	str1 = tmp.getName();
   } // end method teamAJComboBoxActionPerformed
   
   // action when click the teamBJComboBox
   private void teamBJComboBoxActionPerformed(ActionEvent enent)
   {
   	int selectEvent = teamBJComboBox.getSelectedIndex();
   	TeamDetails tmp = new TeamDetails();
   	tmp = database.getTeam(selectEvent);
   	str2 = tmp.getName();
   }  // end method teamBJComboBoxActionPerformed
   
   // action when click the enterQueryJButton
   private void enterQueryJButtonActionPerformed(ActionEvent event)
   {
   	Integer y = (Integer)addYearJSpinner.getValue();
   	Integer m = (Integer)addMonthJSpinner.getValue();
   	Integer d = (Integer)addDateJSpinner.getValue();
   	if( !(m == 1 || m == 3 ||m == 5 ||m == 7 ||m == 9 ||m == 10 ||m == 12) &&(d == 31)) 
   	{
   		JOptionPane.showMessageDialog(null, "The date is illegal!");
   		return ;
   	}
   	if(m == 2 && d >= 29)
   	{
   		if(y %4 != 0 || (y % 100 == 0 && y %400 != 0))
   		{
   			JOptionPane.showMessageDialog(null, "There is only 28 days on February in " + y);
   			return ;
   		}
   		else if(d >= 30)
   		{
   			JOptionPane.showMessageDialog(null, "There is only 29 days on February in " + y);
   			return ;
   		}
   	} 
   	
   	String str = database.queryResult(y,m,d);
   	if(str.length() <= 16) str = "No games today!";  	
   	addDescriptionJTextArea.setText(str);
   }
   
   // quit the system when you click the quitJButton
   private void quitJButtonActionPerformed( ActionEvent event )
   {   	
   	System.exit(0);
   } // end method quitJButtonActionPerformed
   
   // save the information when click the saveToFileJButton
   private void saveToFileJButtonActionPerformed(ActionEvent event) 
   {
   	database.writeToFile();
   	JOptionPane.showMessageDialog(null, " Save success!");
   	reset();
   }  // end method saveToFileJButtonActionPerformed
   
   // reset the Container
   private void reset()
   {
   	descriptionJTextArea.setText("");
   	addDescriptionJTextArea.setText("");
   	logoJLabel.setIcon( new ImageIcon( "images/NBA.png"));   	
   } 
   
   // main method
   public static void main( String args[] ) throws IOException
   {   	  
      SportsResultDataBase application = new SportsResultDataBase();
      application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
   } // end method main
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -