SasseMan 49 Junior Poster

Is the file supposed to be readable, or just store the data for efficient processing? In the latter case, what difference does it make if you have new lines or how the file looks at all?

It sound to me like you want to make a file that efficiently stores a lot of data for fast processing. Have you looked into random access files?

http://docs.oracle.com/javase/tutorial/essential/io/rafs.html

SasseMan 49 Junior Poster

I didn't go through your code that much, but why are you setting and getting lengths? Do you know that List has a method size(), which returns the number of objects in the list, i.e. the length?

What length is it that your setting?

SasseMan 49 Junior Poster

Remarkably that you had the time to create a forum account and post a new thread before googling, which takes 0.13 seconds to get an answer from.

http://www.google.com/search?client=safari&rls=en&q=java+static&ie=UTF-8&oe=UTF-8

SasseMan 49 Junior Poster

It is kind of hard to get mouse event without events since the event is an event in its nature. Do you want to have like a while loop where you call a method getMouseInfo() that return the state of the mouse? An Event is just a callback method that is called when something happens in some other part of the program.

What you can do to catch all mouse events without having a component listening to events is to add an AWTEventListener. This listens to all AWT events and it is possible to mask what event to listen to if you only are interested in mouse events.

Toolkit.getDefaultToolkit().addAWTEventListener(theListener, AWTEvent.MOUSE_MOTION_EVENT_MASK + AWTEvent.MOUSE_EVENT_MASK);

Google AwtEventListener.

SasseMan 49 Junior Poster

Programming isn't magic, every convievable method is not included in the java api. You need to write your own method for extracting alphabetic characters from a string. You can loop through the string, use tokenizers as said, use regular expressions to do something etc...

And what du you mean by write a program that reads alphabetic characters only? Where do you get your input from?

SasseMan 49 Junior Poster

Thats exactly what protected means.

SasseMan 49 Junior Poster

Ahh, frustrating. I solved this but in a ungeneral way.

I guess that the only way to make it general is to perform some kind of analysis of the class that is instansiated to see what the values of the map is going to be cast to before creating the map. Not impossible, but far fetched.

SasseMan 49 Junior Poster

I'm not sure what the default method access is for getInfo(). Try adding public so it instead says: "public void getInfo() {".

Also, your getInfo method does not return anything, which is bad code for a method with get in its name. You should either return something or call it something else.

SasseMan 49 Junior Poster

~s.o.s~: I can't change the program code itself, well, I can but that is not the problem I'm trying to solve, I don't want to rewrite code just to make the test work. That would take to much effort. The example was just one of many places where similar things are done.

The problem with maps is that some classes that have instances of maps, casts the contents of the map to unkown types (from the tests perspective). When I get the fields of a class using reflection, I know that the field is supposed to be an instance of a map. I don't know the types of the keys or values.

The issue occurs after the object has been generated. The transformation calls the doSomething method at some point, that casts the values in the map to some unknown type.

SasseMan 49 Junior Poster

Yes GLUT is a good place to start to get rid of OS headaches. http://www.opengl.org/resources/libraries/glut/

SasseMan 49 Junior Poster

Yes. But I won't be calling that method. The method will be called with a string that also is set via reflection. The point is to just create objects with arbitrary instance variables.

The test is going to be used to test transformation of objects that I have in my program. The test works like this:

1. A method "testTransformation" is called with "Class<?>" as input. Only classes inheriting from the interface "Transformable" will be used as input.

2. Try to create an object with type Class<?>. I do this with with reflection. instansiate the object and recursively populate its instance variables with dummy values. There are some special cases that have to be handled specifically, but I'm trying to make the generation of objects as general as possible.

3. Transform the object by calling transformer.transform(createdObject, outputStream):

4. Transform the object again by calling transformer.transform(transformableObject, inputstream).

5. If no exceptions are thrown during transformation, the test is succesfull.

This is essentially what I'm trying to do.

SasseMan 49 Junior Poster

Maybe, possibly, but I think your'e suggesting that I should return an object in the get method dependending on the value of the input String? That won't be possible since I can't know what string will be used as in parameter in the method doSomething(String).

My though right now is to just handle the creation of maps in a more specific way, by knowing what Object the map belongs to and its variable name, which I can do. It wouldn't be general and will require changing/adding new test code if the program is changed. I can't come up with any other way.

SasseMan 49 Junior Poster

You need a way to read filenames in a directory or subdirectory.

Easy to goole: http://www.exampledepot.com/egs/java.io/GetFiles.html

And then you just read the files one by one and extract the line you want by using, for instance, FileInputStream, BufferedReader etc...

http://docs.oracle.com/javase/6/docs/api/

Read the javadocs and examples.

http://www.roseindia.net/java/beginners/java-read-file-line-by-line.shtml

SasseMan 49 Junior Poster

Hi!
I'm writing a unit test where arbitrary objects have to be created without knowing anything about the objects (with some exceptions). I use reflection to create objects and set their fields to random values etc... I'm almost there but I've come to an issue I can't find a solution to.

Say that an Object that is instansiated using reflection has a field, which is a Map<Object, Object>. I set this field to an empty map.

The object has the following method:

public SomeObject doSomething(String aString) {
    SomeObject someObject = (SomeObject) map.get(aString);
    if(someObject == null) throw new SomeException();
    return someObject;
}

The problem is that my program want to set the map field in the Object instance to some random map. But it cant be totally random since later code depend on what is in that map. What will happen is that the value that is returned from map.get() will try to be cast to some specific type and fail, since I can't know what kind of map to create.

Is there a way to solve this? To somehow detect what the value of map.get() is going to be cast to or something?

Thanks!

/S

SasseMan 49 Junior Poster

Why would directx be better? OpenGL will run on non windows platforms, directx will not. In my opinion both are as hard to learn, and are equally good for drawing shit on the display. Also OpenGL would be better learn if you want to do graphics for phones and stuff, like iphone, android, iPad etc.

You can create whatever graphics and effects you like using both libraries. They both rely on the same principles. Learning one of them will make learning the other one easier, just like learning java makes learning C++ easier, or the other way around. What is it you want to do exactly? What is your goal?

My suggesion would be to go for OpenGL and jump into shaders from the beginning.

SasseMan 49 Junior Poster

Hi!
I'm wondering if there is a tool to make the following functionality in an wasy way.

I have a project in eclipse and I use perforce for versioning. I want to be able to compare the project between two dates and determine which classes/packages etc. that have been added and which classes that been changed and which methods in those classes.

The result should be a list or something that says:

Classes Changed since 20110101
Class1
method1 edited
method2 added

Classes Added since 20110101
Class2 added

Packages Added/Edited since 20110101
Package1 edited
Package2 added

Anyone know of an eclipse plugin or external software or something that can do this easily?

/S

SasseMan 49 Junior Poster

Hi!
I'm looking for a way to make an application (app1), separate from another java application (app2), that can acces the GUI of app2 and also listen to all events that are passed to app2.

I would like to be able to get hold of the frame of app2 so I can traverse its child components. I would like to listen to all possible events from any external sources like mouse, keyboard, etc, that app2 reveices, which app1 also should recieve.

Any ideas on how to do this?

/S

SasseMan 49 Junior Poster

I noticed that I left out a call to repaint() at the end of the timingEvent. I don't really get how to use repaint. It is for example not needed to call it for the other animations, just for this one. The other animations call setBounds which calls repaint, so thats probablty it.

I was also thinking about buffering the animations. The idea is to make an animation each time a component changes and draw to an offscreen image. When the animation is triggered i just paint the correct image at each call to timingEvent instead of doing a lot of painting and stuff. Would that run faster?

SasseMan 49 Junior Poster

Ok! Here some code that I think explaings how I do the animations.

First of, there is a class, AnimationPanel, which is a transparent Jpanel that contains the component that are going to be animated. In this class the following method is called to do a specific animation...

public void appear(Component[] cs) {
         Animator anim = new Animator(300, new AppearTarget(cs));
	queueAnimation(anim);
}

The components in the array cs are about to be animated from a invisible to a visible state. We create the Animator object along with the Target and place it in a queue that is waitning for for other animations to end before running the next, i.e. you can press a button rapidly several times that triggers several animations after each other.

The Animator object just calls start when it is its turn to animate and the target handles the rest.

here is the code for the AppearTarget...

private class AppearTarget extends AnimationTarget {
		public AppearTarget(Component[] cs) {
			super(cs);
		}
		@Override
		public void begin() {
			for(Component c : components) {
				if(c instanceof RoundedGlowPanel) {
					((RoundedGlowPanel) c).setTransparency(0.0f);
				}
			}	
			for(Component c : components) {
				c.setVisible(true);
			}
		}
		
		@Override
		public void end() {
			for(Component c : components) {
				if(c instanceof RoundedGlowPanel) {
					((RoundedGlowPanel) c).setTransparency(1.0f);
				}
			}	
			for(Component c : components) {
				c.setVisible(true);
			}
			super.end();
		}
		
		@Override
		public void timingEvent(float fraction) {
			double alpha = getCurvePoint(fraction);	
			for(Component c : components) {
				if(c instanceof RoundedGlowPanel) {
					((RoundedGlowPanel) c).setTransparency((float) alpha);
				}
			}
		} 
	}

The target sets some …

SasseMan 49 Junior Poster

Hello!

I've written some swing components for which I use timing framework to make some simple animations that hopefully are going to enchance usability. What I am doing is essentially setting the bounds of JPanels for each timing event to animate something that moves and resizes. I also change transparency values during animation by using alpaComposites in the paintComponent method.

The animations look good on my dev system but lags on slower systems which the software mainly will run on.

I'm unsure about how I should optimize the performance of the animations. Does anyone now some place I can find information about this? What approaches are there to this?

Thanks!

/S

SasseMan 49 Junior Poster

I found another way. I overrode the paint method and made a rounded clipping mask. The children could not paint outside of that mask.

I know that java 7 has some nice new handy swing component, unfortunate we won't upgrade for some time.

SasseMan 49 Junior Poster

Hello!

I've made a custom JPanel that overrides paintComponent which paints a rounded rectangle. My problem is that when I place other components in the panel, like a JLabel, they don't get rounded corners like the panel they are in.

here is my panel class:

private static class BackgroundPanel extends DropShadowPanel {

		/** Serial version UID. */
		private static final long serialVersionUID = 4349330263921687004L;

		public BackgroundPanel() {
			super();
			setBorder(new EmptyBorder(0,20,20,20));
		}

		/** {@inheritDoc} */
		@Override
		public boolean isOpaque() {
			return false;
		}

		@Override
		protected void paintComponent(Graphics g) {
			Graphics2D g2 = CommonUIPainter.getGraphics2D(g);
			super.paintComponent(g2);	
			
			Insets insets = getInsets();
			int x = insets.left;
			int y = insets.top;
			int w = getWidth() - insets.left - insets.right;
			int h = getHeight() - insets.top - insets.bottom;
			g2.setColor(getBackground());
			g2.fillRoundRect(x, y, w, h, 20, 20);
		}
	}

So my question is how do I make it so that the panels children also get rounded corners?

SasseMan 49 Junior Poster

JPanel extends JComponent so it works for JPanel as well. Almost all swing component extends JComponent.

SasseMan 49 Junior Poster

I found another way. You can override the contains(Point p) method of JComponent to return false all the time, or make another implementation that takes the children of the component into consideration, but not itself.

I not sure if its a very good solution but it works and is very easy to implement.

SasseMan 49 Junior Poster

I haven't and I can't. We don't want to migrate to java 7 yet. Not my decision. Is there a way to do it in java 6?

SasseMan 49 Junior Poster

Hello!

I have a swing app with lots of components and stuff. I want to place a Container/Jpanel on top of everyting else that is invisible that contains other component which are visible.

I can make the panel invisible or not opaque and still show its child component but I also want the panel not to block events to underlying component. For example there is a button under the panel, the button is visible, but it can't be clicked since the panel is in the way.

How do I make it so that panel doesn't block underlying components from receiving input?

Thanks!

/S

SasseMan 49 Junior Poster

Hello!
I'm trying out an idea I had which requires me to capture the contents of a java window/Frame, much like a screenshot but without the window and menubar, just the contents rendered in java, i.e. an exact image of what is visible in the java application at the moment.

I would also like the screenshot to be software rendered, I don't know if I'm using the correct term, but the captured image should not be different on others systems/computers.

Can i for example hijack a render buffer/display buffer or something and write that to in image?

Does anyone have any ideas?

Thanks!

/S

SasseMan 49 Junior Poster

I was thinking more of the whole package with the artistic part included. Coding a custom animation shouldn't be to timeconsuming, but as you said, the hard part is the quality of the animation effects.

SasseMan 49 Junior Poster

Hello!
I am writing an application for an embedded system with GUI written in swing. I now want to incorporate animations in the GUI to enhance usability.

Hypothetical example:
The user sees a table with some buttons ant things around it. The user can temporarily "save" the table, which makes the table dissapear into a status icon and a new empty table is shown. The user can then switch between these two tables.

The functionality for doing this is already there, but what I want to do now is to animate the dissaperance of the table so that it becomes more clear to the user that the saved table went into the status icon. I want to do this by animating the "minimization".

My question is the following. Are there any animation frameworks for java that makes this possible? I've google around some and found the "timing framework". Does anyone have some experience of this, or maybe something else that may fit my description?

Thanks

/S

SasseMan 49 Junior Poster

Hi!

I am using a vpn connection to connect to my work network, which I use for remote desktop, which is working fine.

I now want to be able to access the same stuff at home that I can access at work. I can for instance write "wiki" in the web browser at work which directs me to the internal wiki page. The problem is that this doesn't work from my home computer with a vpn connection.

I tried setting the work dns address (doesn't seem to matter if do or not) in the vpn settings for my home computer. I then did a nslookup for wiki and got the following error:

nslookup
> wiki
:: Got SERVFAIL reply from [ipadress], trying next server
Server: [another ipaddress]
Address: [another ipaddress]#53

** server can't find wiki: SERVFAIL

SERVFAIL means that the domain does exist and the root name servers have information on this domain, but that the authoritative name servers are not answering queries for this domain.

what can I do about this?

I'm using a MAC with OS X Lion as the home computer.

SasseMan 49 Junior Poster

Hi!

A small SVN problem?

I have an online svn server that I have had for some time that I used for a software project. I want to close that account so I don't have to pay the monthly fee. But before I do that I want to download the entire repository with the entire file history etc to a local svn server on my computer.

Questions...

Will I need to install a svn server or what not (I use a mac)?
How do I download the repository with all files and history into the new repo?

Thanks!

SasseMan 49 Junior Poster

That seems to be exactly what I need, but it doesn't work on windows? I get a message that a critical system was not found...blabla... I also tried with cygwin, didn't work. I followed the install instructions on the website btw. The site mentiones that it doesn't work on windows but that it might work with cygwin, but no luck here.

Any suggestions? I should maybe take a look at popen. Do you know of any examples with popen that does what I want to do? I googled that earlier and couldn't find any.

SasseMan 49 Junior Poster

Hi!

I want to make a python program that runs different simple command line scripts. Right now I use os.system which works fine for running the scripts, but the problem is that the scripts sometimes halt and wait for input from the user. So my question is, how do i programmatically detect when an input has to be made, and then make that input instead of me having to make it manually?

my code like something like this...

os.system(aCommand)
os.system(anotherCommand)

aCommand and antoherCommand might stop and wait for user input which i want to make programmatically.

/Sason

SasseMan 49 Junior Poster

OpengGL gives you the means to create any visual effect that you want. HL2 use OpenGL as well as DirectX since it is avaliable for Mac.

How your graphics look depends on mainly three things. Geometry, textures, and lighting. But the really main thing is lighting. I would recommend not using the fixed function pipeline in openGL for doing your rendering. You should instead use shaders so you can implement lighting effects of your choice, or if you want to use, for instance, normal or bumpmapping effects, that can also be done in the shader. You can find a lot of shader examples on how to implement various effects of lighting, try doing some googling on that.

Its a huge subject and not just a settings or something like that that needs bo be changed. You might also want to look into existing game/graphics frameworks. You probably don't want to implement your own dynamics or physics or graphics engine.

SasseMan 49 Junior Poster

Yes i know about objective c++ etc. Thats why I was suprised when i didn't get c++ stuff working. I sorted it out though, it had something to do with compiler settings.

SasseMan 49 Junior Poster

Hello all!

I'm having problems with running c++ on iOS. I have a iOS openGL project in Xcode 4 and an external library written in c++ that has to be a dependency to the iOS target so it can run on an Ipad. right now I'm testing with the iPad simulator.

The problem is that i can't include stuff like iostream, string etc, and use them. Is there something i have missed? Does iOS not support C++ or parts of C++, like string and IO stuff? I can use some C++ functionality but many parts seems to be missing. I can run c++ code that i have written myself and parts some parts of the c++ library. I can't find any information about this anywhere. Seems to me that I'm missing something trivial.

Any suggestions?

Thanks!

SasseMan 49 Junior Poster

You could do something like this.

pseudocode...

num = random double from 0 to 1
if (num < 0.7) num = random int from 0 to 75/2
else num = random int from 75/2-75

70% of the time it will generate a uniformly distributed random number from 0 to 75/2, the rest of the time from 75/2 to 70.

SasseMan 49 Junior Poster

Try to find out on exactly which line the segfault occurs. Then check if the variables on that line have been initialized properly before the function is called.

SasseMan 49 Junior Poster

You could just store the url of the image in the DB, which would just be a string and would not create so much overhead. I don't have much info on if its good or bad to store images or other large files in DBs, probably has its ups and down. checkout the following example, its quite similar to your code, might help.

http://www.java2s.com/Code/Java/Database-SQL-JDBC/InsertpicturetoMySQL.htm

SasseMan 49 Junior Poster

You don't really need to push the elements onto another stack. I'm assuming that you use a linked list to implement the stack. In that case you can just loop through the stack until you find the element you want to remove, delete it, and then point the previous element in the list to the next element. This takes O(n) time, and requires only one loop. Here some pseudocode...

stack = stack with elements.
elem = element to remove.
prev = null = temp variable to store an elem pointer.

for each element el in stack
     if elem is equal to el
          if prev is null
               delete el and point root to next elem
          else
               delete el and point prev to next elem
          end
          break loop if you don't want to delete duplicates.
     end
     prev = el
end

something like that.

SasseMan 49 Junior Poster

I can guarantee you that you can reformulate the recursion as a loop. Try to go through the algorithm by hand for a very small case that only takes 2-3 recursions and you will se that the solution is obvious, especially in this case where you only have one recursive call in your function.

SasseMan 49 Junior Poster

Yes what StuXYZ said. C++ is not designed for recursion.

SasseMan 49 Junior Poster

googling "facebook api" gives you the answer.

http://developers.facebook.com/docs/api

SasseMan 49 Junior Poster

You should probably not use built in types like doubles, ints and longs for these kind of calculations that require high precision and big numbers. Use GMP or something similar.

http://gmplib.org/

SasseMan 49 Junior Poster

ok, great!

SasseMan 49 Junior Poster

which line in clear is causing the segfault?

SasseMan 49 Junior Poster

Segfaults are memory access violations. Try to find on exactly which row the segfault occurs by printing stuff before and after a row that you suspect may be causing the segfault, that would narrow the search down quite a bit.

SasseMan 49 Junior Poster

Well either you misunderstood your teacher about getch(), or your teacher has lacking skills in C++, which is fine. But use cin.get() instead, it will do the same thing, and it has nothing to do with the program ending. It is used so that the console doesn't close in windows when the program has ended.

SasseMan 49 Junior Poster

Why are you using getch() there? So the console doesn't close? Your compiler must support it. Use std::cin.get() instead.

Would be good if you gave and example of how the file is formatted exactly so it will be easier to help.

What is wrong with length()? length() is an alias of size(). They both do exactly the same thing so try size() instead and se what happens, both should give you the number of characters in the string. You should also use size_t as the type for the length variable and not an int, but I think it will work anyways.

SasseMan 49 Junior Poster

Take this as an example which solves for MAX = 10.

http://www.wolframalpha.com/input/?i=+%7Bx+%281%2By+%281%2Bz+%281%2Bp%2Bq%29%29%29%3C%3D10%2C+x%3E0%2C+y%3E0%2C+z%3E0%2C+p%3E0%2C+q%3E0%7D

There are a finite amount of solutions, and you have to handle the cases where y,z... are 0 which practically gives you another equation.