www.webdeveloper.com
Results 1 to 13 of 13

Thread: I need help!

  1. #1
    Join Date
    Sep 2004
    Posts
    21

    Question I need help!

    hi
    I got 2 questions. 1st, how can I just make the first row and first column are in red font. I don't know what type should I declare the clr. can anyone show me?

    2nd. how about randomly place an input field in one of the cells ?
    int rndRow = Interger.ParseInt(Math.round(Math.random() * i));
    this line give me an error said that "Method ParseInt(double) not found in class java.lang.Integer." what error did I make?



    PHP Code:
    for (int i =1i<= Mi++ ) 
         { 
            
            if(
    == 1) {clr "#ff0000";} // make the first row in color red
           
    else {clr "#000000";} 

             
            
    out.println("<tr>");     
         
            for (
    int j =1j<= Nj++ ) 
            { 
                
    int rndRow Interger.ParseInt(Math.round(Math.random() * i)); // randomly put input field
                
    int rndCol Interger.ParseInt(Math.round(Math.random() * j)); //randomly put input field


                
    if(== 1) {clr "#ff0000";} // make the first col in color red

            
    else {clr "#000000";} 
                if(
    i==rndRow && j==rndCol) { 
             
    out.println("<td><input name=randomInputHere></td>"); 
              } 
              else { 

                
    out.println("<th WIDTH= "); 
                
    out.print(40); 
                 
    out.print(">"); 
                 
                
    out.println(i); 
                 
            
    out.println("</th>"); 
            
            } 
           } 
              
    out.println("</tr>"); 
    randomly put input field Method ParseInt(double) not found in class java.lang.Integer.

  2. #2
    Join Date
    Nov 2003
    Location
    Jerryville, Tejas
    Posts
    11,715
    First off, you shouldn't be emitting HTML from Java; that's what JSPs are for. In a style you put .red { color:#f00 } then in the JSP you can use
    Code:
    <tr>
    <% if (i==1) { %>
    <td class="red">
    <% } else { %>
    <td>
    <% } %>
    Do your td thing</td>
    </tr>
    (Actually, the first row should probably be appropriately styled header cells.)

    So when the compiler complained about ParseInt(double) did you check the API docs to see why?
    Code:
    static int parseInt(String s)
              Parses the string argument as a signed decimal integer.

  3. #3
    Join Date
    Sep 2004
    Posts
    21
    I don't quite get this. you mean that I need use CCS in JSP file?

    can you show me an example?
    PHP Code:
    <tr>
    <% if (
    i==1) { %>
    <
    td class="red">
    <% } else { %>
    <
    td>
    <% } %>
    Do 
    your td thing</td>
    </
    tr

  4. #4
    Join Date
    Nov 2003
    Location
    Jerryville, Tejas
    Posts
    11,715
    Of the CSS? Here's an imbedded style sheet (goes in the head of the document).
    Code:
    ...
    <head>
    ...
    <style type="text/css">
    .red { color: #f00 }
    </style>
    ...
    </head>

  5. #5
    Join Date
    Sep 2004
    Posts
    21

    Unhappy

    I try it but it's not work. I don't know why!!

  6. #6
    Join Date
    Nov 2004
    Posts
    11
    int rndRow = Interger.ParseInt(Math.round(Math.random() * i));

    should be

    int rndRow = (int) Math.round(Math.random() * i);

    I don't see in your code nowhere printing the clr

    should be

    if(i>1){
    if(j == 1) {
    clr = "#ff0000";
    }
    else {clr = "#000000";}
    }
    if(i==rndRow && j==rndCol) {
    out.println("<td style=\"color: "+ clr +";\"><input name=randomInputHere></td>");
    }

  7. #7
    Join Date
    Sep 2004
    Posts
    21

    Question

    thanks yerenkow
    I solve those 2 questions. but for second question I just want to only one input feild, but it give me multiple input field. also it's messd up with my table cuz the input take one cell and others will shif to right in that row. how can I solve this?



    PHP Code:

     
    for (int i =1i<= Mi++ ) 
         {
            
    out.println("<tr>");    
         
         
            for (
    int j =1j<= Nj++ )
            {
               
            
    int rndRow = (int) Math.round(Math.random() * i);
                    
    int rndCol = (int) Math.round(Math.random() * j);
                if(
    i==rndRow && j==rndCol) { 
                
    out.println("<td><input name=randomInputHere size = 1></td>"); 
            }
                
    out.println("<th WIDTH= ");
                
    out.print(40);
                 
    out.print(">");
                if(
    i==1)
                {
                
    out.println("<font color=red>");
                
    out.println(i);
                }
                else
            if(
    j==1)
                {
                
    out.println("<font color=red>");
                
    out.println(i);
                }    
                else
                {
                
    out.println("<font color=black>");
                
    out.println(i);
            }
                
            }   
            
    out.println("</th>");
           
            }
           
              
    out.println("</tr>"); 

  8. #8
    Join Date
    Nov 2004
    Posts
    11
    you need to initialize your place of random input only once, so change this

    for (int i =1; i<= M; i++ )
    {
    out.println("<tr>");


    for (int j =1; j<= N; j++ )
    {

    int rndRow = (int) Math.round(Math.random() * i);
    int rndCol = (int) Math.round(Math.random() * j);

    to

    int rndRow = (int) Math.round(Math.random() * i);
    int rndCol = (int) Math.round(Math.random() * j);
    for (int i =1; i<= M; i++ )
    {
    out.println("<tr>");


    for (int j =1; j<= N; j++ )
    {

    that must solve your first problem

    to make all td same width you must specify width in each one, minimum in forst row, and a summar width in table tag.

    And, your input must have width lesser than td.

  9. #9
    Join Date
    Sep 2004
    Posts
    21
    well, I use the following code to get row and col input from user. so how do I initialize j and i?
    also I just want to the input field take 1 cell. let's say the row number from 1 to 10 then the input table take the seventh cell. but the totally cell should be equal to 10 (1 2 3 4 5 6 input field 8 9 10)
    PHP Code:
    String m1 request.getParameter("mName") ;
         
    m1 m1.trim();
         
    int M Integer.parseInt(m1);

         
    String n1 request.getParameter("nName") ;
         
    n1 n1.trim();
         
    int N Integer.parseInt(n1); 

  10. #10
    Join Date
    Nov 2004
    Posts
    11
    Sorry, it's late and I'm sleepy
    NOT

    int rndRow = (int) Math.round(Math.random() * i);
    int rndCol = (int) Math.round(Math.random() * j);
    for (int i =1; i<= M; i++ )
    {
    out.println("<tr>");


    for (int j =1; j<= N; j++ )
    {

    BUT

    int rndRow = (int) Math.round(Math.random() * M);
    int rndCol = (int) Math.round(Math.random() * N);
    for (int i =1; i<= M; i++ )
    {
    out.println("<tr>");


    for (int j =1; j<= N; j++ )
    {

  11. #11
    Join Date
    Sep 2004
    Posts
    21

    Unhappy

    thanks man. sorry for delay your sleeping. I fixe the multiple input field.
    another question. I just want to the input field take 1 cell. let's say the row number from 1 to 10 and the input table take the seventh cell. but the totally cell should be equal to 10 (1 2 3 4 5 6 input field 8 9 10)
    I know that I need add something under this line of code, so the the table creation will ignore the cell that the input field take. but I don't know how

    if(i==rndRow && j==rndCol) {
    out.println("<td><input name=randomInputHere size = 1></td>");
    }

  12. #12
    Join Date
    Nov 2004
    Posts
    11
    int rndRow = (int) Math.round(Math.random() * M);
    int rndCol = (int) Math.round(Math.random() * N);

    out.println("<table width='"+(N*100)+"' >");
    for (int i =1; i<= M; i++ )
    {
    out.println("<tr>");

    for (int j =1; j<= N; j++ )
    {
    if(i==rndRow && j==rndCol)
    {
    out.println("<td width='100'><input name='yrName' type='text' width='80' ></td>");
    } else {

    out.println("<td width='100'>");
    if(i==1 || j==1)
    {
    out.println("<font color=red>");
    out.println(j * i);
    out.println("</font>");
    } else {
    out.println(j * i);
    }
    out.println("</td>);
    }
    }
    out.println("</tr>");
    }
    out.println("</table>");

  13. #13
    Join Date
    Sep 2004
    Posts
    21

    Thumbs up

    well, it's work. thanks so much.
    last question
    I want to input the cell number in the input field that I create. e.g. the #34 cell is taken by input field. I want to type 34 in it. if the number that I put is correct, then a pop up window will show up. I wrote the following in javascript, but it's not work
    PHP Code:
    z=document.getElementById(2).value
    z
    =parseInt(z)
    c=i*j
    if (== (i*j) )
        {    
    alert("The answer is "+i" * "+j+"  = "  ".   You are right.)
              }

    for (int j =1; j<= N; j++ )
            {
                if(i==rndRow && j==rndCol) 
                    
                    { 
            out.println("
    <th width='40'><input name='number' type='text' size=1 id 2 value=''></th>"); 
            } 

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles