Results 1 to 4 of 4
  1. #1
    bboardlol is offline Member
    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0

    Default New to Applets; not sure how to implement JList from existing program

    Hi,

    I did a program that spits out airplane trips based on miles & months read in from a .txt file.
    Now I need to make it into an applet using JList.

    I understand that to make a JList I need to have something like
    destinationList = new JList(cityNames) but am stuck on how to actually implement it.

    I'm not sure how to start going about this... very newbie programmer here.

    Here's the part of my code where it reads the input file
    Java Code:
    MileRedeemer redeem = new MileRedeemer(); // create new mileRedeemer
      redeem.readDestinations(input); // read in destinations
      
      String[] cityNames = redeem.getCityNames(); // read string city names
      for(int i = 0; i < cityNames.length; i++) // read until end of cities
      {
        System.out.println(cityNames[i]); // print out alpha order cities
      }

  2. #2
    bboardlol is offline Member
    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0

    Default Help with JList

    Hi,
    I'm making an applet. In this applet I have a method named getCityNames() that reads in cities from a .txt and parses them.
    I'm having trouble getting those cities from my getCityNames call in main() into the JList I am creating.
    Currently the list shows up blank(or not created).
    I tried to ... code that isn't relevant to the question.

    Java Code:
    public class MileRedemptionApp extends JApplet
    {  
       ...
       public static DefaultListModel destNames = new DefaultListModel();
       JList destList;
       ...
    public void init()
       {
       ...
       destList = new JList(destNames);
       destPanel.add(destList,c);
       ...
       }
    
    public static void main(String[] args)
    {
    
      ... 
    String[] cityNames = redeem.getCityNames(); // read string city names
          for(int i = 0; i < cityNames.length; i++) // read until end of cities
          {
            destNames.addElement(cityNames[i]);
            //System.out.println(cityNames[i]); // this is how I previously printed them out before making the applet
          }

  3. #3
    bboardlol is offline Member
    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0

    Default Help with reading info into a JList

    Hi,
    I'm making an applet. In this applet I have a method named getCityNames() that reads in cities from a .txt and parses them.
    I'm having trouble getting those cities from my getCityNames call in main() into the JList I am creating.
    Currently the list shows up blank(or not created).
    I tried to ... code that isn't relevant to the question.
    Java Code:
    public class MileRedemptionApp extends JApplet
    {  
       ...
       public static DefaultListModel destNames = new DefaultListModel();
       JList destList;
       ...
    public void init()
       {
       ...
       destList = new JList(destNames);
       destPanel.add(destList,c);
       ...
       }
    
    public static void main(String[] args)
    {
    
      ... 
    String[] cityNames = redeem.getCityNames(); // read string city names
          for(int i = 0; i < cityNames.length; i++) // read until end of cities
          {
            destNames.addElement(cityNames[i]);
            //System.out.println(cityNames[i]); // this is how I previously printed them out before making the applet
          }

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: New to Applets; not sure how to implement JList from existing program

    Kindly go through the Forum Rules, particularly the second paragraph.

    I've merged your three threads here.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. How to implement priority queue ADT by using java program?
    By rclgoriparthi in forum New To Java
    Replies: 4
    Last Post: 01-15-2012, 06:48 PM
  2. Replies: 0
    Last Post: 11-14-2011, 07:54 AM
  3. Implement a multi-threaded matrix multiplication program.
    By redasu in forum Threads and Synchronization
    Replies: 0
    Last Post: 11-17-2010, 10:00 AM
  4. Replies: 13
    Last Post: 04-16-2010, 03:51 AM
  5. how to add GUI to existing program?
    By VinTiger in forum New To Java
    Replies: 2
    Last Post: 05-08-2009, 06:05 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •