#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Need some help please


    Code:
    if(main.equals("Start")) {
     Object[] topics{"Random","Sports","Geography","Politics","History"}; 
    String topic=(String)JOptionPane.showInputDialog(null,"Choose a topic:","Topics",JOptionPane.QUESTION_MESSAGE, null, topics,topics[1]); 
    
    new Thread(){ 
    public void run() {
     .main(new String[]{});}
     }.start();
    This is a part of a code for a quiz that I am doing, this is supposed to run an external file with the questions for each topic. The only little thing that i need to add here is the file name right before main.
    Code:
    .main(new String[]{});}
    My question is; How do I make on of the objects in "topics" to register into the .main part?
    For example:
    I choose the Sports topic
    that means I want
    Code:
    Sports.main(new String[]{});}
    to be executed.

    I still cannot figure this out, which I have been trying to do for the past 4 hours

    Any help appreciated
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    The variable topics is defined inside an if statement and is only known there.
    Can you define it at the class level so all methods can see it?

    It would help if you posted a small, complete program for testing. The bits and pieces you posted make it hard to see what you are trying to do.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0
    I solved the problem by using buffered reader and reading from an .txt file instead . This can be closed now.

IMN logo majestic logo threadwatch logo seochat tools logo