Fedora Linux Support Community & Resources Center
  #1  
Old 25th May 2010, 07:39 PM
bigboss2200 Offline
Wondering Where I Am
 
Join Date: Oct 2005
Posts: 309
linuxfedorafirefox
Cool My first java application - dedicated to Fedora (feedbacks are welcomed)

I've created a small application "that is not completed yet, and still under heavy development" for Fedora.. and here is a screenshot:



The application "simply" is dedicated for those with a fresh fedora installation, or those who are using Fedora for the first time.. It downloads & installs (for now) some certain Repos like Livna, and RPM-Fusion, and some multimedia applications.. then it posts the terminal output into an embeded text viewer..

Please note that the application is still in its first development process, its not completed, and you may encounter some problems.. the main serious problem I'm facing now is that when a user presses the "Download" button, the application seems like its hanging, while infact its downloading and installing.. The whole "terminal" text comes to my dedicated "text field" at once..! not command by command, which what I'm trying to solve..

Any suggestion or feedback (weither its negative or positive) is more than welcome..

HowTo use my application (you have to have Java Development Kit installed):
1- put "script" and "NewJFrame2.java" into one folder
2- open terminal, become root
3- sh script
Attached Files
File Type: gz Application.tar.gz (2.8 KB, 43 views)
__________________
Code:
[Faris@localhost ~]$ cat /dev/urandom > /dev/dsp
http://farisguides.webs.com

Last edited by bigboss2200; 25th May 2010 at 08:23 PM.
Reply With Quote
  #2  
Old 26th May 2010, 03:34 AM
cliff76 Offline
Registered User
 
Join Date: May 2005
Location: PA
Age: 37
Posts: 14
macossafari
Re: My first java application - dedicated to Fedora (feedbacks are welcomed)

Ok I haven't actually looked at your source but I've done this sorta thing enough to know where your main issues probably are. The hanging problem comes from running long running tasks on the Event Dispatch Thread or main GUI thread. This is a no-no with most GUI development, Java, SWT, mobile, and otherwise. In your event handler for the download button you need to immediately spawn a thread to perform the download work. You're probably writing the process stderr and stdout into a big String then dumping it into the text field. You want to spawn a thread that reads both of these and then updates the text field using SwingUtilities.invokeLater(). It's very important you use SwingUtilities here because you're only supposed to update the GUI on the event dispatch thread. Also your timing is off by about a day. If you had put this out yesterday I would have loved to use it because it sounds like exactly what I was looking for as I just made a switch to Fedora. I would try using it now but its kind of late and my desktop is in the office, not responding to my remote session so I'm unable. Now that I've guessed at your problems I'll open the source to see how accurate my guesses were. Oh, and good job!

---------- Post added at 10:34 PM CDT ---------- Previous post was at 10:11 PM CDT ----------

Reading through your code quickly and it looks like you're on the right track. I think you'll want to use 2 text areas, one for stdout and one for stderr. Then you'll want to add a method like so:

Code:
		public void processStreamUsingTextArea(final InputStream aStream, final JTextArea textArea) {
			final BufferedReader reader =  new BufferedReader(new InputStreamReader(aStream));
			new Thread(
				new Runnable(){
					public void run(){
		 	            while ((s = reader.readLine()) != null) {
		 	            	System.out.println(s);
							SwingUtilities.invokeLater(new Runnable() {
								public void run() {
									textArea.append(text);
							      }
							    });
		 	            }
					}
				}
			).start();
		}
From here you just need to move your cmd execution off the event thread and onto its own thread. This will fix the hanging problem and should allow the cmd results to show incrementally in the text area(s). Try something like this:

Code:
	private void btnVLCActionPerformed(ActionEvent evt) {
		System.out.println("btnVLC.actionPerformed, event="+evt);
		new Thread(
		new Runnable(){
			public void run() {
				if (chkRpmFusionFree.isSelected() == true)
				{
					command("rpm -ivh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm");
				}
				if (chkRpmFusionNonFree.isSelected() == true)
				{
					command("rpm -ivh http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm");
				}
				if (chkLivnaRelease.isSelected()==true)
				{
					command("rpm -ivh http://rpm.livna.org/livna-release.rpm");
				}
				if (chkVLC.isSelected() == true)
				{
					command("yum install vlc");
				}
				if (chkMPlayer.isSelected() == true)
				{
					command("yum install -y mplayer mplayer-gui gecko-mediaplayer mencoder");
				}
				if (chkMMS.isSelected() == true)
				{
					command("yum install xmms xmms-mp3 xmms-faad2 xmms-pulse xmms-skins");
				}
			}
		}
		).start();
	}

	public void command (String command)
	  {
					String s = null;   
				 	   try {
				 		   		Process p = Runtime.getRuntime().exec(command);
								processStreamUsingTextArea(p.getInputStream(), textArea);
								processStreamUsingTextArea(p.getErrorStream(), textArea);
								p.waitFor();
				 	        }
				 	   
				 	        catch (IOException e1) {
				 	            System.out.println("exception happened - here's what I know: ");
				 	            e1.printStackTrace();
				 	            System.exit(-1);
				 	        }
			}
That's completely untested but should give you the rough idea. Also you'll need to add a second text field with this approach as errors will mix with normal stdout stuff.
__________________
:eek: Holla' at me... :cool:
Reply With Quote
  #3  
Old 10th June 2010, 12:34 PM
bigboss2200 Offline
Wondering Where I Am
 
Join Date: Oct 2005
Posts: 309
linuxfedorafirefox
Re: My first java application - dedicated to Fedora (feedbacks are welcomed)

@cliff76

Sorry for my late reply.. but your code worked like magic..! thanks alot..! now I can complete whatever I'm doing, and I will post it as soon as its finished ..
__________________
Code:
[Faris@localhost ~]$ cat /dev/urandom > /dev/dsp
http://farisguides.webs.com
Reply With Quote
Reply

Tags
application, dedicated, fedora, feedbacks, java, welcomed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
fedora 9 feedbacks pcandpc Fedora Focus 2 14th May 2008 06:11 AM
Problem with Tomcat / Sun Application 9.1 using java 1.5/1.6 under Fedora 8 pinoycode Using Fedora 0 29th April 2008 01:31 PM
Some welcomed cooperation... tomcat Linux Chat 2 26th August 2007 06:22 PM
CPU/RAM dilemma. Feedback Welcomed ^_^ downhillgames Linux Chat 2 6th August 2007 08:56 AM
Java Application gc2105 Using Fedora 4 27th October 2005 03:02 AM


Current GMT-time: 06:57 (Tuesday, 18-06-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat