Hi!
First off, use of JApplet is prefferable over Applet since it supports Swing component architecture. So let your BallWorld class extend JApplet instead, it is essentially the same thing.

Then you should maybe override the init() method in your BallWorld class to set up you applet. You should instansiate your variables in init() instead of where you declare them.

I noticed that you call Thread.sleep in your paint method and then call repaint. This is not how you should set up animations. Have a look at the class javax.swing.Timer which lets you define a timer that will call a method a given number of times per second or something. You can then directly call paint or repaint each time the timer calls your callback method.

I don't know exactly why you get the error. Do you have a stack trace?

read:

http://docs.oracle.com/javase/tutorial/uiswing/components/list.html

under "Writing a Custom Cell Renderer"

I work at a software company that makes retail enterprise systems. I started hereright out of the university and have been working for about a year. The first couple of moths they gave me some time to familiarize myself with the systems and the code. I started of with minimal help/education from other engineers and then a lot of bugfixing, which they thought was a good way for me to learn and for them to evaluate if I was good enough.

Now after the learning period the work can be quite varying. Our requirements and roadmap team gathers info from different sources (customers, engineers...) and prioritizes work that needs to be done. In our team we look at the roadmap and plan sprints (we work with scrum). At the scrum meetings we divide up the work between ourselves and then do the work. It can be anything from bug fixing, buissness logic implementation, country customization, refactoring old (bad) code, researching new ideas, making implementation proposals, updating/writing documents, helping customer customiziation teams, making unit tests and other tests...

Our boss (The product manager) doesn't tell us directly what to do, he is responsible for what comes into the release/sprints and other stuff. While planning sprints we try to break down tasks into subtaskt and determine as good as we can the time it will take, and we only put in as much tasks in the sprint that we think we have time to do. More often that not we underestimate the ...

The first thing I'm noticing is that all your code is en the paint method. This method should only be overriden if you want to do custom painting like the painting you are doing in the beginning of the method. You should not add swing components to layouts etc. in this method. You should do it once when the program is started.

So move out the layout code for the radiobuttons and other swing components to another method that is called once by the constructor or something. The layout of the components will conform to their parent containers depending on what layout manager you use.

The paint(Graphics g) method will be called constantly while you are resizing a window or anytime anything needs to be painted onto the screen. So if you add new components for each time the method is called, you will get a hell of a lot buttons. And will probably be out of memory pretty fast.

On another note, you should preferrably override paintComponent(Graphics g) instead of paint(Graphics g). paint paints borders and children and stuff, and is calling paintComponent, while paintComponent is only responsible for painting itself.

Something like this...

[code]
String input = "123";
int parsedInput = 0;
try {
parsedInput = Integer.parseInt(input);
} catch(NumberFormatException nfe) {
// Handle incorrect input
}
[/code]

stultuske commented: no idea why this should be negative, since it is an answer to what the OP originally asked +14

Hi!
I have a JScrollPane that contains a JPanel with a CardLayout, which in turn contains two JPanels with some labels and stuff. I want the contents of the ScrollPane/ViewPort to never exceed the width of the viewport.

The problem I'm having is that when a label holds a lot of text, the components inside of the scroll are not completely visible, they dissapear a little on each side. Is there a way of forcing a max size for the scrollpane or something so its contens never gets larger that the scrollspanes horizontal width?

mKorbel commented: nice qurstio +11

In your method displayText(String s) you construct a JFrame and JTextArea for every call you make to it, which is for ever line you read.

You should only construct these once, and hold the text you want to show in the textArea in a variable and just call textArea.setText(theText).

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.

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

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?

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.

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.

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.

[url]http://gmplib.org/[/url]

Would you like a blueberry pie with that solution?

Of course you don't have the real square root, thats what you want to approximate. But you do have the square of the "real" root which is your input data "n". You only need the square and the approximated root to do the error calculation. The "real" root was used just to to make a point. You want itnitn to be very close to n, hence abs(n-itnitn) should be a small number of your choice.

Its not that using integers and doubles are imprecise, as I said you can get the precision you want in your calculation by knowing how big the error is. But if you use BigDecimal etc. you can have an arbitrary amount of precision and size, with your computers memory as a limit. For example you can't use integers, floats or doubles if you want to calculate the square root of a huge number, or if you want more precision than 16 decimals. It all depends on what your doing, if there's no reason to use BigInt then you shouldn't, using integers will probably yield faster execution. But in your case I would use BigDecimal for the input value n also. Real numbers have roots to :) Also an integers max value is not very large.

The important thing here, as in all numerical calculations, is to know how large your error is and to know how much error you can afford to have. This is really important as errors accumulate with time and you often ...

Bladtman242 commented: The problem has been solved, and I really have gotten so much more than just the sollution out of theese answers. +2

[QUOTE=Bladtman242;1371602]
I don't get this about numerical errors and why using 1/i is better. Could you please explain it?
Or provide a link for further reading:)
Why is this?[/QUOTE]

Im no expert on exactly how numerical error occur, but computers has limited precision and resources. But specifically, numerical errors get larger when calculating stuff that are approaching singularities.

when you write i = 1/10 you get a small error in your result. Then when you divide i by 10 again you already have an error and are adding more because of the singularity ( i -> 0 ). This might not happen when dividing 1/10, but later in when i is small.

My point was that if you multiply i by 10 instead and do the calculation 1/i once you don't get the accumulating error in i since multiplying 1010 or 10010 and so on does't give as much numerical errors, if any. Then you only make the division 1/i once which gives you less error.

Try to print the value of i in your loop after you divide it by 10. You will se that the value isn't exactly what you are expecting. And then print 1/i when you multiply it by 10.

[QUOTE=Bladtman242;1371602]And with 1/i it will still calculate 16 decimals you say?[/QUOTE]

As I said I'm not completely sure myself about how the errors work, but the first 10 decimals should be correct and the last part is crap which you can throw away. 1/i will probably ...

Bladtman242 commented: Provided information which helped cast light over the sollution +2

Since the try statement might fail your variables will not be initialized, just as the compiler states. either you can place the code that uses firstArg and secondArg in the try statement or you can initialize the variables to something.

You could also set firstArg and secondArg to some default value in the catch statement. I know that you call system.exit(1) in the catch statement but the compiler probably doesn't care about that.

Java is quite good at catching errors like this, but try to always initialize variables when you create them to save yourself from headache in the future.

Bladtman242 commented: Even though it might be basic stuff to you, it was great help to me :) +2

GMP has a c++ wrapper, you could use that if you really want to code in c++ style.

Salem commented: Exactly! It's like they never bothered to read more than 5 words... +19