コード例 #1
0
ファイル: NewsGUI.java プロジェクト: adhorrig/World-Cup
  private void newsBtn2ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_newsBtn2ActionPerformed
    // TODO add your handling code here:
    displayText = newsBtn2.getText();
    newsArea.setText(
        NewsAdd.NewsArrList.get(1).headlinetext
            + "\n\n"
            + NewsAdd.NewsArrList.get(1).fullarticletext);
    // reference: http://stackoverflow.com/questions/4801386/how-do-i-add-an-image-to-a-jbutton
    try {
      Image img;
      img = ImageIO.read(getClass().getResource("news_images/1002p.png"));
      // (This part by Nilsson Denver) keeps only current news article active, closes all other news
      // stories and resources
      newsBtnUpdates.setIcon(new ImageIcon(img));
      newsBtnUpdates.setText("");
      newsBtn1.setText(NewsAdd.NewsArrList.get(0).headlinetext);
      newsBtn2.setText(" ");
      newsBtn3.setText(NewsAdd.NewsArrList.get(2).headlinetext);
      newsBtn1.setIcon(null);
      newsBtn2.setIcon(new ImageIcon(img));
      newsBtn3.setIcon(null);
    } catch (IOException ex) {

    }
  } // GEN-LAST:event_newsBtn2ActionPerformed
コード例 #2
0
ファイル: NewsGUI.java プロジェクト: adhorrig/World-Cup
  /** Creates new form NewsMenuGUI2 */
  public NewsGUI() {
    initComponents();
    getContentPane().setBackground(new Color(255, 255, 0));
    // Start of Loading the data file
    // Declare objects required to read from file
    File inFile;
    FileInputStream fStream;
    ObjectInputStream oStream;
    // use a try statement

    try {
      // create objects
      inFile = new File("news.data");
      fStream = new FileInputStream(inFile);
      oStream = new ObjectInputStream(fStream);
      // read arrayList from file

      NewsArrList = (ArrayList<NewsOther>) oStream.readObject();
      // loop through the ArrayList
      // for (int i = 0; i<qList.size(); i =i+1){
      //            for(NewsOther x:NewsArrList){
      // Print the contents of each object
      //                JOptionPane.showMessageDialog(null,"Item 1 "+x.getArticlenbr());
      //            }

      // close the stream
      oStream.close();
    } // catch IOException
    catch (IOException e) {
      System.out.println(e);
    } // catch classNotFoundException
    catch (ClassNotFoundException ex) {
      System.out.println(ex);
    }

    // End of Data File Loading
    if (NewsAdd.NewsArrList != null) {
      if (NewsAdd.NewsArrList.size() > 0) {
        newsBtn1.setText(NewsAdd.NewsArrList.get(0).headlinetext);
        newsBtn2.setText(NewsAdd.NewsArrList.get(1).headlinetext);
        newsBtn3.setText(NewsAdd.NewsArrList.get(2).headlinetext);
      }
    }
  }