Can some one help me???

I'm doing a basic Java course and need help with this code

I'm trying to get this line to work but keep coming back with a "'.class' expected"

I have tried different combinations but nothing is working for me.

public void paintComponent (Graphics page)
      {
         super.paintComponent (page);

         for (int col; col<7; col++)
            for(int row; row<3; row++)

            page.setColor(Color.red);
         page.drawLine( 0, 100, int status(0,0), 100);

Any ideas????

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Surely that is not all of the code? Post the rest and please place it within [code] [/code] tags.

Also, always use braces around for() blocks. Even though a single statement without braces is allowed after for() and if() statements, you are likely at some point to add additional code and then wind up trying to figure out why it isn't working right because what you thought of as a block really isn't. Just get in the habit of using braces even for single statements.

Here is the rest of it.

import java.awt.*;
   import java.awt.event.*;
   import javax.swing.*;

    public class PaperPanel extends JPanel
   {
      private JButton testButton;
      private JTextField numField;
      int sold;
      //int row;
      //int col;
      PaperManager pm = new PaperManager();
   	
   		
       public PaperPanel()		
      {      
         setPreferredSize (new Dimension (600, 400));
           
         JButton d0 = new JButton("Monday");
         JButton d1 = new JButton("Tuesday");
         JButton d2 = new JButton("Wednesday");
         JButton d3 = new JButton("Thursday");
         JButton d4 = new JButton("Friday");
         JButton d5 = new JButton("Saturday");
         JButton d6 = new JButton("Sunday");
      	
         add (d0);
         add (d1);
         add (d2);
         add (d3);
         add (d4);
         add (d5);
         add (d6);
         
         TestListener0 t0 = new TestListener0();
         d0.addActionListener(t0);
      	
         TestListener1 t1 = new TestListener1();
         d1.addActionListener(t1);
      	
         TestListener2 t2 = new TestListener2();
         d2.addActionListener(t2);
      	
         TestListener3 t3 = new TestListener3();
         d3.addActionListener(t3);
      	
         TestListener4 t4 = new TestListener4();
         d4.addActionListener(t4);
      	
         TestListener5 t5 = new TestListener5();
         d5.addActionListener(t5);
      	
         TestListener6 t6 = new TestListener6();
         d6.addActionListener(t6);
      	
         numField = new JTextField(10);
         numField.setText("");
         add(numField);
      }
      
       private class TestListener0 implements ActionListener
      {
          public void actionPerformed(ActionEvent e)
         {
            String input = numField.getText();
            sold = Integer.parseInt(input);
            pm.update(0,sold);
            repaint();
         }
      }
      
       private class TestListener1 implements ActionListener
      {
          public void actionPerformed(ActionEvent e)
         {
            String input = numField.getText();
            int sold = Integer.parseInt(input);
            pm.update(1,sold);
            repaint();
         }
      }
      
       private class TestListener2 implements ActionListener
      {
          public void actionPerformed(ActionEvent e)
         {
            String input = numField.getText();
            int sold = Integer.parseInt(input);
            pm.update(2,sold);
            repaint();
         }
      }
      
       private class TestListener3 implements ActionListener
      {
          public void actionPerformed(ActionEvent e)
         {
            String input = numField.getText();
            int sold = Integer.parseInt(input);
            pm.update(3,sold);
            repaint();
         }
      }
      
       private class TestListener4 implements ActionListener
      {
          public void actionPerformed(ActionEvent e)
         {
            String input = numField.getText();
            int sold = Integer.parseInt(input);
            pm.update(4,sold);
            repaint();
         }
      }
      
       private class TestListener5 implements ActionListener
      {
          public void actionPerformed(ActionEvent e)
         {
            String input = numField.getText();
            int sold = Integer.parseInt(input);
            pm.update(5,sold);
            repaint();
         }
      }
   	
       private class TestListener6 implements ActionListener
      {
          public void actionPerformed(ActionEvent e)
         {
            String input = numField.getText();
            int sold = Integer.parseInt(input);
            pm.update(6,sold);
            repaint();
         }
      }
      
       public void paintComponent (Graphics page)
      {
         super.paintComponent (page);
         	
         for (int col; col<7; col++)
            for(int row; row<3; row++)
            
         page.setColor(Color.red);
         page.drawLine( 0, 100, int status(0,0), 100);      }
   }

Help !!!???

This line

page.drawLine( 0, 100, int status(0,0), 100);

is not a valid method call because you have placed the type definition ('int') in it. Drop the 'int' part.

And get braces around those for() blocks unless you expect to set the color to red 21 times and only draw a single line.

That is how I initially had it but, "status" is an object that is being read from another program. In that progran it is a set of arrays. Like in...

public double status (int day, int type)

When I first wrote it, it told me that I could not have "(int, int, double, int) " so, I have to convert status from a double to a int.

Edited 3 Years Ago by Dani: Formatting fixed

Ah, ok, you are trying to cast it to an int. You need to place parens around the cast like so

page.drawLine( 0, 100, (int)status(0,0), 100);

Done that.
Now, I replaced the 100 with the row's
meaning, the line now reads...

"page.drawLine (0, 100+row*5, (int) pm.status(0,0), 100+row*5)
Why it doesn't find the 'row' now.
It is declared at the top!!!

For the exact reason that I have been telling you to use braces to delimit your for() blocks. That for statement is only applying to the line directly after it and the variable "row" that you declared is only in scope for that single statement. You need to use blocks with the for() statements if you wish to execute more than a single line

public void paintComponent (Graphics page)
      {
         super.paintComponent (page);

         // setColor() only needs to be called once - not each iteration	
         page.setColor(Color.red);
         
         for (int col; col<7; col++) {
            for(int row; row<3; row++) {
               page.drawLine( 0, 100, (int) status(0,0), 100);
            }
         }
      }

Sorry for not mentioning it before but, I do want to print 21 lines...

I did change it as you said but now I got....
"variables col and row might not have been initialized"....Why?
I thought they were initialized at the top...

> Sorry for not mentioning it before but, I do want to print 21 lines...

Yes, that was understood. Your code, as written, would have executed the setColor() statement 21 times and drawLine() only once, because the drawLine() call was not in the for() {} block. My point is that you should always include the braces on a for() block

for( ... ) {
    doSomething();
}

even though the compiler allows an implicit block of a single statement after the for()

// DON'T USE THIS FORM
for ( ... )
    doSomething();

Without the braces, the for() only applies to that single statement directly following it.

The implicit block form is completely acceptable, but it is less clear and prone to insidious problems when later another line of code is added to what should be a block but is not.

the last section of programing as it is at this moment is;

public void paintComponent (Graphics page)
{
super.paintComponent (page);
page.setColor(Color.red);
for (int col; col<7; col++)
{
  for (int row; row<3; row++)
{
  page.drawLine (0; 100+row*5; (int) pm.status(0,0); 100+row*5);
}
}
}

How does it look?

I'm still having the "col and row might not have been initilized" (in red)

I did change it as you said but now I got....
"variables col and row might not have been initialized"....Why?
I thought they were initialized at the top...

You declared them - you did not initialize them, meaning set them to a specific value. Declare them like this instead

for ([B]int col=0[/B]; col<7; col++) {
            for([B]int row=0[/B]; row<3; row++) {
               page.drawLine( 0, 100, (int) status(0,0), 100);
            }
         }

I did as you said and one set of three line is being drawn.

What all these lines are about is, they're 3 parameters of info for each day of the week. that's why I need 21.
With the last changes you advised me to do, I get Monday's line only. Why is that? what about the other days?
My understanding was that it would read all 3 parameters of each day and update the graph as I input the info....

You are only using the 'row' variable in drawLine() and I suspect you want to also use 'col', otherwise you are drawing over the same area several times.

I thought that it would get the lines started on the left (0) and draw them 21 times one bellow the other.

As you can see in my initial post. I'm using buttons, one for each day of the week.
If the lines are being drawn on top of each other, it would not make any difference which button I'm pressing, the lines would extend or retract but, that is not the case. The lines only appear when I press the Monday button.

It will draw the lines from whichever (x,y) to (x', y') that you specify, so you have to vary those four parameters each iteration as needed.

Done mate!!!
Got it going finally.
I input the (x,Y) manually and it worked.

All i need to do now is to Find out what comand line I need to right so the values entered in the text box get deleted after pressing the button.

Thank you very much for your help!!!
I really appreciate it.

This question has already been answered. Start a new discussion instead.