comp.lang.java.programmer http://groups-beta.google.com/group/comp.lang.java.programmer [EMAIL PROTECTED]
Today's topics: * From 0 to "SUN CERTIFIED PROGRAMMER FOR THE JAVA 2" in 1 month? - 4 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6b63d2ac9ab490fe * Java trick - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/bfd25be52dc6a3ad * 'long' integer of 19 digits will not compile - 2 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7f5887b55eeaa33c * what u program? - 3 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ee20f99e67fd5410 * Beginner Advice Sought - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/b96a0a430a102e22 * method by property name - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/642915f103fe8568 * Exception Handling - 3 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a34b306b81d0e163 * Memory leakage problem with a database application - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/cd24fb0a93e5b285 * How to incremet IndetAddress / IP numbers - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/94897e32234ceaaf * simpleDateFormat and April month - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/383df9c88dcb10ba * Web Start, local classpath? - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2dbf202f1c3add8f * application Structure - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/27f54d1556bc79f5 ========================================================================== TOPIC: From 0 to "SUN CERTIFIED PROGRAMMER FOR THE JAVA 2" in 1 month? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6b63d2ac9ab490fe ========================================================================== == 1 of 4 == Date: Sun, Sep 19 2004 6:21 pm From: Sudsy <[EMAIL PROTECTED]> Paul Lutus wrote: <snip> > Sure, but if someone can move from zero to passing the test and actually > understanding all the information to function as professional Java > programmer in one month, he has no need for the certification. People will > be calling him up and begging him to work for them. Paul, you claim to be a dot-com millionaire so perhaps you've lost touch with reality, what with not needing to work and all. I suggest perusal of this article: <http://news.com.com/Study+400%2C000+IT+jobs+lost+since+2001/2100-1022_3-5364627.html> Truth of the matter is that you can be an exceptional developer and still not rise above the noise level in this extremely tight employment market. In most organizations today, HR sets the bar and performs the "weeding- out" based mostly on skill sets which may or may not be applicable to an advertised position. If you don't include the "politically correct" acronyms in your application and/or resume then you can't even expect an acknowledgement of receipt of same. They also discriminate based on age, knowing that someone fresh out of college can be paid significantly less than a seasoned professional. The fact that ageism is illegal doesn't seem to faze them when there's money to be saved and bonuses to be earned... Sorry, but that's just the way it is. == 2 of 4 == Date: Sun, Sep 19 2004 7:35 pm From: Paul Lutus <[EMAIL PROTECTED]> Sudsy wrote: > Paul Lutus wrote: > <snip> >> Sure, but if someone can move from zero to passing the test and actually >> understanding all the information to function as professional Java >> programmer in one month, he has no need for the certification. People >> will be calling him up and begging him to work for them. > > Paul, you claim to be a dot-com millionaire so perhaps you've lost > touch with reality, Actually I became a software millionaire before there was an Internet or anything remotely dot.commish. As to my being out of touch with reality, I think that is a valid criticism on the average day. :) > what with not needing to work and all. I suggest > perusal of this article: > <http://news.com.com/Study+400%2C000+IT+jobs+lost+since+2001/2100-1022_3-5364627.html> > Truth of the matter is that you can be an exceptional developer and > still not rise above the noise level in this extremely tight employment > market. My point is that an sufficiently talented person doesn't think of himself as property, and will start a company if none will hire him. That's exactly what I did. BTW I still get calls from headhunters. All that aside, I agree with your second point. > Sorry, but that's just the way it is. That depends on how original you are willing to be. -- Paul Lutus http://www.arachnoid.com == 3 of 4 == Date: Sun, Sep 19 2004 9:12 pm From: Steve Sobol <[EMAIL PROTECTED]> Paul Lutus wrote: > Actually I became a software millionaire Am I just a complete flaming idiot, or am I correct in remembering that you were heavily involved in some big software project back in the days of the Apple II? It's bugged me since the first time I saw you post here. I recognize the name, and your name is not a common one. -- JustThe.net Internet & New Media Services, http://JustThe.net/ Steven J. Sobol, Geek In Charge / 888.480.4NET (4638) / [EMAIL PROTECTED] PGP Key available from your friendly local key server (0xE3AE35ED) Apple Valley, California Nothing scares me anymore. I have three kids. == 4 of 4 == Date: Sun, Sep 19 2004 10:51 pm From: Paul Lutus <[EMAIL PROTECTED]> Steve Sobol wrote: > Paul Lutus wrote: > >> Actually I became a software millionaire > > Am I just a complete flaming idiot, or am I correct in remembering that > you were heavily involved in some big software project back in the days of > the Apple II? It's bugged me since the first time I saw you post here. I > recognize the name, and your name is not a common one. Nice recall! I wrote Apple Writer, one of the first non-crippled word processors, for the Apple II. It became an international best-seller. This verges on ancient history. Here's a bit of that history, recently posted on the Web for the first time: http://www.atariarchives.org/deli/cottage_computer_programming.php -- Paul Lutus http://www.arachnoid.com ========================================================================== TOPIC: Java trick http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/bfd25be52dc6a3ad ========================================================================== == 1 of 2 == Date: Sun, Sep 19 2004 6:35 pm From: "Gary Labowitz" <[EMAIL PROTECTED]> "Thomas G. Marshall" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] <<snip>> -- > Forgetthesong,I'dratherhavethefrontallobotomy... AndI'dratherhavethebottleinfrontofme -- Gary == 2 of 2 == Date: Sun, Sep 19 2004 7:26 pm From: Chris Smith <[EMAIL PROTECTED]> Thomas G. Marshall wrote: > The way he phrased this makes it very clear to me that > /of course/ he was being sarcastic. Okay, I didn't get that clearly, but that's why I added the parenthetical comment. -- www.designacourse.com The Easiest Way to Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation ========================================================================== TOPIC: 'long' integer of 19 digits will not compile http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7f5887b55eeaa33c ========================================================================== == 1 of 2 == Date: Sun, Sep 19 2004 7:19 pm From: "Keith Valentine" <[EMAIL PROTECTED]> Thanks Andrew for your help. Keith "VisionSet" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > "Keith Valentine" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> I am learning about integer types and I have found that when I try to >> compile code that assigns the highest or lowest 'long' integers to a > 'long' >> type variable I receive the errors: >> >> "integer number too large: -9223372036854775808" >> >> Or >> >> "integer number too large: 9223372036854775807" >> >> These values contain 19 digits, however values containing a maximum of 9 >> digits will compile without a problem. >> > > You are probably doing this: > > long lng = 9223372036854775807; > > which you can't do because the literal value 9223372036854775807 is being > taken as an integer which it obviously isn't. > You must do this: > > long lng = 9223372036854775807L; > > which tells the compiler you wish to have the literal treated as a long. > All literals are taken as an int unless you specify otherwise. > > The error message gives you a clue: > > "integer number too large" it has failed to recognise that you want it to > be > a long. > > -- > Mike W > > == 2 of 2 == Date: Sun, Sep 19 2004 7:22 pm From: "Keith Valentine" <[EMAIL PROTECTED]> Thanks for your help Mike. Keith "VisionSet" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > "Keith Valentine" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> I am learning about integer types and I have found that when I try to >> compile code that assigns the highest or lowest 'long' integers to a > 'long' >> type variable I receive the errors: >> >> "integer number too large: -9223372036854775808" >> >> Or >> >> "integer number too large: 9223372036854775807" >> >> These values contain 19 digits, however values containing a maximum of 9 >> digits will compile without a problem. >> > > You are probably doing this: > > long lng = 9223372036854775807; > > which you can't do because the literal value 9223372036854775807 is being > taken as an integer which it obviously isn't. > You must do this: > > long lng = 9223372036854775807L; > > which tells the compiler you wish to have the literal treated as a long. > All literals are taken as an int unless you specify otherwise. > > The error message gives you a clue: > > "integer number too large" it has failed to recognise that you want it to > be > a long. > > -- > Mike W > > ========================================================================== TOPIC: what u program? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ee20f99e67fd5410 ========================================================================== == 1 of 3 == Date: Sun, Sep 19 2004 7:50 pm From: jaYPee <[EMAIL PROTECTED]> On 18 Sep 2004 11:41:52 GMT, Joona I Palaste <[EMAIL PROTECTED]> wrote: >jaYPee <[EMAIL PROTECTED]> scribbled the following: >> I just wanted to know what most program [you] do in [Java]? [Because] >> [I'm] a [VB] >> programmer and [I] do a lot of database programming. > >> [Thanks] in advance > >I'm currently pretty much completely engaged in a large customer >project. Our customer is the Finnish state bureau for gambling - >Veikkaus OY. They want to upgrade their internal game winnings >monitoring system and we're implementing a new one for them. >Java-wise, this means a Servlet that basically acts as a gateway to a >humongous request-response -style database access program with >different customised information retrieval and update components. It's >more fun than it sounds, really. Thank you all for the information you've shared w/ me. I want to know also if java support cyrstal reports as a reporting tool when it comes to database programming. if not what is the reporting tool used by java? for those who critisized my question i asking for sorry. I'm asking 'cause I know that you can give me a simple answer from my simple question. It's hard to find a specific answer off the net. I also learn that this is not the correct group to ask this newbie question but it's too late 'cause i learn it after i posted my question here. sorry once again. == 2 of 3 == Date: Sun, Sep 19 2004 8:33 pm From: Peter Ashford <[EMAIL PROTECTED]> jaYPee wrote: > On 18 Sep 2004 11:41:52 GMT, Joona I Palaste <[EMAIL PROTECTED]> > wrote: > > >>jaYPee <[EMAIL PROTECTED]> scribbled the following: >> >>>I just wanted to know what most program [you] do in [Java]? [Because] >>>[I'm] a [VB] >>>programmer and [I] do a lot of database programming. >> >>>[Thanks] in advance >> >>I'm currently pretty much completely engaged in a large customer >>project. Our customer is the Finnish state bureau for gambling - >>Veikkaus OY. They want to upgrade their internal game winnings >>monitoring system and we're implementing a new one for them. >>Java-wise, this means a Servlet that basically acts as a gateway to a >>humongous request-response -style database access program with >>different customised information retrieval and update components. It's >>more fun than it sounds, really. > > > > Thank you all for the information you've shared w/ me. I want to know > also if java support cyrstal reports as a reporting tool when it comes > to database programming. if not what is the reporting tool used by > java? Java is a general purpose language - it does not have one single reporting tool. BTW Crystal reports java - use google. == 3 of 3 == Date: Sun, Sep 19 2004 8:29 pm From: Andrew Thompson <[EMAIL PROTECTED]> On Mon, 20 Sep 2004 10:50:16 +0800, jaYPee wrote: > for those who critisized my question i asking for sorry. The only people who do not make mistakes are those who either do nothing, or do nothing new, but.. > ...I also learn ... ..the *ability* to learn new things puts you ahead of most people, including a lot of those who are just *willing* to learn. I think you will gain a lot from posting to c.l.j.help, and you'll be back here *answering* questions very soon. :-) -- Andrew Thompson http://www.PhySci.org/codes/ Web & IT Help http://www.PhySci.org/ Open-source software suite http://www.1point1C.org/ Science & Technology http://www.lensescapes.com/ Images that escape the mundane ========================================================================== TOPIC: Beginner Advice Sought http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/b96a0a430a102e22 ========================================================================== == 1 of 2 == Date: Sun, Sep 19 2004 8:40 pm From: "jbeck" <[EMAIL PROTECTED]> Looking for recommendations as to the top two or three books to use to begin learning Java. Also, recommendations for compilers? == 2 of 2 == Date: Sun, Sep 19 2004 9:02 pm From: Andrew Thompson <[EMAIL PROTECTED]> On Sun, 19 Sep 2004 21:40:57 -0600, jbeck wrote: > Sub: Beginner Advice Sought ..beginners are best helped on a different group, described here.. <http://www.physci.org/codes/javafaq.jsp#cljh> > Looking for recommendations as to the top two or three books to use to begin > learning Java. That depends, is Java the first language you are learning? Are you already comfortable with OO design from other OO languages? Besides books, there are also the Sun Java tutorials, an offline version of the JavaDocs is very useful as well, as they are invaluable. There are also a lot of good resources listed and linked in my FAQ. <http://www.physci.org/codes/javafaq.jsp#res> > Also, recommendations for compilers? Get it free from Sun*. It is called the J2SDK. Or did you mean an IDE? The Sun Java compiler operates from the command line, or can be called from any number of IDE's, or ANT. * there are other SDK's besides Sun's, but it is the standard and it's free. Two points in it's favor. HTH -- Andrew Thompson http://www.PhySci.org/codes/ Web & IT Help http://www.PhySci.org/ Open-source software suite http://www.1point1C.org/ Science & Technology http://www.lensescapes.com/ Images that escape the mundane ========================================================================== TOPIC: method by property name http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/642915f103fe8568 ========================================================================== == 1 of 1 == Date: Sun, Sep 19 2004 9:46 pm From: "Adam P. Jenkins" <[EMAIL PROTECTED]> Check out the beanutils package from Jakarta. It has all sorts of useful classes and methods to make dealing with Java Beans much more convenient. http://jakarta.apache.org/commons/beanutils/ Adam "Timo Nentwig" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi! > > I want to get a Method by a Bean's property name - with one function call. > Is there some third-party helper package to do this? > > public class Test > { > private String thisIsMyCamelCaseProperty; > > public String getThisIsMyCamelCaseProperty() > { > ... > } > > Code I want to write: > > Method m = getMethod(Test.getClass(), "thisIsMyCamelCaseProperty"); ========================================================================== TOPIC: Exception Handling http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a34b306b81d0e163 ========================================================================== == 1 of 3 == Date: Sun, Sep 19 2004 10:10 pm From: "C-man" <[EMAIL PROTECTED]> I have this chunk of code that checks to see which radio button is selected out of a group of radio buttons. Basically is says if(radio1.isSelected() do a function. else if(radio2.isSelected()) do a diff function and so on. Basically I want to know which built in exception I should use to handle the last case else() provided that for some reason their is an error with the selection process. Or is their no built in exceptions, meaning I would have to write my own. Thanks == 2 of 3 == Date: Sun, Sep 19 2004 11:29 pm From: Jacob <[EMAIL PROTECTED]> C-man wrote: > I have this chunk of code that checks to see which radio button is selected > out of a group of radio buttons. Basically is says > if(radio1.isSelected() do a function. else if(radio2.isSelected()) do a diff > function and so on. Basically I want to know which built in exception I > should use to handle the last case else() provided that for some reason > their is an error with the selection process. Or is their no built in > exceptions, meaning I would have to write my own. I don't recall the radio behaviour, but if it allows for none selected than this is part of the model, and you should handle it properly without using exception (because there is nothing "exceptional" going on). If a radio group always ensures exactly one selection then there is no way your test can fail other then with forreign threads messing it up, in which case you have more serious problems to assess... In general: If you test for cases that cannot happen, you confuse your fellow programmers (or yourself two weeks down the road). You are indicating a possible flow of logic that is not there; You make your program more complex than necessary, and make maintainance harder. In short: Prefer a solid program crash for "impossible" cases. Think about it: What can you really do within the exception handler you are suggesting? If you actually are able to solve the users problem, then you should do that without the exception. And (to lanch a debate :-) Extenssive use of exception handling is a sign of programmer laziness in my opinion. If you take the time and consider all aspects of your data model and logic, there should be no room left for exceptional behaviour other than when dealing with external hardware (network, printers, ports, memory, etc.) == 3 of 3 == Date: Sun, Sep 19 2004 11:12 pm From: Paul Lutus <[EMAIL PROTECTED]> C-man wrote: > I have this chunk of code that checks to see which radio button is > selected out of a group of radio buttons. Basically is says > if(radio1.isSelected() do a function. else if(radio2.isSelected()) do a > diff function and so on. Basically I want to know which built in exception > I should use to handle the last case else() provided that for some reason > their is an error with the selection process. Or is their no built in > exceptions, meaning I would have to write my own. Just throw the exception that seems approprioate, or handle the error yourself without throwing an exception. It wouild be better, and easier, to prevent the original problem of having no radio buttons selected. Read this article to see how: http://java.sun.com/docs/books/tutorial/uiswing/components/button.html#radiobutton -- Paul Lutus http://www.arachnoid.com ========================================================================== TOPIC: Memory leakage problem with a database application http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/cd24fb0a93e5b285 ========================================================================== == 1 of 1 == Date: Sun, Sep 19 2004 10:13 pm From: Babu Kalakrishnan <[EMAIL PROTECTED]> Devian wrote: > [EMAIL PROTECTED] (Devian) wrote in message news:<[EMAIL PROTECTED]>... > >>BK I write a simple application to test my real application's logic >>and in that application I'm facing the same problem again.I want to >>tell about this program.I have a main frame(Frame2) and in that frame >>Frame1 is opened by clicking the related treenode.Frame1's close >>operation is set to DISPOSE_ON_CLOSE and Frame1 has a dispose >>monitor.When Frame1 is opened memory usage is increasing but when >>Frame1 is closed by clicking X button of the window memory never >>released.I dont understand what I'm doing wrong?Here is the code of >>Frame2: >> Without sample code that can be compiled and run on my machine, I cannot unfortunately check if your code does exhibit a memory leak or not. However, just want to clarify one thing - when you refer to your problem a "memory leak", how are you defining a memory leak ? The above observation (about memory usage increasing when Frame1 is opened but not decreasing when the frame is disposed) is pretty standard behaviour for most JVMs if you're only looking at the total memory used by the JVM. Most of the JVM implementations I've seen don't release memory back to the OS every time the memory requirement shrinks. What you'd want to check is if memory requirement continues to increase if you repeatedly open and dispose these frames (eventually resulting in a OutOfMemoryError). Also at least on the sun JVMs you can observe the reduction in memory usage by invoking GC manually and checking if the "used" memory reduces (The difference between the results of the totalMemory and freeMemory methods of the Runtime class). BK ========================================================================== TOPIC: How to incremet IndetAddress / IP numbers http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/94897e32234ceaaf ========================================================================== == 1 of 2 == Date: Sun, Sep 19 2004 10:26 pm From: Babu Kalakrishnan <[EMAIL PROTECTED]> Paul Lutus wrote: > Markus Kern wrote: > >>i now got another problem, >>what's a good way to compare two instances of InetAddress. >>I want to check if one InetAddress is smaller that another. > > > Compare the integers I had you create previously. You cannot apply a > criterion such as "smaller" to an InetAddress, but you can to an integer. > A simple integer comparison will not work if the desired order is 0.0.0.0 to 255.255.255.255. You really need unsigned integer comparison. BK == 2 of 2 == Date: Sun, Sep 19 2004 10:54 pm From: Paul Lutus <[EMAIL PROTECTED]> Babu Kalakrishnan wrote: > Paul Lutus wrote: >> Markus Kern wrote: >> >>>i now got another problem, >>>what's a good way to compare two instances of InetAddress. >>>I want to check if one InetAddress is smaller that another. >> >> >> Compare the integers I had you create previously. You cannot apply a >> criterion such as "smaller" to an InetAddress, but you can to an integer. >> > > A simple integer comparison will not work if the desired order is > 0.0.0.0 to 255.255.255.255. You really need unsigned integer comparison. Yes, quite so, but this approach and its variants is far simpler than what has been proposed until now. I suggest the use of a long for the purposes of simplifying the comparison, in which case the previously posted code will obligingly break it into the required bytes. -- Paul Lutus http://www.arachnoid.com ========================================================================== TOPIC: simpleDateFormat and April month http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/383df9c88dcb10ba ========================================================================== == 1 of 1 == Date: Sun, Sep 19 2004 11:58 pm From: [EMAIL PROTECTED] (Nurettin Arslankaya) Hi, For your information, the code for that i wrote for test purposes. Generally we did not left blank at least we place a message box there. /* the problematic part of my code is below */ import java.util.*; public class XMLIslem() public XMLIslem() { } public static Date MStrToDate(String Dt) throws ParseException { Date trh; String dts = Dt.trim(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleTimeZone tz=new SimpleTimeZone(0,"TURKEY/ANKARA"); tz.setStartYear(3000); formatter.setTimeZone(tz); tz.setDefault(tz); formatter.setTimeZone(TimeZone.getDefault()); if (dts.equals("")) { return ZeroDate; } trh = formatter.parse(dts); if (!dts.equals(formatter.format(trh))){ throw new ParseException(dts + " geçerli bir tarih değil. ",0); } return trh; } } /* the code above is throws exception because, the input text and formatted text are different. "February 31" is parsed without any error. But in other programming languages this text can throw error. So I need to recheck formatted text aganist to wrong data. But this test fails at daylight saving starts days. The code above is running correct. Possibly startyear may not needed. this code is working several places and operating systems (especially Windows based) we distribute Java runtime 1.4 that I am using. The error occured two times in previous. One at April, 1, 1980 and the other at April, 14, 1975. */ thanks for your interests. ========================================================================== TOPIC: Web Start, local classpath? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2dbf202f1c3add8f ========================================================================== == 1 of 2 == Date: Mon, Sep 20 2004 12:42 am From: [EMAIL PROTECTED] (JW) Hi All, I am using JBuilder to create a application, which is basically a swing client that accesses session beans deployed on Weblogic 8 server. I want other people to be able to download this application via Webstart. It seems I have to include all of weblogic-related classes (from weblogic.jar or webservices.jar) into my application .jar file, but this makes it 90 MB. Assuming the client machines (machines needing to download my application) have the appropriate weblogic .jar files on them already, can I have webstart look for the necessary jar files in the classpath of the client machine so that I don't have a 90 MB .jar file to download? Thanks! == 2 of 2 == Date: Mon, Sep 20 2004 12:54 am From: Andrew Thompson <[EMAIL PROTECTED]> On 20 Sep 2004 00:42:33 -0700, JW wrote: > I am using JBuilder to create a > application, which is basically a swing > client that accesses session beans deployed > on Weblogic 8 server. > > I want other people to be able to download > this application via Webstart. Do you want them to be able to load the session beans when thay are off-line? Or will the clients have a permanent or readily available internet connection? -- Andrew Thompson http://www.PhySci.org/codes/ Web & IT Help http://www.PhySci.org/ Open-source software suite http://www.1point1C.org/ Science & Technology http://www.lensescapes.com/ Images that escape the mundane ========================================================================== TOPIC: application Structure http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/27f54d1556bc79f5 ========================================================================== == 1 of 1 == Date: Mon, Sep 20 2004 1:21 am From: "news.skynet.be" <[EMAIL PROTECTED]> Hello. I am a beginner at this Java stuff, so bear with me. I have been writing an imaging application as a way of learning Java. I have got little bits working and tied them together in an application. But now I am looking to tune, or correctly model, the application use threads to improve performance. What I am looking for is if I have structured my application in a logical way and if I have where would it be useful to apply threads. Below is the code of the application if someone could take a quick look and see if I have made any major blunders with my structure and where they would apply threads. Thanks for taking the time to read. import java.awt.*; import java.io.*; import java.awt.event.*; import java.awt.geom.*; import java.awt.image.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import javax.swing.UIManager; import java.util.LinkedList; import java.awt.image.BufferedImage; import javax.imageio.*; //start of new image processor class class newImgProc2 extends JComponent{ private BufferedImage source, destination; public JComboBox options; public int startX, startY, endX, endY, ix, iy, rectH, rectW; public LinkedList lLsUndo = new LinkedList(); public int undoFlag = 0; public JScrollPane iScroll; public boolean swap = false; public newImgProc2( BufferedImage image ) {//extend buffered image to include undo handler source = destination = image; setBackground(Color.white); setLayout(new BorderLayout()); // create a panel to hold the combo box JPanel controls = new JPanel(); JPanel nuCont = new JPanel(); //use my button creator class to create a button ButtCreator butt1 = new ButtCreator("myBright","graphics/bright.gif","graphics/roll.gif","Make Brighter"); ButtCreator butt2 = new ButtCreator("myScale","graphics/scale.gif","graphics/roll.gif","Scale Down"); ButtCreator bLoad = new ButtCreator("myLoad","graphics/load.gif","graphics/roll.gif","Load a File"); ButtCreator bSave = new ButtCreator("mySave","graphics/save.gif","graphics/roll.gif","Save a File"); ButtCreator bDark = new ButtCreator("myDark","graphics/dark.gif","graphics/roll.gif","Make Darker"); ButtCreator bRot = new ButtCreator("myRotate","graphics/rotate.gif","graphics/roll.gif","Rotate the image"); ButtCreator bUndo = new ButtCreator("myUndo","graphics/undo.gif","graphics/roll.gif","Undo"); ButtCreator bRedo = new ButtCreator("myRedo","graphics/redo.gif","graphics/roll.gif","Redo"); controls.add(butt1); controls.add(bDark); controls.add(butt2); controls.add(bLoad); controls.add(bSave); controls.add(bRot); nuCont.add(bUndo); nuCont.add(bRedo); add(controls, BorderLayout.NORTH); add(nuCont, BorderLayout.SOUTH); //------ //add an event handler //add the event listener to the object ProcButt pB = new ProcButt(); butt1.addActionListener(pB); butt2.addActionListener(pB); bLoad.addActionListener(pB); bSave.addActionListener(pB); bDark.addActionListener(pB); bUndo.addActionListener(pB); bRedo.addActionListener(pB); bRot.addActionListener(pB); } //undo method public void updateUndoAr(BufferedImage img){ lLsUndo.add(undoFlag,img); undoFlag = undoFlag+1; if(lLsUndo.size()>undoFlag){ for (int i=undoFlag;i<=lLsUndo.size();i++){ lLsUndo.remove(i); } } } public void undoUndoAr(){ try{ System.out.println("before undo "+undoFlag); if(undoFlag-1>=0){ undoFlag = undoFlag-1; } BufferedImage last = (BufferedImage)lLsUndo.get(undoFlag); setTheImage(last); System.out.println("after undo "+undoFlag); } catch( IndexOutOfBoundsException e){ Toolkit.getDefaultToolkit().beep(); JPanel warn = new JPanel(); JOptionPane.showMessageDialog(warn, "ERROR: Undo Error!\n\t\tNothing left to undo!\n"+e); } } public void redoUndoAr(){ try{ System.out.println("f before redo "+undoFlag); undoFlag = undoFlag+1; System.out.println("f after redo "+undoFlag); BufferedImage last = (BufferedImage)lLsUndo.get(undoFlag); setTheImage(last); } catch( IndexOutOfBoundsException e){ Toolkit.getDefaultToolkit().beep(); JPanel warn = new JPanel(); JOptionPane.showMessageDialog(warn, "ERROR: Redo Error!\n\t\tNothing more to redo!\n"+e); } } //class procButt implements ActionListener, UndoableEditListener{ class ProcButt implements ActionListener{ public void actionPerformed(ActionEvent e){ String b = e.getActionCommand();//teh name of the button BufferedImageOp op = null; if(b.equals("myBright")){ op = new RescaleOp(1.5f, 0, null); } else if(b.equals("myUndo")){ undoUndoAr(); } else if(b.equals("myRedo")){ redoUndoAr(); } else if(b.equals("myScale")){ op = new AffineTransformOp(AffineTransform.getScaleInstance(.75, .75), null); } else if(b.equals("myLoad")){ getImage(); } else if(b.equals("myRotate")){ op = new AffineTransformOp(AffineTransform.getRotateInstance(Math.PI / 6), null); } else if(b.equals("myDark")){ op = new RescaleOp(.5f, 0, null); } else if(b.equals("mySave")){ try{ outputFile(); } catch(Exception exp){ System.out.println(exp); } } if (op != null){ updateUndoAr(destination); destination = op.filter(source, null); source = destination; } repaint(); } } //class to deal with painting the thing public void paintComponent(Graphics g) { int imageWidth = destination.getWidth(); int imageHeight = destination.getHeight(); int width = getSize().width; int height = getSize().height; g.drawImage(destination,0, 0, null); //start listeners addMouseListener(new MouseAdapter(){ public void mousePressed(MouseEvent e){ startX = e.getX(); startY = e.getY(); } public void mouseReleased(MouseEvent e){ updateUndoAr(destination); BufferedImage my; if(swap == true){ my = source.getSubimage(ix,iy,rectW,rectH); swap = false; } else{ my = source.getSubimage(startX,startY,rectW,rectH); swap = false; } source = my; destination = source; repaint(); } }); addMouseMotionListener(new MouseMotionAdapter(){ public void mouseDragged(MouseEvent e){ repaint(); ix = e.getX(); iy = e.getY(); if(ix>startX){ rectW = ix - startX; } else{ rectW = startX - ix; swap = true; } if(iy>startY){ rectH = iy - startY; } else{ rectH = startY - iy; swap = true; } Graphics g2 = getGraphics(); if(swap == true){ g2.drawRect(ix,iy,rectW,rectH); } else{ g2.drawRect(startX,startY,rectW,rectH); } } }); //end list } // temp output file bit public void outputFile() throws Exception{ //start of the output stuff FileOutputStream fo = new FileOutputStream("graphics/myImg.jpg"); BufferedOutputStream bo = new BufferedOutputStream(fo); ImageIO.write(destination, "jpeg", bo); bo.close(); //finding the size of teh image in memory ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(destination, "jpeg", baos); System.out.println("data in mem = "+baos.size()); baos.close(); } // EOF temp outupt file bit // load file from users HD method public void getImage(){ JFileChooser dlg = new JFileChooser(); //disable the file dialog from showing all dlg.setAcceptAllFileFilterUsed(false); dlg.addChoosableFileFilter(new DialogFilter()); int r = dlg.showDialog(this, "Load Image"); if( r == JFileChooser.CANCEL_OPTION){ return; } try{ File f = dlg.getSelectedFile(); java.net.URL url = f.toURL(); ImageIcon icn = new ImageIcon(url); System.out.println(icn.getImageLoadStatus()); //gets the size of the local file long sizeLocal = f.length(); System.out.println("local size of file from dialog "+sizeLocal); Image fi = icn.getImage(); // draw the Image into a BufferedImage int w = fi.getWidth(null), h = fi.getHeight(null); //buffImage is being passed to the image processor class BufferedImage fBuff = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D imageGraphics = fBuff.createGraphics(); setTheImage(fBuff); scaleTheImage(fBuff); //end paste from main } catch(Exception e){ System.out.println("could not load file"); } } //end of load file method private Rectangle getAffectedArea(int oldX, int oldY, int newx, int newy, int width, int height) { int x = Math.min(oldX, newx); int y = Math.min(oldY, newy); int w = (Math.max(oldX, newx) + width) - x; int h = (Math.max(oldY, newy) + height) - y; return new Rectangle(x, y, w, h); } //if the image is being sent in from an extended class, then reset it here public void setTheImage(BufferedImage iImg){ source = iImg; destination = source; repaint(); } public void scaleTheImage(BufferedImage iImg){ BufferedImageOp op; int w = iImg.getWidth(); int h = iImg.getHeight(); op = new AffineTransformOp(AffineTransform.getScaleInstance(.5, .5), null); destination = op.filter(source, null); source = destination; } //so an external class can get the image public BufferedImage retTheImage(){ return source; } } //end of new image processor class //********************** class outTheImage2 extends newImgProc2{ private BufferedImage theImage; public outTheImage2(BufferedImage theImage){ super(theImage); scaleTheImage(); } public void scaleTheImage(){ //get the current image from the parent BufferedImage thisImg = super.retTheImage(), destImg; int w = thisImg.getWidth(); int h = thisImg.getHeight(); BufferedImageOp op; //transform the image op = new AffineTransformOp(AffineTransform.getScaleInstance(.5, .5), null); destImg = op.filter(thisImg, null); //set the image back to the parent super.setTheImage(destImg); } } //creates the frame of the whole application class ImageProcCanvas2 extends JFrame{ public ImageProcCanvas2(outTheImage2 thisImage, int w, int h){ JFrame.setDefaultLookAndFeelDecorated(true); try{ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel " ); } catch(Exception e){ System.out.println(e); } JFrame frame = new JFrame("OGRe Image Processor"); frame.getContentPane().add(thisImage); int myH = h +200; frame.setSize(w, myH); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); frame.setVisible(true); } } //********************** public class BufferedImage002 { public static void main(String args[]){ String filename = "graphics/desk001.jpg"; String outFileName = "outImg.jpg"; // get the image from hd or could be url ImageIcon icon = new ImageIcon(filename); Image i = icon.getImage(); // draw the Image into a BufferedImage int w = i.getWidth(null), h = i.getHeight(null); //buffImage is being passed to the image processor class BufferedImage buffImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); //create the image Graphics2D imageGraphics = buffImage.createGraphics(); imageGraphics.drawImage(i, 0, 0, null); //get the height of the buffered image int width = buffImage.getWidth()+40; int height = buffImage.getHeight()+80; //scale the buffered image outTheImage2 i1 = new outTheImage2(buffImage); //set up a new frame to deal with the whole app ImageProcCanvas2 newOgre = new ImageProcCanvas2(i1, width, height); } } //********************** There are two other objects too. One for creating the buttons and one for filtering the dialog to show only images on the users HD. I think this maybe too much to take in in one go.. but thanks for taking the time to read this far. cheers Martin -- --------------- http://www.nonstoploop.co.uk/ - dynamic websites http://www.rossanobacchin.be/ - fine art http://www.weycameras.co.uk/ - photographic supplies --------------- ======================================================================= You received this message because you are subscribed to the Google Groups "comp.lang.java.programmer". comp.lang.java.programmer [EMAIL PROTECTED] Change your subscription type & other preferences: * click http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe Report abuse: * send email explaining the problem to [EMAIL PROTECTED] Unsubscribe: * click http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe ======================================================================= Google Groups: http://groups-beta.google.com
