Results 1 to 7 of 7
  1. #1
    shivi24 is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default output to applet

    i am new to java.
    i have written the following code and now want the output to be printed on an applet..i have used jxl in this.


    import java.io.*;
    import java.util.Locale;
    import jxl.*;
    import jxl.read.biff.BiffException;

    public class Test
    {
    String st="i have to abate this";
    String[] arr=new String[5];

    public Test()
    { System.out.println("primary sentence is: ");
    arr=st.split(" ");
    for(int i=0;i<arr.length;i++)
    System.out.print(arr[i]+" ");
    System.out.println("\n");
    }



    public void init(String filePath)
    {
    FileInputStream fs = null;
    try
    {
    fs = new FileInputStream(new File(filePath));
    contentReading(fs);
    }
    catch (IOException e)
    {
    e.printStackTrace();
    }
    finally
    {
    try
    {
    fs.close();
    }
    catch (IOException e)
    {
    e.printStackTrace();
    }
    }
    }



    //Returns the Headings used inside the excel sheet
    public void getHeadingFromXlsFile(Sheet sheet)
    {
    int columnCount = sheet.getColumns();
    for (int i = 0; i < columnCount; i++)
    {
    System.out.println(sheet.getCell(i, 0).getContents());
    }
    }


    public void contentReading(InputStream fileInputStream)
    {
    WorkbookSettings ws = null;
    Workbook workbook = null;
    Sheet s = null;
    Cell rowData[] = null;
    int rowCount = 0;
    int columnCount = 0;
    DateCell dc = null;
    int totalSheet = 0;
    Cell c=null;
    String[][] str=new String[arr.length][];
    try {
    ws = new WorkbookSettings();
    ws.setLocale(new Locale("en", "EN"));
    workbook = Workbook.getWorkbook(fileInputStream, ws);

    //Getting Default Sheet i.e. 0
    s = workbook.getSheet(0);

    //total number of rows
    rowCount = s.getRows();
    // System.out.println("Total Rows inside Sheet:" + rowCount);

    //Total Total No Of Columns in Sheet
    columnCount = s.getColumns();
    // System.out.println("Total Column inside Sheet:" + columnCount);

    //Reading Individual Row Content
    for (int i = 0; i < arr.length; i++)
    { // System.out.println("mkd 86");
    c=s.findCell(arr[i]);
    if(c==null)
    { str[i]=new String[1];
    str[i][0]=arr[i];
    }
    //System.out.println(arr[i]);

    else
    {// System.out.println("mkd 89");
    rowData=s.getRow(c.getRow());
    str[i]=new String[rowData.length-1];
    for(int j=1;j<rowData.length;j++)
    { str[i][j-1]=rowData[j].getContents();

    }

    //System.out.println(c.getContents());

    }

    }
    System.out.println("possible combinations are: ");
    String[] str1=new String[5];
    //make all possible combination of collected data
    for(int i1=0;i1<str[0].length;i1++)
    { str1[0]=str[0][i1];
    for(int i2=0;i2<str[1].length;i2++)
    { str1[1]=str[1][i2];
    for(int i3=0;i3<str[2].length;i3++)
    { str1[2]=str[2][i3];
    for(int i4=0;i4<str[3].length;i4++)
    { str1[3]=str[3][i4];
    for(int i5=0;i5<str[4].length;i5++)
    { str1[4]=str[4][i5];

    for(int k=0;k<str1.length;k++)
    System.out.print(str1[k]+" ");
    System.out.println("\n");
    } } } } }


    workbook.close();

    } catch (IOException e)
    {
    e.printStackTrace();
    }
    catch (BiffException e)
    {
    e.printStackTrace();
    }
    }



    public static void main(String[] args)
    {
    try
    {
    Test tst = new Test();
    tst.init("C:\\shivi\\test.xls");
    }
    catch (Exception e)
    {
    e.printStackTrace();
    }
    }
    }





    the test file contains few thousaand words with their meaning in the consecutive cell of the file. like for the sentence provided here " i have to abate this"..
    'abate' has two meanings both in the Test.xls file..
    and similarly 'this' has only one meaning..
    hoping to get a solution.
    thanks for ur help! :)

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default

    want the output to be printed on an applet
    Can you describe the problem more? What does the program do that is wrong?
    What should it do that it doesn't do?

    What does applet have to do with this code? It has a main() method and does not extend an applet class.

  3. #3
    shivi24 is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default

    Sir,
    i need to create a GUI for the program. Thats why i need to print the output on an applet.
    I know that Applet does not contain main(). i havent tried the program on applet, providing u with what u can call a raw code.
    I am not able to understand which applet method to override. how to proceed on..

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default

    Thats why i need to print the output on an applet.
    not sure what that means?
    Applets are special programs that load into a browser. They use GUI like any other program would use GUI. They have special methods that browsers use to communicate with them.

    Why do you want to use an applet?

    For a program to have GUI it needs a window like you can get with a JFrame. Then you add some panels and in those panels you add the components that you need. To control where the components and panels are located in the containers they are in, you use a layout manager.

  5. #5
    shivi24 is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default

    Ok.
    actually its my college project and my head asked me to present the output in a better way.
    and i want to use applet because i know a little about it. i have no clue about JFrames.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default

    Applets extend panels. So any GUI building that works in an Applet will work with other panels. No magic about using JFrames. There must be thousands of simple programs on the forums that show how to use a JFrame. Build your panel and add it to the JFrame.

  7. #7
    shivi24 is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

Similar Threads

  1. Need help with output
    By cedric11 in forum New To Java
    Replies: 4
    Last Post: 11-30-2009, 01:09 PM
  2. Replies: 2
    Last Post: 09-29-2009, 03:33 PM
  3. Java, output string, getting correct output? HELP!
    By computerboyo in forum New To Java
    Replies: 2
    Last Post: 02-25-2009, 11:44 PM
  4. Calling another applet on click of button in one applet
    By niteshwar.bhardwaj in forum Java 2D
    Replies: 1
    Last Post: 02-19-2009, 12:54 PM
  5. Replies: 4
    Last Post: 06-08-2007, 06:15 AM

Posting Permissions

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