Steffen Reinhard

Greenhorn
+ Follow
since Jun 13, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Steffen Reinhard

Hi all!
I don't get a really good grasp of the Enum concept. What is the advantage of using Enums? Why shouldn't I just, well, use primitive-value constants for example? Or, for reference-type values a Collection of the reference type defined in an inner class? Thanks in advance -

cheers,

Steffen
Hi everybody!

I wrote some code overwriting JPanel's paintComponent() method and put it in a convenience JFrame.


When I run it the Rectangle drawn in paintComponent() is sometimes shown and sometimes it isn't. If it isn't I have to force a repaint by changing JFrame's size and then it is shown ... bizarre! Any Ideas, anybody?

Thanks in advance for any hint on how to solve this problem.
16 years ago

Originally posted by francis varkey:
Dear Sirs,

Here is a program. When clickin a button a progreesbar is appear in indeterminata mode and setting some messages to a textarea. This is working.
But I want to display the bar independent of work of textarea. Please advise.



Hi Francis,

your JProgressBar is working independently from any action in your JTextArea, as you never set any value. Immediately after creation your JProgressBar starts displaying errrr... indeterminate progress. That is, it starts jogging along happily but doesn't really show any real progress. Try the following code (and mind I just put in the JLabel for demonstration purposes, the JProgressBar is really controlled by the value of the counter variable):




There is, however, a class javax.swing.ProgressMonitor which pops up a configurable dialog with a JProgressBar, the usual ok/cancel buttons and a message that can be customized to meet your specific needs.


Hope this helps.

Cheers,

Steffen

[ January 04, 2007: Message edited by: Steffen Reinhard ]
[ January 04, 2007: Message edited by: Steffen Reinhard ]
17 years ago

Originally posted by shri balaji:
any one can help me out about installing java compiler and including java bin and etc etc.... and where is the path i should include bin?



Hi Shri,

first you need to go to
JDK 6.0 Download page
to get the current JDK (which is version 6.0 as of now). The smaller JRE download won't do as it is just the Java Runtime Environment. Download the Java installer for your operating system.

If you're using Windows, install Java, just like any other Program, just by double-clicking the .exe file you downloaded in the previous step.

This installs the complete JDK, including compiler, aplletviewer, runtime environment, the proper java packages, etc. You wont have to worry where to store any binaries, the installer takes care of the details.

You can check your installation by typing (in a Console Window):
which should return a message confirming you're using, say, Sun JDK 1.6.0 (or whatever you actually installed).

Futhermore you should consider setting PATH and CLASSPATH environment variables. PATH should include the bin directory of your JDK, whereas CLASSPATH should include the current directory (".").

On my Linux box, I edited the .bashrc file (which contains general settings) to include JAVA_HOME which points to my JDK directory, JRE_HOME which points to the jre subdirectory of my JDK directory, and JAVA_BINDIR to point to the bin subdirectory. I don't know if all af them are really necessary, but I had a bit of trouble with an pre-installed Java version and the aforesaid settings helped me switch my os to use JDK 1.6.

Hope this helps.

Cheers,


Steffen
17 years ago
Hi Lee,

your Class GUI extends java.awt.Frame but you initialize all of your instance variables in an init() method, which would work in an Applet but isn't called automatically by the Java VM.

In an application, initialization of objects and primitives takes place in a constructor (such as public GUI(){...}). As your class doen't declare any constructors at all, the compiler decides to use the default constructor (which, in your case, happens to be the no-argument contructor of java.awt.Frame class).

Consider renaming the init() method to GUI() (to provide a contructor for the initialization of your variables) and give it another try ...

Cheers,


Steffen

[ December 24, 2006: Message edited by: Steffen Reinhard ]
[ December 24, 2006: Message edited by: Steffen Reinhard ]
17 years ago

Originally posted by Shyam Sunder:
HOW to achive this scenario?.
user might seletct any of the month in the combo box. Assuming user selected jan 26 2006 i should get the date which user selected should be between dec 2005 and feb 2006



Why use a Date object in the first place? Try using a java.util.Calendar object. As the Calendar class is abstract, you need to write the following code to get a calendar instance:

Calendar cal = Calendar.getInstance();

Your Calendar instance offers you a really vast variety of fields (i.e. pieces of Date information) you can handle in your application (e.g. for setting the selectedIndex values in your ComboBoxes).

I hope this helps,

cheers,


Steffen
17 years ago
Hi Ming!

Try Bruce Eckel's "Thinking in Java" book, which is very readable, doesn't expect you to have advanced programming skills (though some basic understanding of C syntax helps) and is published online:

http://www.mindview.net/Books/TIJ/

Hope this helps,

cheers,


Steffen
17 years ago

Originally posted by marc weber:

Steffen: Can we count you among our Mac users? Or are you using another Unix variant?



I'm having a never-ending love affair with Ubuntu Linux's dapper drake (Oh, I know, the roman catholic church will strongly disapprove ...)
17 years ago

Originally posted by Tony VanHorn:
I didn't know if we could over load main() like we could other constructors,
[ December 22, 2006: Message edited by: Tony VanHorn ]



Hi Tony,

it is indeed possible to overload a main method (which is, by the way, something pretty different from a constructor). The following text shows the output of a small program using overloaded versions of the main method:


This is the small program that does it all:


But what could be the use of overloading the main method? In terms of clarity and readability of your sources you don't win. Why not do the cast to whatever type you need in the basic String[] args version of your main method?

Hope this helps,

cheers,


Steffen

[ December 23, 2006: Message edited by: Steffen Reinhard ]

[ December 23, 2006: Message edited by: Steffen Reinhard ]
[ December 23, 2006: Message edited by: Steffen Reinhard ]
17 years ago
Thank you very much for your prompt reply to my question which might solve my problem though I admit I haven't yet figured out how to work with the java.util.jar classes.

My problem seems to be a little more complex than I conceived in the first place as I chose to embed the jar containing utility classes and resources in the jdk1.6.0 directory (to be more specific, at jre/lib/ext),
but I expect locating the jar in question should be possible by using System properties such as JAVA_HOME or even JRE_HOME as well as standard File-class functionality.

Once more thank you ever so much for your help as well as your patience.

Cheers,


Steffen
17 years ago
I've been fiddling about with jar files, lately... Currently I'm using a .jar that contains a number of resources such as fonts, images and so on.

As long as I attempt to access a resource (e.g. using getClass().getResource(String s) for images or getClass().getResourceAsStream(String s) for setting up of a custom font, respectively) things work properly.

I tried to create a new File object using a path (say, File f = new File("/images")). Now, calling f's isDirectory() method returns 'false'.
Same thing is happening when I call f's exists() method, though I get a friendly getAbsolutePath() message confirming a path for a file that obviously doesn't exist:


The output is:

Absolute Path: /images
/images exists? false
/images is a directory? false

What I need is a List (or an Array) of filenames to access resources programmatically without having to look up the fienames/paths myself.

Is there any way to list the files contained in a given directory whithin the jar's internal file structure?

Confusedly yours,

Steffen
[ December 21, 2006: Message edited by: Steffen Reinhard ]
17 years ago
Hi all!

I wrote an Applet for demonstration purposes which includes 64 vectors moving away from a common starting point and rebounding from the surrounding walls, thus gradually filling the applet window and masking part of the underlying signal. The animation works all right but tends to get boringlymind-bogglingly slow after a couple of seconds, as the underlying thread has to draw 64 GeneralPaths consisting of virtually thousands of Line2D objects with every rendering of the BufferedImage.

Is there a way to bypass the cleaning of the bufferedImage so I would only have to render and draw the current line segment?

For the actual code see below:



To view the Applet itself see Hallradius-Demo

I'll be glad to receive any suggestion to improve the shameful performance of my Applet ...

Thanks in advance!

Cheers -


Steffen
18 years ago
I've seen a couple of these, too ... Basically, this isn't exactly an error message, it's just a javac version 1.5.something compiler warning. Recompiling with "-Xlint:unchecked" won't make things much clearer. I did. It didn't.

As you are not dealing with a compile-time error, the warning won't keep your code from running (as long as you don't have any
real errors in your code). If the chatty compiler messages keep bothering you, consider switching back to good old SDK 1.4 (if you don't need any of the additional features of Java 1.5). To do this you will have to reconfigure your IDE. If you don't use an IDE you will have to set a couple of environment variables (taking for granted you still have some SDK 1.4.something stuffed away on your system, otherwise just download and install according to instructions given for your os).

I hope this will help.

Cheers -

Steffen
[ August 03, 2005: Message edited by: Steffen Reinhard ]
18 years ago
Hio all!

Having browsed the topic list I feel a bit shy to ask a - presumably - rather silly question, but I really haven't any clue how it could be done.

Dramatis personae: An applet graphics-object cast to a Graphics2D object within body of paint() method, a Rectangle 2D.Double, filled and painted, a couple of GeneralPaths initialized to start from a given location (using AffineTransform.getTranslateInstance(500,300)).

How can I draw a couple of lines (moving from the given 0,0 coordinates and bouncing off the drawn rectangle), thus eventually filling up the whole Rectangle2D surface.

As far as I figured out, I can use the Rectangle2D's outcode() method(s) to check if a given Point2D p lies within the Rectangle returning outcode 0) or not (returning outcodes 1 to 12, respectively).

I can even figure out the position of given point relative to the given Rectangle2D (using the return value of Rectangle2D's outcode methods).

What I didn't manage to do so far is
  • calculate Coordinates of Point2D to append to GeneralPath after bouncing off the Rectangle2D's border (that is: calculate the change of direction)
  • animate the whole thing without getting chatty error messages


  • Now, I hope I haven't asked an exceedingly 'off-topic' question, but I just can't figure out how to do it.

    Thanks in advance for any suggestions!

    Cheers -


    Steffen
    [ August 01, 2005: Message edited by: Steffen Reinhard ]
    18 years ago
    Hi, all!

    On several occasions I tried to access a java.util.LinkedList ll using two threads to write data to the beginning (using addFirst()) while trying to extract data from the end (using removeLast()) thus creating something like a buffer for sequential data access.

    Alas! In a better world it would all have worked out the way I planned it.

    In reality I keep getting error messages stating that a ConcurrentModificationException has occurred ... Weeeellll ... There's no way I can tell my Java environment that this is exactly what I intended to do: concurrent modification of data using one thread for input and one for output, respectively.

    Tried synchronizing on the LinkedList object. Doesn't help. Java seems to be somewhat stubborn when it comes to bypassing the fail-fast behavior of it's Container classes ...

    Any ideas, anyone?


    Thanks in advance!

    Cheers -

    Steffen

    [ July 20, 2005: Message edited by: Steffen Reinhard ]
    [ July 20, 2005: Message edited by: Steffen Reinhard ]