Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 03-07-2013, 09:28 PM   #1
Baseband Member
 
drill's Avatar
 
Join Date: Mar 2013
Location: US
Posts: 34
Default Java Programming Application

Hello CF! I have made a Java application (the application really is not impressive at all), but it is a clipboard memory program.

How it works: The program will make a list of copied items. To get the item you want, first click the window. Then scroll with the arrow keys to the item you want in your clipboard. Press "Enter". Now the selected item is in your clipboard.


Requirements: Java 7 (works on Linux and Windows, Mac is untested but will probably work)


Things not to do: -do not copy anything but images and text (However, both CAN be copied at the same time)

-do not copy online material (save it first as an image or put the text in word first, then copy it)

-do not hibernate with the program on


NOTE: Items in the "Things not to do" will most likely be fixed in the future


If there are any bugs you see do not hesitate to report them to me.

Also, I am welcome to suggestions for the application.


Now, here is the link:

https://www.dropbox.com/sh/fbtyvcirtvm4nwd/KusrIhfELo
__________________

__________________
drill is offline   Reply With Quote
Old 03-08-2013, 02:02 AM   #2
In Runtime
 
Fujitsu_Technician's Avatar
 
Join Date: Sep 2012
Location: UK
Posts: 284
Default Re: Java Programming Application

good work however I do not trust jarva as it is main source for virus attacks but I always repect people who can write in jarva and and for making the effort to make applications I use VB.net myself and I know how frustrating it is when people don't trust what you have made becuase the anti virus states it is a theat because it does not know the application or herd of it before and becuase you do not have a website on the product if it was uploaded to a website and published from a website the av is happy so I don't bother making applications anymore for the public just for familey and friends and companys like Citizans advice who no me and trust what I write is good content.

Best of Luck I hope you do better than I did.

Kind Regards
__________________

__________________
Fujitsu_Technician is offline   Reply With Quote
Old 03-08-2013, 06:36 AM   #3
Site Team
 
berry120's Avatar
 
Join Date: Jul 2009
Location: England, UK
Posts: 3,434
Default Re: Java Programming Application

Quote:
good work however I do not trust jarva as it is main source for virus attacks
Nah, Java applets have been frought with security holes for ages (which is why most modern browsers disable them by default anyway) but desktop Java is as secure as anything else.

Nice little starter app, although it's not resizable and doesn't scroll? Can't see the source because you haven't attached it to the jar, but try adding your main component to a scrollpane and making the JFrame resizable, which should solve that issue.
__________________
Save the whales, feed the hungry, free the mallocs.
berry120 is offline   Reply With Quote
Old 03-08-2013, 09:08 AM   #4
Baseband Member
 
drill's Avatar
 
Join Date: Mar 2013
Location: US
Posts: 34
Default Re: Java Programming Application

Quote:
Originally Posted by berry120 View Post
Nice little starter app, although it's not resizable and doesn't scroll? Can't see the source because you haven't attached it to the jar, but try adding your main component to a scrollpane and making the JFrame resizable, which should solve that issue.
Thanks! And yes it does scroll, you must use the arrow keys. I have never used the jscrollpane at all before, so it just seemed easier this way. That will be one of the things I add to this program, and probably the ability to use the mouse instead of relying on the enter key. Also, I guess I could make it resizable too, I guess I was thinking that wouldnt be a feature that people would want, but I guess I was wrong. Anyway, I attached the source file for you in case you still wanted to see it.

https://www.dropbox.com/s/w13h37kcbc...boardFile.java
__________________
drill is offline   Reply With Quote
Old 03-08-2013, 04:39 PM   #5
BSOD
 
Join Date: Feb 2013
Location: Parallel Universe
Posts: 313
Default Re: Java Programming Application

Any chance of looking at the souce code, its not attated to the jar.

Nice little applet.
__________________
XPikachu is offline   Reply With Quote
Old 03-08-2013, 04:48 PM   #6
Baseband Member
 
drill's Avatar
 
Join Date: Mar 2013
Location: US
Posts: 34
Default Re: Java Programming Application

Quote:
Originally Posted by Pichu View Post
Any chance of looking at the souce code, its not attated to the jar.

Nice little applet.

Thanks! And yes, here it is:

https://www.dropbox.com/s/w13h37kcbc...boardFile.java
__________________
drill is offline   Reply With Quote
Old 03-08-2013, 05:17 PM   #7
BSOD
 
Join Date: Feb 2013
Location: Parallel Universe
Posts: 313
Default Re: Java Programming Application

Very tidy code well done.

I am going to start moving away from Java and get into MYOB.
__________________
XPikachu is offline   Reply With Quote
Old 03-08-2013, 07:38 PM   #8
Site Team
 
berry120's Avatar
 
Join Date: Jul 2009
Location: England, UK
Posts: 3,434
Default Re: Java Programming Application

Quote:
Originally Posted by drill View Post
Actually, and not meaning to be critical, but amongst other things that code has the potential for a few bugs in the GUI code because of threading issues. When I've got a bit more time I can run through them if you'd like?
__________________
Save the whales, feed the hungry, free the mallocs.
berry120 is offline   Reply With Quote
Old 03-08-2013, 08:12 PM   #9
In Runtime
 
Fujitsu_Technician's Avatar
 
Join Date: Sep 2012
Location: UK
Posts: 284
Default Re: Java Programming Application

Quote:
Originally Posted by drill View Post
Hello CF! I have made a Java application (the application really is not impressive at all), but it is a clipboard memory program.

How it works: The program will make a list of copied items. To get the item you want, first click the window. Then scroll with the arrow keys to the item you want in your clipboard. Press "Enter". Now the selected item is in your clipboard.


Requirements: Java 7 (works on Linux and Windows, Mac is untested but will probably work)


Things not to do: -do not copy anything but images and text (However, both CAN be copied at the same time)

-do not copy online material (save it first as an image or put the text in word first, then copy it)

-do not hibernate with the program on


NOTE: Items in the "Things not to do" will most likely be fixed in the future


If there are any bugs you see do not hesitate to report them to me.

Also, I am welcome to suggestions for the application.


Now, here is the link:

https://www.dropbox.com/sh/fbtyvcirtvm4nwd/KusrIhfELo

as long as you are happy with your work drill that is the main thing as it is not my adopted launage I don't tend to run jarva application much well not JAR files anyway but I respect you for your work and shear your views on programming like I do any one who can program as there is so much to learn in each language Best of luck.

Kind Regards
__________________
Fujitsu_Technician is offline   Reply With Quote
Old 03-08-2013, 08:28 PM   #10
Baseband Member
 
drill's Avatar
 
Join Date: Mar 2013
Location: US
Posts: 34
Default Re: Java Programming Application

Quote:
Originally Posted by berry120 View Post
Actually, and not meaning to be critical, but amongst other things that code has the potential for a few bugs in the GUI code because of threading issues. When I've got a bit more time I can run through them if you'd like?

Sure, be my guest. I always look forward to learning how to code better
__________________
drill is offline   Reply With Quote
Old 03-09-2013, 08:30 AM   #11
Site Team
 
berry120's Avatar
 
Join Date: Jul 2009
Location: England, UK
Posts: 3,434
Default Re: Java Programming Application

Quote:
Originally Posted by drill View Post
Sure, be my guest. I always look forward to learning how to code better
In that case, here goes!

First off, I'm not sure how much experience you have with either / or Swing and threading? There's a few rules that need to be followed to guarantee that your application will be free of threading bugs, and the main one in this instance is that you must only ever do anything to Swing components if you're running on the event dispatch thread (see here for details.)

Quote:
This is necessary because most Swing object methods are not "thread safe": invoking them from multiple threads risks thread interference or memory consistency errors.
Granted, some Swing objects *are* thread safe, but for the moment assume that none are - it's considered good practice to just do everything that needs to be done in Swing on the EDT.

In your case, the update() method is called from an arbitrary thread which is most definitely *not* the EDT (it's one that you've just created), so this is especially dangerous since the two are running concurrently. (No, you might not usually run into these problems with simple applications, but for more advanced ones you definitely will at some point, so pays to have it right straight off.)

If you're not on the EDT but you want to execute a piece of Swing code on the EDT, then it's relatively easy to do:

Code:
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            //Code to run on the EDT goes here.
        }
    });
This essentially schedules a runnable to be executed on the EDT - it will be invoked at some point in the near future. If you want to wait until that drawing code is complete (which isn't usually what you want but is available anyway) then use invokeAntWait() rather than invokeLater(). As you've probably already found, if you attempt to do *everything* on the EDT then your application will just appear to lock up while these tasks are completing, not what you want.

You may be starting to realise there's more to threading than you first thought - it's a hugely complicated topic, entire books have been written on threading issues you can come across just in Java (Java concurrency in practice is a great book if you're interested, but not for the beginner.) Introducing threading to your application unlocks a whole potential hive of livelocks, deadlocks, race hazards and so on, and many will be unpredictable and hard to track down. So use threads wisely, and only when you have to

In terms of other points, overall it's not bad but I'd suggest a few style / misc changes:
  • Comments are a bit sparodic - you've put one about declaring the variables, but this isn't really needed (it's obvious to anyone reading the code that's what you're doing.) However, you should really comment all methods and explain what they do, because that isn't so obvious. In these comments you can put things like whether the method needs to be executed on the EDT or not in order to aid others that may be using your code. Might not be important now, but in a team of people or on a large codebase good commenting gets incredibly important. Use the set Javadoc style for this.
  • Your imports are a bit sparodic - you've got one star one and the rest are just individual imports. I'd advocate using individual imports for everything, since it makes it clearer to the reader what you're importing and mitigates name clashes (two classes with the same name in different packages you may be importing.) Whatever you choose, make it consistent.
  • A lot of things are static that shouldn't be static - unless you can really justify it, nothing should really be static (at least tell yourself that to start with.) I see nothing in that class that should really be static.
  • With fields such as "private static ArrayList<JLabel> labels = new ArrayList<JLabel>();" - first off you don't need the second JLabel class, you can use diamond, and secondly it's better practice to use an interface type for the field rather than tying it to an implementation - it makes things much easier to swap out that way. So it would become: "private static List<JLabel> labels = new ArrayList<>();" (where list is java.util.List.)

So overall, it's not bad - but there are definitely things you can work on even if you want to just keep the same level of functionality!
__________________
Save the whales, feed the hungry, free the mallocs.
berry120 is offline   Reply With Quote
Old 03-09-2013, 09:21 AM   #12
Baseband Member
 
drill's Avatar
 
Join Date: Mar 2013
Location: US
Posts: 34
Default Re: Java Programming Application

Quote:
Originally Posted by berry120 View Post
First off, I'm not sure how much experience you have with either / or Swing and threading?
As you guessed, I am very new to threading. So new that this is my first application that involves threading. And to be honest, I didnt hear of EDT until just now. I will probably fix a good bit of my code up later today when I have more time. Also, I dont remember why I had all those statics (as I wrote this a couple weeks ago and I have a very bad memory), but I remember coming across errors, and all I had to do was declare the variable a static to fix them (yes I usually go the path of least resistance).

You taught me a lot about threading today so

---------- Post added at 09:21 AM ---------- Previous post was at 09:19 AM ----------

Quote:
Originally Posted by Fujitsu_Technician View Post
as long as you are happy with your work drill that is the main thing as it is not my adopted launage I don't tend to run jarva application much well not JAR files anyway but I respect you for your work and shear your views on programming like I do any one who can program as there is so much to learn in each language Best of luck.

Kind Regards
Well thanks, and I can understand your hesitance to use java apps as that I have seen it before. If you ever change your mind about them you are welcome to use the java apps that I post.
__________________
drill is offline   Reply With Quote
Old 03-09-2013, 09:24 AM   #13
Site Team
 
berry120's Avatar
 
Join Date: Jul 2009
Location: England, UK
Posts: 3,434
Default Re: Java Programming Application

Quote:
Originally Posted by drill View Post
As you guessed, I am very new to threading. So new that this is my first application that involves threading. And to be honest, I didnt hear of EDT until just now. I will probably fix a good bit of my code up later today when I have more time. Also, I dont remember why I had all those statics (as I wrote this a couple weeks ago and I have a very bad memory), but I remember coming across errors, and all I had to do was declare the variable a static to fix them (yes I usually go the path of least resistance).

You taught me a lot about threading today so
It was probably because you came across an error that went something like "non-static variable cannot be referenced from a static context" - in this case making everything static appears to fix the error quite quickly, but in fact breaks the OO model, since whatever you make static will no longer be tied to the object, it will be tied to the class instead (which while it seems to work in the trivial case, usually isn't what you want at all.)

And you're welcome in terms of the threading stuff, just be aware that it's not nearly as trivial as it might seem in the majority of cases. The java.util.concurrent package has some really useful classes in this regard and supports all sorts of things, but perhaps best to leave that until a bit later
__________________

__________________
Save the whales, feed the hungry, free the mallocs.
berry120 is offline   Reply With Quote
Reply

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
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 12:38 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0
×