Jonathan Janisch

Greenhorn
+ Follow
since Mar 17, 2007
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 Jonathan Janisch

Craig, I appreciate the time you put into your response. It's not really what I was attempting to accomplish though

Chu, thanks. This isn't really important - it's really just an experiment for fun. I wanted to make a cheap digital whiteboard using only a small mouse and a projector.

In order to do that I needed to be able to map positions on the whiteboard to screen coordinates. I attempted to solve that by first entering a configuration mode where the user clicks the top left, bottom left, and bottom right of the whiteboard - but I'm having issues getting those coordinates reliably.
12 years ago
I'm just guessing without really looking at the code that it's not loading your image properly. When you run that particular code in NetBeans it expects to find the image in your project folder here:

build
dist
images\1.jpg <---
nbproject
src
test
build.xml
manifest.mf

Did you know that Java 6 has built in support for displaying splash screens?

http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/splashscreen/
[ August 14, 2007: Message edited by: Jonathan Janisch ]
12 years ago
When you move your mouse all the way to the left - it hits the left edge of the screen and stops - even if the user keeps moving his mouse to the left.

In Java, there doesn't appear to be any way to detect that the user keeps moving his mouse "left".

Basically, if the current mouse coords are 50,100 and I move my mouse 10 feet to the left on my desk Java will still only report the position as 0,100.

My problem is, not only do I have to detect that the user moved the mouse to location -32535235,100 I also have to detect that position accurately.

In order to accomplish this, I'm doing the following:

1) Use robot class to forcefully move the cursor to the center of the screen.
2) Detect relative mouse movements and some Point which keeps track of the total movement
3) Repeat - go back to step 1

The code I'm using is basically straight out of a Java game development book "Developing Games in Java". This technique appears to work well for reporting simple changes in the relative x,y movement. It does not appear to be accurate in reporting actual x,y coordinates.

So my test case is this:

1) Start the application.
2) Move the mouse 1 foot to the left (left side of desk) - record the X location
3) Move the mouse 2 feet to the right (right side of desk)- record the X location.
4) Finally, move the mouse back to the left side of the desk and ensure it is the same (or very close) to the location recorded in step 2.

Currently when I do this, it's way off by hundreds of pixels.

Is there a simple error in the code that I'm missing? Any ideas on how I can accomplish this?

Here's the code:

[ August 14, 2007: Message edited by: Jonathan Janisch ]
12 years ago
For some reason BeanInfo is one of those things I feel like I'll never learn. I've read through the tutorials on sun's site and countless others and IMHO the examples they provide are either too simple or too complex.

I have a class MyClass and a bean info class MyClassBeanInfo which extends SimpleBeanInfo.

MyClass has one normal javabean property: orientation which has:

int getOrientation() and void setOrientation(int orientation).

1) In the NetBeans properties window, orientation is shown in the "other properties" section. How can I make it a "main property"?

2) Also, if you edit the orientation field you can enter any int value in there (although in my case I'm throwing an IllegalArgumentException so netbeans fails to write an illegal value). With Swing controls like JSlider, the orientation property allows you to select between HORIZONTAL and VERTICAL. It doesn't allow you to enter any int value. I looked at the source for JSlider and it appears to use annotations for beaninfo (is this preferred? all the tutorials appear to be outdated). I copied and pasted the annotation and got rid of my beaninfo class and it still allowed me to enter any integer.

/**
* Set the orientation
*
* @param orientation the new orientation
* @throws IllegalArgumentException if orientation is not one of {@code VERTICAL}, {@code HORIZONTAL}
* @see #getOrientation
* @beaninfo
* preferred: true
* bound: true
* attribute: visualUpdate true
* description: Set the scrollbars orientation to either VERTICAL or HORIZONTAL.
* enum: VERTICAL MyClass.VERTICAL
* HORIZONTAL MyClass.HORIZONTAL
*
*/

3) Also, when the orientation property is called, the control should resize itself to the vertical/horizontal preferred size.

Note: I'm using NetBeans 6 M9 and they appeared to remove the bean editor so I have to do it all by hand which I prefer for learning anyway. Is there a really good up to date tutorial on custom java components, beaninfo, etc that does not show up in the top 100 google results?

Thanks
[ June 22, 2007: Message edited by: Jonathan Janisch ]
12 years ago
I solved it using my own persistence delegate to create a new Person. I don't understand why I had to do this, since I thought that was the purpose of the defaultpersistencedelegate. I did see some stuff in the source for defaultpersistencedelegate that involved checks for overriding equals - but I won't pretend like I understand how it works.

12 years ago
Hi, I'm trying to write out a class to XML using XMLEncoder.

There's a few unique things about this class.

1) It has no default constructor
2) I'm overriding the equals method.
3) The class has a static int count which defaults to 0. Each object is assigned an ID based on the current count. The ID is used to compare two objects.

Since it has no default constructor, I'm using the defaultpersistencedelegate. Here's the code:



If you run this, you will get a stackoverflowerror (atleast under jdk1.6.0_01 on Windows). I'm not an XMLEncoder expert, I've narrowed the problem down and I came up with this simple Person.java example.

The combination of the static int ID and override equals seems to be the problem. If you change the equals to:



It will still give the same error. However, if you remove the equals method completely, it will work fine and the xml output is as I expected. But unfortunately, I need to override the equals method.

1) Does anyone know how I can fix this?
2) Why would "return super.equals(obj)" give different behavior than having no equals method at all?

Note: I realize if my class were really a Person class, the equals method should compare SSN, first and last name, etc. and not some made up int ID - this is just a simple example to demonstrate the problem.

Thank you!
12 years ago
Smitha, you have to either:

1) myjframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

or

2) add a window listener to the frame and System.exit on window close.

If you do not do this the java/javaw process will never terminate.
12 years ago
They're called docking frameworks.

See this thread: Java Docking dilemma

I'm using Infonode's docking framework and I'm fairly happy with it. It has a GPL and commercial license.

You can also build your application using the Netbeans platform.
12 years ago
I don't see why you can't just simply use plain Swing with JLabels and JTextFields.

Here's an example. I did a random google image search for "form".

I found this form:
http://www.crscc.com/oes/rc/appform1of2.jpg

I created the following Swing frame in less than 4 minutes using NetBeans' GUI builder (Matisse).
http://i7.tinypic.com/4gqpj5l.gif

It's not exact since it's just an example, but if I spent another 20 minutes I could make it exact - pixel for pixel. For the inputs, I simply used non-opaque JTextFields with a MatteBorder for the underline effect.
12 years ago
Programming is about problem solving.

Try to compile it and see what happens. If it gives you an error, try to figure out why. I believe you were using the addActionListener method earlier, maybe that might help.

The (JavaDoc for JButton says that addActionListener expects an ActionListener. '...' doesn't appear to be an Object, let alone an ActionListener. It doesn't even appear to be legal Java code!



If you really don't want to learn then I'll tell you the answer

You asked:

So, how do I add actionlisteners to this buttons?



The code I posted showed how to add an ActionListener to your dynamic buttons as you requested. You have to replace '...' with a object whose class implements the ActionListener interface. Craig already posted code that does this.
12 years ago
If you're going to do GUI development, I strongly suggest NetBeans. It's much more straightfoward to design a GUI out of the box using NetBeans than other Java IDE's.
12 years ago
Timbo, I just downloaded JBuilder just to answer your question

I have never used it before. It is JBuilder 2005 Foundation.

1) I created a new project.
2) I created a new "Frame" called "MyFrame" using the javax.swing.JFrame base class.
3) I clicked the "Design" tab.
4) I added a JLabel and JButton.

It generated the following code:



Notice: MyFrame extends JFrame. Thus, when MyFrame()'s constructor is called, JFrame's default constructor is automatically called.

I added the following code to maximize the window as in my first post and it worked as expected:



You will probably have to combine this with Michael's code to get it to work for earlier JDK's.
[ March 20, 2007: Message edited by: Jonathan Janisch ]
12 years ago
Problem:

Originally posted by arnie frenato:
you can probably see that there is no variable assigned to the newly created buttons..



Solution:

Assign them to a variable.




12 years ago