Drop_of_Rain
asked on
Error in Main
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.ActionListe ner;
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.addActionListe ner(this);
//EightPointBlocksArrayLis t.add(onOf fButton);
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.setDefaultCloseOpera tion(JFram e.EXIT_ON_ CLOSE);
}
public void actionPerformed(ActionEven t e)
{
JColoredButton button = (JColoredButton)e.getSourc e();
int index = EightPointBlocksArrayList. indexOf(bu tton) ;
if (index > -1)
{
EightPointBlocksArrayList. remove(ind ex); // removal of button
EightPointBlocksArrayList. remove(ind ex); // removal of timing.wav
button.setDefaultColor();
}
else
{
EightPointBlocksArrayList. add(button );
EightPointBlocksArrayList. add("timin g.wav");
button.setPressedColor();
}
System.out.println(EightPo intBlocksA rrayList);
}
}
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(defaultBackg round);
setForeground(deafultForeg round);
}
}
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.ActionListe
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.
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.addActionListe
//EightPointBlocksArrayLis
gridPanel.add(onOffButton)
}
}
}
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.getContentPane().add
frame.setSize(400, 400);
frame.setVisible(true);
frame.setDefaultCloseOpera
}
public void actionPerformed(ActionEven
{
JColoredButton button = (JColoredButton)e.getSourc
int index = EightPointBlocksArrayList.
if (index > -1)
{
EightPointBlocksArrayList.
EightPointBlocksArrayList.
button.setDefaultColor();
}
else
{
EightPointBlocksArrayList.
EightPointBlocksArrayList.
button.setPressedColor();
}
System.out.println(EightPo
}
}
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(defaultBackg
setForeground(deafultForeg
}
}
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
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
When creating the EightPointBlocks instance
frame.getContentPane().add (new EightPointBlocks());
should be (for instance):
frame.getContentPane().add (new EightPointBlocks(2,4));
frame.getContentPane().add
should be (for instance):
frame.getContentPane().add
> 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.ActionListe ner;
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.addActionListe ner(this);
//EightPointBlocksArrayLis t.add(onOf fButton);
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.setDefaultCloseOpera tion(JFram e.EXIT_ON_ CLOSE);
}
public void actionPerformed(ActionEven t e)
{
JColoredButton button = (JColoredButton)e.getSourc e();
int index = EightPointBlocksArrayList. indexOf(bu tton) ;
if (index > -1)
{
EightPointBlocksArrayList. remove(ind ex); // removal of button
EightPointBlocksArrayList. remove(ind ex); // removal of timing.wav
button.setDefaultColor();
}
else
{
EightPointBlocksArrayList. add(button );
EightPointBlocksArrayList. add("timin g.wav");
button.setPressedColor();
}
System.out.println(EightPo intBlocksA rrayList);
}
}
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(defaultBackg round);
setForeground(deafultForeg round);
}
}
> frame.getContentPane().add
> should be (for instance):
> frame.getContentPane().add
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.ActionListe
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.
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.addActionListe
//EightPointBlocksArrayLis
gridPanel.add(onOffButton)
}
}
}
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.getContentPane().add
frame.setSize(400, 400);
frame.setVisible(true);
frame.setDefaultCloseOpera
}
public void actionPerformed(ActionEven
{
JColoredButton button = (JColoredButton)e.getSourc
int index = EightPointBlocksArrayList.
if (index > -1)
{
EightPointBlocksArrayList.
EightPointBlocksArrayList.
button.setDefaultColor();
}
else
{
EightPointBlocksArrayList.
EightPointBlocksArrayList.
button.setPressedColor();
}
System.out.println(EightPo
}
}
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(defaultBackg
setForeground(deafultForeg
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
ASKER
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.
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.
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
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
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent
import java.awt.event.ActionListe
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.
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.addActionListe
//EightPointBlocksArrayLis
gridPanel.add(onOffButton)
}
}
}
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.getContentPane().add
frame.setSize(400, 400);
frame.setVisible(true);
frame.setDefaultCloseOpera
}
public void actionPerformed(ActionEven
{
JColoredButton button = (JColoredButton)e.getSourc
int index = EightPointBlocksArrayList.
if (index > -1)
{
EightPointBlocksArrayList.
EightPointBlocksArrayList.
button.setDefaultColor();
}
else
{
EightPointBlocksArrayList.
EightPointBlocksArrayList.
button.setPressedColor();
}
System.out.println(EightPo
}
}
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(defaultBackg
setForeground(deafultForeg
}
}
Hope that helps . . .
Javatm