Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

cannot resolve symbol

843810Nov 7 2002 — edited Nov 8 2002
I have j2sdk1.4.1_01 and the same for the runtime environment
Using Win2000...class path variables are set..have complied easier programs:....


The program which comes from a java2 instructional book is as follows:
any help would be appreciated
First the errors:

C:\j2sdk1.4.1_01\ThreeWay>javac -classpath . ThreeWay.java
(have tried the regular---C:\j2sdk1.4.1_01\ThreeWay>javac ThreeWay.java ,same errors)

ThreeWay.java:31: cannot resolve symbol
symbol : variable tfPanel
location: class ThreeWay
tfPanel.setLayout(new BorderLayout());
^
ThreeWay.java:34: cannot resolve symbol
symbol : variable tfPanel
location: class ThreeWay
tfPanel.add(textfield, BorderLayout.SOUTH);
^
ThreeWay.java:35: cannot resolve symbol
symbol : variable tfPanel
location: class ThreeWay
add(tfPanel, BorderLayout.EAST);
^
ThreeWay.java:59: cannot resolve symbol
symbol : variable spreadPerRadio
location: class ThreeWay
spreadPerRadio = (float)(maxValue-minValue) / 4.0f;
^
ThreeWay.java:77: cannot resolve symbol
symbol : method reviseRadios ()
location: class ThreeWay
reviseRadios();
^
ThreeWay.java:90: cannot resolve symbol
symbol : method reviseRadios ()
location: class ThreeWay
reviseRadios();
^
ThreeWay.java:129: cannot resolve symbol
symbol : variable spreadPerRadio
location: class ThreeWay
float f = (value - minValue) / spreadPerRadio;
^
ThreeWay.java:152: cannot resolve symbol
symbol : method reviseRadios ()
location: class ThreeWay
reviseRadios();
^
ThreeWay.java:172: cannot resolve symbol
symbol : variable spreadPerRadio
location: class ThreeWay
newValue += spreadPerRadio;
^
ThreeWay.java:204: cannot resolve symbol
symbol : method reviseRadios ()
location: class ThreeWay
reviseRadios();
^
ThreeWay.java:268: cannot resolve symbol
symbol : variable spreadPerRadio
location: class ThreeWay
{ return (int)spreadPerRadio; }
^
11 errors

the program:

import java.awt.*;
import java.awt.event.*;
import java.util.*;


public class ThreeWay
extends Container
implements ActionListener, AdjustmentListener,
ItemListener, Adjustable
{
private Vector listeners = new Vector();
private Scrollbar bar;
private TextField textfield;
private CheckboxGroup cbgroup;
private Checkbox checkboxes[];
private int minValue;
private int maxValue;
private int value;
private float spreadPerRatio;

public ThreeWay(int value, int minValue, int maxValue)
{
this.minValue = minValue;
this.maxValue = maxValue;
this.value = value;

setLayout(new BorderLayout());

// Build and add textfield
Panel tfpanel = new Panel();
tfPanel.setLayout(new BorderLayout());
textfield = new TextField(" " + value);
textfield.addActionListener(this);
tfPanel.add(textfield, BorderLayout.SOUTH);
add(tfPanel, BorderLayout.EAST);

// Build and add checkboxes.
Panel cboxPanel = new Panel();
GridBagLayout gbl = new GridBagLayout();
cboxPanel.setLayout(gbl);
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridwidth = gbc.gridheight = 1;
gbc.weightx = gbc.weighty = 1;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.NONE;
gbc.anchor = GridBagConstraints.SOUTH;
checkboxes = new Checkbox[5];
cbgroup = new CheckboxGroup();
for (int i=0; i<5; i++)
{
checkboxes[i] = new Checkbox("", (i==0), cbgroup);
checkboxes.addItemListener(this);
gbc.gridx = i;
if (i > 2)
gbc.anchor = GridBagConstraints.SOUTHEAST;
gbl.setConstraints(checkboxes[i], gbc);
cboxPanel.add(checkboxes[i]);
}
spreadPerRadio = (float)(maxValue-minValue) / 4.0f;

// Build and add scrollbar.
Panel cboxSbarPanel = new Panel();
cboxSbarPanel.setLayout(new GridLayout(2, 1));
cboxSbarPanel.add(cboxPanel);
bar = new Scrollbar(Scrollbar.HORIZONTAL, value, 0,
minValue, maxValue);
bar.addAdjustmentListener(this);
cboxSbarPanel.add(bar);
Panel restrictorPanel = new Panel();
restrictorPanel.setLayout(new BorderLayout());
restrictorPanel.add(cboxSbarPanel, BorderLayout.SOUTH);
add(restrictorPanel, BorderLayout.CENTER);

// Make all subordinate components reflect current value.
reviseScrollbar();
reviseTextfield();
reviseRadios();
}

public int getValue()
{
return(value);
}

public synchronized void setValue(int newValue)
{
value = newValue;
reviseScrollbar();
reviseTextfield();
reviseRadios();
notifyListeners();
}

public void addAdjustmentListener(
AdjustmentListener listener)
{
if (!listeners.contains(listener))
listeners.addElement(listener);
}

public void removeAdjustmentListener(
AdjustmentListener listener)
{
listeners.removeElement(listener);
}

private void notifyListeners()
{
AdjustmentListener listener;

AdjustmentEvent event = new AdjustmentEvent(this,
0, 0, value);
Vector copyOfListeners = (Vector)(listeners.clone());
Enumeration enum = copyOfListeners.elements();
while (enum.hasMoreElements())
{
listener = (AdjustmentListener)enum.nextElement();
listener.adjustmentValueChanged(event);
}
}

private void reviseScrollbar()
{
bar.setValue(value);
}

private void reviseTextfield()
{
float f = (value - minValue) / spreadPerRadio;
int nth = Math.round(f);
if (nth < 0)
{
nth = 0;
}
else if (nth > 4)
{
nth = 4;
}

cbgroup.setSelectedCheckbox(checkboxes[nth]);
}


//
// Called when the scrollbar is moved.
//

public synchronized void adjustmentValueChanged(
AdjustmentEvent e)
{
value = e.getValue();
reviseRadios();
reviseTextfield();
notifyListeners();
}

//
// Called when one of the checkboxes is clicked.
//
public synchronized void itemStateChanged(ItemEvent e)
{
// Only react to selected checkbox.
if (e.getStateChange() != ItemEvent.SELECTED)
return;

// Determine new value.
int newValue = minValue;
for (int i=0; i<checkboxes.length; i++)
{
if (e.getSource() == checkboxes[i])
break;
newValue += spreadPerRadio;
}

value = newValue;
reviseTextfield();
reviseScrollbar();
notifyListeners();
}

//
// Called when the user hits ENTER in the textfield.
//
public synchronized void actionPerformed(ActionEvent e)
{
// Only accept valid numeric input.
int newValue = 0;
try
{
newValue = Integer.parseInt(textfield.getText());
}
catch (NumberFormatException x)
{
textfield.setText("" + value);
return;
}

// Normalize to within bounds.
newValue = Math.min(newValue, maxValue);
newValue = Math.max(newValue, minValue);

value = newValue;
reviseScrollbar();
reviseRadios();
notifyListeners();
}

/*
* Set background color of everything by setting it on this
* container and recursively on all children.
*/
public void setBackground(Color color)
{
super.setBackground(color);
setBackgndRecursive(this, color);
}


private void setBackgndRecursive(Container parent,
Color color)
{
Component children[] = parent.getComponents();
for (int i=0; i<children.length; i++)
{
children[i].setBackground(color);
if (children[i] instanceof Container)
{
setBackgndRecursive((Container)children[i], color);
}
}
}


/*
* Set foreground color of everything by setting it on this
* container and recursively on all children.
*/

public void setForeground(Color color)
{
super.setForeground(color);
setForegndRecursive(this, color);
}

private void setForegndRecursive(Container parent,
Color color)
{
Component children[] = parent.getComponents();
for (int i=0; i<children.length; i++)
{
children[i].setForeground(color);
if (children[i] instanceof Container)
{
setForegndRecursive((Container)children[i], color);
}
}
}

public void setFont(Font font)
{
textfield.setFont(font);
}

//
// Methods of interface Adjustable.
//
public int getBlockIncrement()
{ return (int)spreadPerRadio; }
public int getMaximum()
{ return maxValue; }
public int getMinimum()
{ return minValue; }
public int getOrientation()
{ return Scrollbar.HORIZONTAL; }
public int getUnitIncrement()
{ return bar.getUnitIncrement(); }
public int getVisibleAmount()
{ return bar.getVisibleAmount(); }
public void setBlockIncrement(int b) { }
public void setMaximum(int m) { }
public void setMinimum(int m) { }
public void setUnitIncrement(int m) { }
public void setVisibleAmount(int v)
{ bar.setVisibleAmount(v); }
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 6 2002
Added on Nov 7 2002
7 comments
288 views