-
Help
I need help to solve below problem. I've searched for errors but couldn't find anything wrong with it. Your help is appreciated.
http://img442.imageshack.us/img442/9867/19356349.png
Code:
import java.awt.*;
import java.awt.event.*;
public class IssueFrame implements DataClass,ActionListener, ItemListener {
public static int indItem=0;
public static int ind=0;
public static int curr=0;
public static int recNo=0;
public static int itemBal=0;
private Frame f;
private Frame f2;
private Frame f3;
private Label lblTitle;
private Label lblNo;
private Label lblName;
private Label lblCode;
private Label lblDesc;
private Label lblQtyIssue;
private Label lblCurrBal;
private TextArea taEmp;
private Choice cbNo;
private Choice cbCode;
private TextField tfName;
private TextField tfDesc;
private TextField tfQtyIssue;
private TextField tfCurrBal;
private Button btnSave;
private Button btnView1;
private Button btnView2;
private Button Close;
private Button Close2;
private Panel p1;
private Panel p2;
private Panel p3;
private Panel p5;
private Panel p6;
public IssueFrame() {
f=new Frame("Issue Stock Record");
f2=new Frame("Issue Stock Report");
f3=new Frame("Stock Balance Report");
lblTitle=new Label("Issued Stock Information");
lblNo=new Label("Employee No");
lblName=new Label("Employee Name");
lblCode=new Label("Item Code");
lblDesc=new Label("Description");
lblQtyIssue=new Label("Quantity Issue");
lblCurrBal=new Label("Current Balance");
tfName=new TextField(10);
tfDesc=new TextField(30);
tfQtyIssue=new TextField(30);
tfCurrBal=new TextField(10);
cbNo=new Choice();
cbCode=new Choice();
btnSave=new Button("Save");
btnView1=new Button("View Emp");
btnView2=new Button("View Stock");
btnClose=new Button("Close");
btnClose2=new Button("Close");
EmployeeFrame e=new EmployeeFrame();
p1=new Panel();
p2=new Panel();
p3=new Panel();
p5=new Panel();
p6=new Panel();
taEmp=new TextArea(5,40);
}
public void viewIssueFrame() {
EmployeeFrame e=new EmployeeFrame();
f.setLayout(new BorderLayout());
p1.setLayout(new FlowLayout());
p1.add(lblTitle);
p2.setLayout(new GridLayout(6,2));
int x=e.ind;
for(int i=0;i<e.ind;i++)
cbNo.addItem(emp[i].getEmpNo());
cbNo.addItemListener(this);
p2.add(lblNo);
p2.add(cbNo);
p2.add(lblName);
p2.add(tfName);
ItemFrame it=new ItemFrame();
int y=it.indItem;
for(int i=0;i<it.indItem;i++)
cbCode.addItem(item[i].getItemCode());
cbCode.addItemListener(this);
p2.add(lblCode);
p2.add(cbCode);
p2.add(lblDesc);
p2.add(tfDesc);
p2.add(lblQtyIssue);
p2.add(tfQtyIssue);
p2.add(lblCurrBal);
p2.add(tfCurrBal);
p3.setLayout(new GridLayout(1,4));
p3.add(btnSave);
btnSave.addActionListener(this);
p3.add(btnView1);
btnView1.addActionListener(this);
p3.add(btnView2);
btnView2.addActionListener(this);
p3.add(btnClose);
btnClose.addActionListener(this);
f.add(p1, BorderLayout.NORTH);
f.add(p2, BorderLayout.CENTER);
f.add(p3, BorderLayout.SOUTH);
f.setSize(500,300);
f.setVisible(true);
}
public void setBlank() {
tfName.setText("");
tfDesc.setText("");
tfQtyIssue.setText("");
tfCurrBal.setText("");
}
public void itemStateChanged(ItemEvent e) {
int x=cbNo.getSelectedIndex();
if(cbNo.getSelectedItem().equals(emp[x].getEmpNo()))
tfName.setText(emp[x].getEmpName());
int y=cbCode.getSelectedIndex();
if(cbCode.getSelectedItem().equals(item[y].getItemCode()))
{
tfDesc.setText(item[y].getItemDesc());
String s=Integer.toString(item[y].getItemBal());
tfCurrBal.setText(s);
}
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==btnSave)
{
System.out.println("Save");
save();
}
else
if(e.getSource()==btnView1)
{
System.out.println("View1");
setPanelView1();
}
else
if(e.getSource()==btnView2)
{
System.out.println("View2");
setPanelView2();
}
else
if(e.getSource()==btnClose)
{
f.setVisible(false);
}
if(e.getSource()==btnClose2)
{
f2.setVisible(false);
}
}
public void save() {
EmployeeFrame e=new EmployeeFrame();
int x=cbCode.getSelectedIndex();
int tempQty=Integer.parseInt(tfQtyIssue.getText());
int tempBal=item[x].getItemBal();
int temp=tempBal-tempQty;
item[x].setItemBal(temp);
int z=cbNo.getSelectedIndex();
Item tempItem=new Item();
tempItem=new Item("","",0);
tempItem.setItemCode(cbCode.getSelectedItem());
tempItem.setItemDesc(tfDesc.getText());
int q=Integer.parseInt(tfQtyIssue.getText());
tempItem.setItemBal(q);
emp[z].setItem(tempItem);
}
public void setPanelView1() {
f2.setLayout(new BorderLayout());
p5.setLayout(new FlowLayout());
taEmp.setText("");
EmployeeFrame ef=new EmployeeFrame();
for(int i=0;i<ef.ind;i++)
taEmp.append(emp[i].getEmpNo()+""+
emp[i].getEmpName()+""+
emp[i].getItem().getItemCode()+""+
emp[i].getItem().getItemDesc()+
emp[i].getItem().getItemBal()+"\n");
taEmp.setEditable(false);
p5.add(taEmp);
p6.setLayout(new FlowLayout());
p6.add(btnClose2);
btnClose2.addActionListener(this);
f2.add(p5, BorderLayout.CENTER);
f2.add(p6, BorderLayout.SOUTH);
f2.setSize(500,300);
f2.setVisible(true);
}
public void setPanelView2() {
f3.setLayout(new BorderLayout());
p5.setLayout(new FlowLayout());
taEmp.setText("");
ItemFrame ef=new ItemFrame();
for(int i=0;i<ef.indItem;i++)
taEmp.append(item[i].getItemCode()+""+item[i].getItemDesc()+""+item[i].getItemBal()+"\n");
taEmp.setEditable(false);
p5.add(taEmp);
p6.setLayout(new FlowLayout());
p6.add(btnClose2);
btnClose2.addActionListener(this);
f2.add(p5, BorderLayout.CENTER);
f2.add(p6, BorderLayout.SOUTH);
f2.setSize(500,300);
f2.setVisible(true);
}
}
-
The compiler's telling you exactly what's wrong. It's complaining that you're using a variable that's never declared, btnClose (and maybe another one -- tough to read the picture so I suggest you not use images for this). So where do you declare this variable in the code above?
-
Problem solved! I missed the word btn in private. Thanx!!