Hi,
Im trying to list all the drives in the local machine in a combo box and when a drive selected all the folders and files in that drive must be listed ina list box.
I was succesfull in listing the drives in the combobos.But when i try to list the folders in the list box im getting error like this:
Error:
Prod_applet.java:226: Cannot find symbol
symbol : variable local_jlist
location: class Prod_applet
local_jlist.addElement(local_files[i]);
1 error
Can any one help me in solving this problem ASAP please?Just got struck with it
i have given the code below.
Thankyou
Prod_applet.java
--------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.File;
import java.io.FilenameFilter;
import java.io.FileFilter;
public class Prod_applet extends JFrame implements ItemListener{
boolean inAnApplet = true;
final boolean shouldFill = true;
final boolean shouldWeightX = true;
public Prod_applet() {
JPanel local_window = new JPanel();
JPanel server_window = new JPanel();
JPanel button_window = new JPanel();
JPanel action_window = new JPanel();
JButton connect = new JButton("Connect");
connect.setMargin(new Insets(0, 0, 0, 0));
JButton disconnect = new JButton("Disconnect");
disconnect.setMargin(new Insets(0, 0, 0, 0));
JButton up_but = new JButton(">>");
up_but.setMargin(new Insets(0, 0, 0, 0));
JButton down_but = new JButton("<<");
down_but.setMargin(new Insets(0, 0, 0, 0));
JLabel local_lbl = new JLabel("Local Site");
JLabel server_lbl = new JLabel("Remote Site");
JComboBox local_combobox = new JComboBox();
local_combobox.setEditable(true);
JComboBox server_combobox = new JComboBox();
List local_jlist = new List();
//local_jlist.setMargin(new Insets(0, 0, 0, 0));
List server_jlist = new List();
//server_jlist.setMargin(new Insets(0, 0, 0, 0));
JButton local_mkdir = new JButton("MkDir");
local_mkdir.setMargin(new Insets(0, 0, 0, 0));
JButton server_mkdir = new JButton("MkDir");
server_mkdir.setMargin(new Insets(0, 0, 0, 0));
JButton local_delete = new JButton("Delete");
local_delete.setMargin(new Insets(0, 0, 0, 0));
JButton server_delete = new JButton("Delete");
server_delete.setMargin(new Insets(0, 0, 0, 0));
JButton local_refresh = new JButton("Refresh");
local_refresh.setMargin(new Insets(0, 0, 0, 0));
JButton server_refresh = new JButton("Refresh");
server_refresh.setMargin(new Insets(0, 0, 0, 0));
Container contentPane = getContentPane();
BorderLayout border = new BorderLayout();
contentPane.setLayout(border);
contentPane.add(local_window, BorderLayout.WEST);
contentPane.add(server_window, BorderLayout.EAST);
contentPane.add(button_window, BorderLayout.CENTER);
contentPane.add (action_window, BorderLayout.SOUTH);
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(2, 2, 2, 2);
GridBagConstraints c1 = new GridBagConstraints();
c1.insets = new Insets(2, 2, 2, 2);
GridBagConstraints c2 = new GridBagConstraints();
c2.insets = new Insets(2, 2, 2, 2);
GridBagConstraints c3 = new GridBagConstraints();
c3.insets = new Insets(2, 2, 2, 2);
GridBagConstraints c4 = new GridBagConstraints();
c4.insets = new Insets(2, 2, 2, 2);
GridBagConstraints c5 = new GridBagConstraints();
c5.insets = new Insets(2, 2, 2, 2);
GridBagConstraints c6 = new GridBagConstraints();
c6.insets = new Insets(2, 2, 2, 2);
local_window.setLayout(gridbag);
server_window.setLayout(gridbag);
button_window.setLayout(gridbag);
action_window.setLayout(gridbag);
File[] drives = File.listRoots();
for(int i = 0 ; i
Looks like local_jlist is a function local variable (inpublic Prod_applet()).. and not in the scope where you're using it (line 226).. make it a member variable.. it should work..
I have declared all the variables public only. No problem with other components only the listbox is bugging up.
Thnak you
I have declared all the variables public only. No problem with other components only the listbox is bugging up.
Im new for this just now trying practically.Can you help me in this more.
Thnak you
As thekashyap mentioned, local_jlist is a function local variable (inpublic Prod_applet()) which mean you can not access it in public void itemStateChanged(ItemEvent e) . So you need to declare it on top level to be accesible by other methods
boolean inAnApplet = true;
final boolean shouldFill = true;
final boolean shouldWeightX = true;
public List local_jlist;
Also List doesn't have method addElement() so add() would be solution check reference
OK just seen this application running...
1. TextArea to list files is very-very small you should do something bigger. Play with settings for each component
2. In remote site I chosed my optical drive which made lots of un-catched errors and on top of that list was displayed in wrong TextArea (under my local disk)
3. Puzzled with functionality of buttons Connect & Disconnect. What do they do? If this application is supposed to work as FTP client you have to be able define location where you want to connect (like ftp.adobe.pub.com plus user name), but cann't say to much I doon't know what research you did into FTP clients
Hi thanks,
I have tried that also.Its now showing erro like"variable local_jlistmight not have been initialized"
Hi thanks, I have tried that also.Its now showing erro like"variable local_jlistmight not have been initialized"
Post the updated code and I will look at it
Hi thanks, I have tried that also.Its now showing erro like"variable local_jlistmight not have been initialized"
This just means that you must set a value for the variable before it is used. You could change it's declaration to
public List local_jlist = null;
// or this
public List local_jlist = new ArrayList();
Note, you cannot simply say new List(), since List is an interface and not a class. You need to choose one of the List implementations to create.
Note, you cannot simply say new List(), since List is an interface and not a class. You need to choose one of the List implementations to create.
Am I mistaken and List is not a class? What about this . However, you right List can be also interface but with less option then List class
Am I mistaken and List is not a class? What about this . However, you right List can be also interface but with less option then List class
Ah, yes, sorry I misread his intent. I was not thinking of the awt UI component, but rather the collection interface List.
Please disregard that bit about List :)
Hi,
Thanks.Iv fixed the problem and its working.
Now got another problem. When i select a drive from the combo box the directories get listed in the listbox.But when i choose the next drive the directoreis in the that choosen drive is appened along with the listed directoreis in the list box. I tried the clear method but not working.What may be my mistale?
Thank you
Updated code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.File;
import java.io.FilenameFilter;
import java.io.FileFilter;
public class Prod_applet extends JFrame implements ItemListener{
boolean inAnApplet = true;
final boolean shouldFill = true;
final boolean shouldWeightX = true;
public List local_jlist = new List();
public Prod_applet() {
JPanel local_window = new JPanel();
JPanel server_window = new JPanel();
JPanel button_window = new JPanel();
JPanel action_window = new JPanel();
JButton connect = new JButton("Connect");
connect.setMargin(new Insets(0, 0, 0, 0));
JButton disconnect = new JButton("Disconnect");
disconnect.setMargin(new Insets(0, 0, 0, 0));
JButton up_but = new JButton(">>");
up_but.setMargin(new Insets(0, 0, 0, 0));
JButton down_but = new JButton("<<");
down_but.setMargin(new Insets(0, 0, 0, 0));
JLabel local_lbl = new JLabel("Local Site");
JLabel server_lbl = new JLabel("Remote Site");
JComboBox local_combobox = new JComboBox();
local_combobox.setEditable(true);
JComboBox server_combobox = new JComboBox();
//List local_jlist = new List();
//local_jlist.setMargin(new Insets(0, 0, 0, 0));
List server_jlist = new List();
//server_jlist.setMargin(new Insets(0, 0, 0, 0));
JButton local_mkdir = new JButton("MkDir");
local_mkdir.setMargin(new Insets(0, 0, 0, 0));
JButton server_mkdir = new JButton("MkDir");
server_mkdir.setMargin(new Insets(0, 0, 0, 0));
JButton local_delete = new JButton("Delete");
local_delete.setMargin(new Insets(0, 0, 0, 0));
JButton server_delete = new JButton("Delete");
server_delete.setMargin(new Insets(0, 0, 0, 0));
JButton local_refresh = new JButton("Refresh");
local_refresh.setMargin(new Insets(0, 0, 0, 0));
JButton server_refresh = new JButton("Refresh");
server_refresh.setMargin(new Insets(0, 0, 0, 0));
Container contentPane = getContentPane();
BorderLayout border = new BorderLayout();
contentPane.setLayout(border);
contentPane.add(local_window, BorderLayout.WEST);
contentPane.add(server_window, BorderLayout.EAST);
contentPane.add(button_window, BorderLayout.CENTER);
contentPane.add (action_window, BorderLayout.SOUTH);
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(2, 2, 2, 2);
GridBagConstraints c1 = new GridBagConstraints();
c1.insets = new Insets(2, 2, 2, 2);
GridBagConstraints c2 = new GridBagConstraints();
c2.insets = new Insets(2, 2, 2, 2);
GridBagConstraints c3 = new GridBagConstraints();
c3.insets = new Insets(2, 2, 2, 2);
GridBagConstraints c4 = new GridBagConstraints();
c4.insets = new Insets(2, 2, 2, 2);
GridBagConstraints c5 = new GridBagConstraints();
c5.insets = new Insets(2, 2, 2, 2);
GridBagConstraints c6 = new GridBagConstraints();
c6.insets = new Insets(2, 2, 2, 2);
local_window.setLayout(gridbag);
server_window.setLayout(gridbag);
button_window.setLayout(gridbag);
action_window.setLayout(gridbag);
File[] drives = File.listRoots();
for(int i = 0 ; i
replace line 214 (according my IDE) which you commented out //local_jlist.clear(); with local_jlist.removeAll(); . If you check API properly you will find that List.clear()Deprecated. As of JDK version 1.1, replaced by removeAll().This will sort your problem with apend.
hi tolearn
i have indicated where you made mistakes using "++++++++++++++++++" look out these sections and you will get some coooments
Also not that list is an abstract window toolkit componet (awt) in the package java.awt.
it does have the method addElement(String)
instead you use
List mylist = new List();
mylist.add( String)
the reason you were getting the error variable local_jlist might not have been initialized is because you declared it in the method Prod_applet as follows
List local_jlist;
instead of List local_jlist = new List();
This happens when you are using java 1.4 and bellow. With java 1.5 you do not get that message
The following is the new code and let me know if you get any more problems
mport java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.File;
import java.io.FilenameFilter;
import java.io.FileFilter;
public class Prod_applet extends JFrame implements ItemListener{
boolean inAnApplet = true;
final boolean shouldFill = true;
final boolean shouldWeightX = true;
//++++++++++++++++++++++++++++++++++++++++++++
//make the local_jlist public to all methods in the class
List local_jlist;
public Prod_applet() {
JPanel local_window = new JPanel();
JPanel server_window = new JPanel();
JPanel button_window = new JPanel();
JPanel action_window = new JPanel();
JButton connect = new JButton("Connect");
connect.setMargin(new Insets(0, 0, 0, 0));
JButton disconnect = new JButton("Disconnect");
disconnect.setMargin(new Insets(0, 0, 0, 0));
JButton up_but = new JButton(">>");
up_but.setMargin(new Insets(0, 0, 0, 0));
JButton down_but = new JButton("<<");
down_but.setMargin(new Insets(0, 0, 0, 0));
JLabel local_lbl = new JLabel("Local Site");
JLabel server_lbl = new JLabel("Remote Site");
JComboBox local_combobox = new JComboBox();
local_combobox.setEditable(true);
JComboBox server_combobox = new JComboBox();
//++++++++++++++++++++++++++++++++++
//this is only visible in this method i.e the constructo
//make it visible to the whole class
//List local_jlist = new List();
//the correct code is
local_jlist = new List();
//local_jlist.setMargin(new Insets(0, 0, 0, 0));
List server_jlist = new List();
//server_jlist.setMargin(new Insets(0, 0, 0, 0));
JButton local_mkdir = new JButton("MkDir");
local_mkdir.setMargin(new Insets(0, 0, 0, 0));
JButton server_mkdir = new JButton("MkDir");
server_mkdir.setMargin(new Insets(0, 0, 0, 0));
JButton local_delete = new JButton("Delete");
local_delete.setMargin(new Insets(0, 0, 0, 0));
JButton server_delete = new JButton("Delete");
server_delete.setMargin(new Insets(0, 0, 0, 0));
JButton local_refresh = new JButton("Refresh");
local_refresh.setMargin(new Insets(0, 0, 0, 0));
JButton server_refresh = new JButton("Refresh");
server_refresh.setMargin(new Insets(0, 0, 0, 0));
Container contentPane = getContentPane();
BorderLayout border = new BorderLayout();
contentPane.setLayout(border);
contentPane.add(local_window, BorderLayout.WEST);
contentPane.add(server_window, BorderLayout.EAST);
contentPane.add(button_window, BorderLayout.CENTER);
contentPane.add (action_window, BorderLayout.SOUTH);
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(2, 2, 2, 2);
GridBagConstraints c1 = new GridBagConstraints();
c1.insets = new Insets(2, 2, 2, 2);
GridBagConstraints c2 = new GridBagConstraints();
c2.insets = new Insets(2, 2, 2, 2);
GridBagConstraints c3 = new GridBagConstraints();
c3.insets = new Insets(2, 2, 2, 2);
GridBagConstraints c4 = new GridBagConstraints();
c4.insets = new Insets(2, 2, 2, 2);
GridBagConstraints c5 = new GridBagConstraints();
c5.insets = new Insets(2, 2, 2, 2);
GridBagConstraints c6 = new GridBagConstraints();
c6.insets = new Insets(2, 2, 2, 2);
local_window.setLayout(gridbag);
server_window.setLayout(gridbag);
button_window.setLayout(gridbag);
action_window.setLayout(gridbag);
File[] drives = File.listRoots();
for(int i = 0 ; i