Solved

Error in Main

Posted on 2004-04-23
8
245 Views
Last Modified: 2011-09-20
Hello everyone out there I hope someone can help me with this simple question!

Something is wrong with the main. Error cannot resolve symbol- constructor EightPointBlocks()

Get error can't recondnize



import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class EightPointBlocks extends JPanel implements ActionListener
{
     JCheckBox onOffButton;
     JLabel label;
     JPanel gridPanel;
     ArrayList EightPointBlocksArrayList;
     ArrayList arrayList;

public EightPointBlocks(int ncols, int nrows)

     {
          EightPointBlocksArrayList = new ArrayList();
          label = new JLabel();
          //Call it like this . . .
          gridPanel = new JPanel();
          gridPanel.setLayout(new GridLayout(0, ncols));
          // Setting MY layout...
          setLayout(new BorderLayout());
          add(label, BorderLayout.NORTH);
          add(gridPanel, BorderLayout.CENTER);
          label.setText("          8 Point Blocks");
          label.setForeground(Color.red);
          setBackground(Color.white);
          looprow : for (int row = 0; row < nrows; row++)
          {
               for (int col = 0; col < ncols; col++)
               {
                    int n = (20 * col + row + 1);
                    if (n > 50)
                    {
                         break looprow;
                    }
                    JButton onOffButton = new JColoredButton("" + n, Color.green, Color.black);
                    onOffButton.addActionListener(this);
                    //EightPointBlocksArrayList.add(onOffButton);
                    gridPanel.add(onOffButton);
               }
          }
     }


     public static void main(String[] args)
     {
          JFrame frame = new JFrame();
          frame.getContentPane().add(new EightPointBlocks());
          frame.setSize(400, 400);
          frame.setVisible(true);

          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     }

     public void actionPerformed(ActionEvent e)
{
                               
          JColoredButton button = (JColoredButton)e.getSource();
         
          int index = EightPointBlocksArrayList.indexOf(button) ;

          if (index > -1)
          {
               EightPointBlocksArrayList.remove(index); // removal of button
               EightPointBlocksArrayList.remove(index); // removal of timing.wav

               button.setDefaultColor();
          }
          else
          {
               EightPointBlocksArrayList.add(button);
               EightPointBlocksArrayList.add("timing.wav");
 
               button.setPressedColor();
          }
         
          System.out.println(EightPointBlocksArrayList);
}  

}

class JColoredButton extends JButton
{
     private Color foreground;
     private Color deafultForeground;
     private Color background;
     private Color defaultBackground;

     public JColoredButton(String label, Color background, Color foreground)
     {
          super(label);
          this.background = background;
          this.foreground = foreground;
          defaultBackground = getBackground();
          deafultForeground = getForeground();
     }
     
     public void setPressedColor()
     {
          setBackground(background);
          setForeground(foreground);
     }
     
     public void setDefaultColor()
     {
          setBackground(defaultBackground);
          setForeground(deafultForeground);
     }
}          
0
Comment
Question by:Drop_of_Rain
  • 5
  • 2
8 Comments
 
LVL 15

Expert Comment

by:Javatm
ID: 10906262
This should solve the problem :

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class EightPointBlocks extends JPanel implements ActionListener
{
     JCheckBox onOffButton;
     JLabel label;
     JPanel gridPanel;
     ArrayList EightPointBlocksArrayList;
     ArrayList arrayList;
     int ncols, nrows;

public EightPointBlocks()

     {
          EightPointBlocksArrayList = new ArrayList();
          label = new JLabel();
          //Call it like this . . .
          gridPanel = new JPanel();
          gridPanel.setLayout(new GridLayout(0, ncols));
          // Setting MY layout...
          setLayout(new BorderLayout());
          add(label, BorderLayout.NORTH);
          add(gridPanel, BorderLayout.CENTER);
          label.setText("          8 Point Blocks");
          label.setForeground(Color.red);
          setBackground(Color.white);
          looprow : for (int row = 0; row < nrows; row++)
          {
               for (int col = 0; col < ncols; col++)
               {
                    int n = (20 * col + row + 1);
                    if (n > 50)
                    {
                         break looprow;
                    }
                    JButton onOffButton = new JColoredButton("" + n, Color.green, Color.black);
                    onOffButton.addActionListener(this);
                    //EightPointBlocksArrayList.add(onOffButton);
                    gridPanel.add(onOffButton);
               }
          }
     }


     public static void main(String[] args)
     {
          JFrame frame = new JFrame();
          frame.getContentPane().add(new EightPointBlocks());
          frame.setSize(400, 400);
          frame.setVisible(true);

          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     }

     public void actionPerformed(ActionEvent e)
{

          JColoredButton button = (JColoredButton)e.getSource();

          int index = EightPointBlocksArrayList.indexOf(button) ;

          if (index > -1)
          {
               EightPointBlocksArrayList.remove(index); // removal of button
               EightPointBlocksArrayList.remove(index); // removal of timing.wav

               button.setDefaultColor();
          }
          else
          {
               EightPointBlocksArrayList.add(button);
               EightPointBlocksArrayList.add("timing.wav");

               button.setPressedColor();
          }

          System.out.println(EightPointBlocksArrayList);
}

}

class JColoredButton extends JButton
{
     private Color foreground;
     private Color deafultForeground;
     private Color background;
     private Color defaultBackground;

     public JColoredButton(String label, Color background, Color foreground)
     {
          super(label);
          this.background = background;
          this.foreground = foreground;
          defaultBackground = getBackground();
          deafultForeground = getForeground();
     }

     public void setPressedColor()
     {
          setBackground(background);
          setForeground(foreground);
     }

     public void setDefaultColor()
     {
          setBackground(defaultBackground);
          setForeground(deafultForeground);
     }
}

Hope that helps . . .
Javatm
0
 
LVL 15

Expert Comment

by:Javatm
ID: 10906284
Test it and if it gives you a runtime error
it is because the int ncols, nrows; doesnt not have any values yet.

So you need to specify the value like :

int ncols=2, nrows=2;

Hope that helps . . .
Javatm
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10906299
When creating the EightPointBlocks instance

          frame.getContentPane().add(new EightPointBlocks());

 should be (for instance):

          frame.getContentPane().add(new EightPointBlocks(2,4));
 
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:Javatm
ID: 10906307
> When creating the EightPointBlocks instance
> frame.getContentPane().add(new EightPointBlocks());
> should be (for instance):
> frame.getContentPane().add(new EightPointBlocks(2,4));

Which is like my 1st and 2nd comment :)


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class EightPointBlocks extends JPanel implements ActionListener
{
     JCheckBox onOffButton;
     JLabel label;
     JPanel gridPanel;
     ArrayList EightPointBlocksArrayList;
     ArrayList arrayList;
     int ncols=2, nrows=2;

public EightPointBlocks()

     {
          EightPointBlocksArrayList = new ArrayList();
          label = new JLabel();
          //Call it like this . . .
          gridPanel = new JPanel();
          gridPanel.setLayout(new GridLayout(0, ncols));
          // Setting MY layout...
          setLayout(new BorderLayout());
          add(label, BorderLayout.NORTH);
          add(gridPanel, BorderLayout.CENTER);
          label.setText("          8 Point Blocks");
          label.setForeground(Color.red);
          setBackground(Color.white);
          looprow : for (int row = 0; row < nrows; row++)
          {
               for (int col = 0; col < ncols; col++)
               {
                    int n = (20 * col + row + 1);
                    if (n > 50)
                    {
                         break looprow;
                    }
                    JButton onOffButton = new JColoredButton("" + n, Color.green, Color.black);
                    onOffButton.addActionListener(this);
                    //EightPointBlocksArrayList.add(onOffButton);
                    gridPanel.add(onOffButton);
               }
          }
     }


     public static void main(String[] args)
     {
          JFrame frame = new JFrame();
          frame.getContentPane().add(new EightPointBlocks());
          frame.setSize(400, 400);
          frame.setVisible(true);

          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     }

     public void actionPerformed(ActionEvent e)
{

          JColoredButton button = (JColoredButton)e.getSource();

          int index = EightPointBlocksArrayList.indexOf(button) ;

          if (index > -1)
          {
               EightPointBlocksArrayList.remove(index); // removal of button
               EightPointBlocksArrayList.remove(index); // removal of timing.wav

               button.setDefaultColor();
          }
          else
          {
               EightPointBlocksArrayList.add(button);
               EightPointBlocksArrayList.add("timing.wav");

               button.setPressedColor();
          }

          System.out.println(EightPointBlocksArrayList);
}

}

class JColoredButton extends JButton
{
     private Color foreground;
     private Color deafultForeground;
     private Color background;
     private Color defaultBackground;

     public JColoredButton(String label, Color background, Color foreground)
     {
          super(label);
          this.background = background;
          this.foreground = foreground;
          defaultBackground = getBackground();
          deafultForeground = getForeground();
     }

     public void setPressedColor()
     {
          setBackground(background);
          setForeground(foreground);
     }

     public void setDefaultColor()
     {
          setBackground(defaultBackground);
          setForeground(deafultForeground);
     }
}
0
 
LVL 15

Accepted Solution

by:
Javatm earned 125 total points
ID: 10906318
Or it can be :

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class EightPointBlocks extends JPanel implements ActionListener
{
     JCheckBox onOffButton;
     JLabel label;
     JPanel gridPanel;
     ArrayList EightPointBlocksArrayList;
     ArrayList arrayList;

public EightPointBlocks(int ncols, int nrows)

     {
          EightPointBlocksArrayList = new ArrayList();
          label = new JLabel();
          //Call it like this . . .
          gridPanel = new JPanel();
          gridPanel.setLayout(new GridLayout(0, ncols));
          // Setting MY layout...
          setLayout(new BorderLayout());
          add(label, BorderLayout.NORTH);
          add(gridPanel, BorderLayout.CENTER);
          label.setText("          8 Point Blocks");
          label.setForeground(Color.red);
          setBackground(Color.white);
          looprow : for (int row = 0; row < nrows; row++)
          {
               for (int col = 0; col < ncols; col++)
               {
                    int n = (20 * col + row + 1);
                    if (n > 50)
                    {
                         break looprow;
                    }
                    JButton onOffButton = new JColoredButton("" + n, Color.green, Color.black);
                    onOffButton.addActionListener(this);
                    //EightPointBlocksArrayList.add(onOffButton);
                    gridPanel.add(onOffButton);
               }
          }
     }


     public static void main(String[] args)
     {
          JFrame frame = new JFrame();
     
          // Instantiating the size . . .

          frame.getContentPane().add(new EightPointBlocks(2,2));
          frame.setSize(400, 400);
          frame.setVisible(true);

          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     }

     public void actionPerformed(ActionEvent e)
{
                               
          JColoredButton button = (JColoredButton)e.getSource();
         
          int index = EightPointBlocksArrayList.indexOf(button) ;

          if (index > -1)
          {
               EightPointBlocksArrayList.remove(index); // removal of button
               EightPointBlocksArrayList.remove(index); // removal of timing.wav

               button.setDefaultColor();
          }
          else
          {
               EightPointBlocksArrayList.add(button);
               EightPointBlocksArrayList.add("timing.wav");
 
               button.setPressedColor();
          }
         
          System.out.println(EightPointBlocksArrayList);
}  

}

class JColoredButton extends JButton
{
     private Color foreground;
     private Color deafultForeground;
     private Color background;
     private Color defaultBackground;

     public JColoredButton(String label, Color background, Color foreground)
     {
          super(label);
          this.background = background;
          this.foreground = foreground;
          defaultBackground = getBackground();
          deafultForeground = getForeground();
     }
     
     public void setPressedColor()
     {
          setBackground(background);
          setForeground(foreground);
     }
     
     public void setDefaultColor()
     {
          setBackground(defaultBackground);
          setForeground(deafultForeground);
     }
}          
0
 

Author Comment

by:Drop_of_Rain
ID: 10906389
Comment from Javatm
Date: 04/23/2004 10:32PM PDT
 Comment  


Or it can be :  This one fixed my last posted comment. I should of looked at the code better before i tried your last one.

Thanks,
Christopher
0
 

Author Comment

by:Drop_of_Rain
ID: 10906394
Javatm

I have never gotten an email from you. Why don't you get an email at Yahoo to then we will be able to email each other. email me when you do.
0
 
LVL 15

Expert Comment

by:Javatm
ID: 10906420
Yes of course my friend I'm very sorry I was busy but dont worry I'll send you e-mails.
I have an e-mail in yahoo but it contains a lot of spams and I dont know how to fix it.

You know friend I've always wanted to be a real Java Programmer but I have'nt
got any chance to prove it.

I applied for one but they are still reviewing it. How I wish I could be a real
programmer instead of being a tech support.

Thanks for your time . . .
Javatm
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question