Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-07-2008, 10:06 AM
Java Tip's Avatar
Moderator
 
Join Date: Nov 2007
Posts: 1,691
Rep Power: 5
Java Tip will become famous soon enoughJava Tip will become famous soon enough
Default Adding file contents to Choice component
The applet presented below reads a file and adds its contents to Choice component.

Code:
import java.applet.*;
import java.awt.*;
import java.net.*;
import java.io.*;

public class ReadDataInChoice extends Applet {
  Choice myChoice;
  
  public void init() {
    myChoice  = new java.awt.Choice();
    add(myChoice);
    readFile("dataforchoice.txt");
  }
  public void readFile(String f) {
    try {
      String anItem = "";
      URL source = new URL(getCodeBase(), f);
      BufferedReader in = 
         new BufferedReader(new InputStreamReader(source.openStream()));
      while(null != (anItem = in.readLine())) {
        myChoice.add(anItem);
      }
      in.close();
    }
    catch(Exception e) {
     e.printStackTrace();
    }
  }
}
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Viewing contents of zip file Java Tip Java Tips 0 03-03-2008 06:16 PM
Concatenation file contents Java Tip Java Tips 1 02-07-2008 02:29 PM
Reading file contents (BufferedReader) Java Tip Java Tips 0 02-07-2008 10:00 AM
Viewing contents of JAR file Java Tip Java Tips 0 12-21-2007 04:12 PM
viewing the contents of a text file in JTextArea warship New To Java 0 07-17-2007 03:29 PM


All times are GMT +2. The time now is 11:21 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org