hi
im trying to make a GUI for a HTML parser
The problem is JProgressBar is not showing the progress, only updates when the
total have been downloaded.
I have been reading and the problem seems to be the Main thread is bloked by the actionperformed so i did try to convert the personalParser into a new Thread but still didnt work
the basic structure of my app is
How can i fix this ?Code:class gui{ JProgressBar preloader; JButton download; JLabel display; //other components ..... public gui(){ preloader=new JProgressBar (); download=new JButton ("Download"); display=new JLabel (""); myButtontListener mbl=new myButtontListener (preloader); download.addActionListener(mbl); //frame.add etc ....... } } class myButtontListener implements ActionListener{ JProgressBar preloader; personalParser myParser; JLabel display; public myButtontListener (JProgressBar bar, JLabel lbl){ preloader;=bar; display=lbl; } public void actionPerformed(ActionEvent event) { if( event.getActionCommand() == "Download" ){ myParser=new personalParser ("http://server.com/", preloader); String [] HtmlCode=myParser.getContentInArray(); display.setText(HtmlCode[5]); } } } class personalParser { JProgressBar preloader; String url public personalParser (String url,JProgressBar bar ){ preloader=bar; this.url=url; } public String[] getContentInArray(){ String [] code=new String[100]; //some net connections ........ //here i use a loop to fill the array and need to set the JProgressBar value //to display how many blocks of a especific tag have been downloaded and //added to the array String TagBlock=""; int count=0; while ((TagBlock = input.readLine()) != null) { count++; code[count]=TagBlock; preloader.setValue ( count ); } return code } }![]()


Reply With Quote


Bookmarks