Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
hexadecimal
Nov 23, 2008

by Fragmaster

The Bill posted:

I think javadoc has a -private option (or something along those lines).

Yea I use that, but it still doesn't seem to get inner private classes. I just changed them to public, problem solved. Not an elegant solution thou :(

Adbot
ADBOT LOVES YOU

The Bill
Sep 2, 2008

hexadecimal posted:

Yea I use that, but it still doesn't seem to get inner private classes. I just changed them to public, problem solved. Not an elegant solution thou :(
-private definitely works on private inner classes. They won't be listed in the package summary but you can see them on the tree hierarchy.

hexadecimal
Nov 23, 2008

by Fragmaster
Is it possible to pass remote reference to the webservice using SOAP and axis2, then have java program running as webservice invoke methods on the client?

zootm
Aug 8, 2006

We used to be better friends.

hexadecimal posted:

Is it possible to pass remote reference to the webservice using SOAP and axis2, then have java program running as webservice invoke methods on the client?
I'm not sure what you're asking here, but I think that the answer is no, at least not directly. In SOAP the client invokes methods on the server which can just send responses. Of course you could send a response which should be interpreted as taking an action but there's almost definitely a better way to do this.

hexadecimal
Nov 23, 2008

by Fragmaster

zootm posted:

I'm not sure what you're asking here, but I think that the answer is no, at least not directly. In SOAP the client invokes methods on the server which can just send responses. Of course you could send a response which should be interpreted as taking an action but there's almost definitely a better way to do this.

Sorry if this is stupid or completely noobish, I have very limited experience with RMI, but would it be possible to somehow serialize a remote reference to an object that is running on client's computer, and send it in HTTPRequest to the webservice? Then have the Java program running as webservice store that reference and subsequently use RMI to invoke methods on the client's object?

So I guess what this really is, is using webservice to setup RMI communication between server and client objects. If I am running RMI Registry on the same computer that run's webservice, would there be a way to do it that way also? That is, have the webservice return remote reference to the server side object to the client, and set up RMI that way?

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost

hexadecimal posted:

I have some bugs in my webservice, that are probably threading related. However when it becomes unresponsive it blocks all other webservices. How can I make sure that my buggy webservice doesn't make other webservices and axis2 cry, besides the obvious "fix the bugs in the program"?
Your web service is causing resource starvation for other services, so there's little option but to fix it, or maybe use a JMX console to tell the JVM to kill the offending thread in your web service. The problem is, if your web service is jacked up enough, this method won't solve anything besides freeing up the thread schedulers a bit. Your time is best spent fixing it or at least limiting the resources the app receives. Well ok, it's technically possible to use "sandbox" an application to its own individual JVM depending upon support from the application server, but I haven't done it myself.

hexadecimal posted:

Stuff about RMI, SOAP, and HTTPRequests in Java
You're trying to wrap RMI within SOAP, which isn't pretty mainly because by using SOAP you remove possible system references due to transport + encoding (HTTP + XML / JSON) and are only left with logical ones. Serializing RMI requests into SOAP might as well be like trying to serialize RMI requests within other RMI requests - possible with some serious alchemy, but I think revising the architecture / design would be more productive.

On the other hand, what you're looking for has been done before, but the whole thing kinda makes me want to scream obscenities at all the useless compliance guys and standards-for-the-sake-of-standards attitude prevalent in so many organizations.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
What's an easy way to encode html entities with java?

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

fletcher posted:

What's an easy way to encode html entities with java?

Apache Common's StringEscapceUtils.
http://commons.apache.org/lang/

Gbanfalvi
Jul 23, 2007

Ok this might way too simple or really hard, but i can't think of a solution.

I'm writing a simple networked paint program. Users in my program connect to each other through a socket and are displayed a clear white BufferedImage acting as a canvas. When they drag the mouse across the canvas, mouse events are turned into paths which are drawn on the panel and sent over to the other user as strings. These are simply parsed and drawn on that user's screen.

My issue is with implementing transparency on the strokes. Because each minor segment is drawn individually – making it look like it updates quickly – lots of these overlap giving an inconsistent transparency. I did a mockup in Fireworks because these overlaps show up much more frequently in the program and the problem isn't as clear:



This example is more or less what I get if I draw the paths with a stroke with cap_round, but all the other modes give me similar problems.

My current version of the program (without transparency) is here if you'd like to test it: http://exegersis.com/apps/ Multiple pages haven't been fully implemented yet.

Trig Discipline
Jun 3, 2008

Please leave the room if you think this might offend you.
Grimey Drawer
I'd like to ask what is potentially a mind-bendingly stupid question, but it's driving me crazy. I'm a scientist, and I'm working with a guy who has written a piece of java software. It has a GUI, but I'm supposed to be using some super-secret poo poo that's not available from the GUI yet, invoking it from the command line. All I have is a jar file. He says I should be able to type:

java stuff.Things -arguments

And wonderful things should happen to me and my family. That is not happening. I get java.lang.NoClassDefFoundError: stuff/Things every time. I have never had to use a jar file this way before, and I'm guessing that I'm missing something really simple. I've googled it (honest!) but all I've found so far are a bunch of pages for java programmers outlining how to catch and use command line arguments.

hexadecimal
Nov 23, 2008

by Fragmaster

Trig Discipline posted:

I'd like to ask what is potentially a mind-bendingly stupid question, but it's driving me crazy. I'm a scientist, and I'm working with a guy who has written a piece of java software. It has a GUI, but I'm supposed to be using some super-secret poo poo that's not available from the GUI yet, invoking it from the command line. All I have is a jar file. He says I should be able to type:

java stuff.Things -arguments

And wonderful things should happen to me and my family. That is not happening. I get java.lang.NoClassDefFoundError: stuff/Things every time. I have never had to use a jar file this way before, and I'm guessing that I'm missing something really simple. I've googled it (honest!) but all I've found so far are a bunch of pages for java programmers outlining how to catch and use command line arguments.

You are probably not including some required library in the classpath: http://en.wikipedia.org/wiki/Classpath_(Java)

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Trig Discipline posted:

All I have is a jar file. He says I should be able to type:

java stuff.Things -arguments

code:
java -cp path/to/file.jar stuff.Things -arguments

Trig Discipline
Jun 3, 2008

Please leave the room if you think this might offend you.
Grimey Drawer
Oh sweet jesus THANK you!

Jarl
Nov 8, 2007

So what if I'm not for the ever offended?
I'm coding to the Lego NXT via lejos, and I have a server app on a pc which needs to make use of bluetooth in order to communicate with my nxt's.

For this I use a lejos bluetooth wrapper of sorts perfectly suited for the nxt's running lejos. Now when I try to connect to an nxt through this I get the runtime error "Exception in thread "main" java.lang.NoSuchMethodError: javax.bluetooth.RemoteDevice.<init>(Ljava/lang/String;)V" and a big rear end call stack. This is of course because lejos in turn use the standard java bluetooth library, but the method shouldn't be missing since I have bluecove.jar in my classpath.

Mill Town
Apr 17, 2006

Jarl posted:

I'm coding to the Lego NXT via lejos, and I have a server app on a pc which needs to make use of bluetooth in order to communicate with my nxt's.

For this I use a lejos bluetooth wrapper of sorts perfectly suited for the nxt's running lejos. Now when I try to connect to an nxt through this I get the runtime error "Exception in thread "main" java.lang.NoSuchMethodError: javax.bluetooth.RemoteDevice.<init>(Ljava/lang/String;)V" and a big rear end call stack. This is of course because lejos in turn use the standard java bluetooth library, but the method shouldn't be missing since I have bluecove.jar in my classpath.

One of the annoying things about classpaths is that you have to specify the full path to jars, including file name, not just the directory it's in. So the classpath should be something like

c:\blah\blah\otherstuff.jar;c:\blah\blah\bluecove.jar

rather than just

c:\blah\blah

What OS are you on, anyway? What is your full classpath?

Edit: This page is helpful:
http://mindprod.com/jgloss/classpath.html#GOTCHAS

Edit x2: As this link points out, if your application itself is running from a .jar, Java silently ignores the classpath. You have to add the library jars to your manifest rather than the command-line classpath.

Mill Town fucked around with this message at 15:34 on Jan 18, 2009

Jarl
Nov 8, 2007

So what if I'm not for the ever offended?
My OS is Vista.
MY IDE is Eclipse.
In my eclipse project I have the same jar's as with the environment variable CLASSPATH ".;%Documents%\Eclipse\Lego\bin;%Program Files%\leJOS NXJ\lib\classes.jar;%Program Files%\leJOS NXJ\lib\jtools.jar;%Program Files%\leJOS NXJ\lib\pccomm.jar;%Program Files%\leJOS NXJ\lib\pctools.jar;%Program Files%\leJOS NXJ\3rdparty\lib\bcel-5.1.jar;%Program Files%\leJOS NXJ\3rdparty\lib\bluecove.jar;%Program Files%\leJOS NXJ\3rdparty\lib\commons-cli-1.0.jar;%Program Files%\leJOS NXJ\3rdparty\lib\cpptasks.jar"

I'm not running from a jar - although I didn't know that could cause problems.

Mill Town
Apr 17, 2006

Jarl posted:

My OS is Vista.
MY IDE is Eclipse.
In my eclipse project I have the same jar's as with the environment variable CLASSPATH ".;%Documents%\Eclipse\Lego\bin;%Program Files%\leJOS NXJ\lib\classes.jar;%Program Files%\leJOS NXJ\lib\jtools.jar;%Program Files%\leJOS NXJ\lib\pccomm.jar;%Program Files%\leJOS NXJ\lib\pctools.jar;%Program Files%\leJOS NXJ\3rdparty\lib\bcel-5.1.jar;%Program Files%\leJOS NXJ\3rdparty\lib\bluecove.jar;%Program Files%\leJOS NXJ\3rdparty\lib\commons-cli-1.0.jar;%Program Files%\leJOS NXJ\3rdparty\lib\cpptasks.jar"

I'm not running from a jar - although I didn't know that could cause problems.

Classpath looks good. Go to the command line and do

dir %Program Files%\leJOS NXJ\3rdparty\lib\bluecove.jar

and make sure it's really there.

Also, can you post the code that's giving the error?

Edit: Also, what's the exact command you are using to run this from the command line (or are you running it from inside the IDE?) Does running inside the IDE work or do they both throw this exception?

Edit x2: What's the output of java -version?

Mill Town fucked around with this message at 18:23 on Jan 18, 2009

Jarl
Nov 8, 2007

So what if I'm not for the ever offended?
I just found out it's because I include classes.jar in the project, which I'm not supposed to do. That jar is only for the programs running on the nxt, and not the programs running on the pc communicating with it.

Thanks for your help though.

HFX
Nov 29, 2004

Jarl posted:

I just found out it's because I include classes.jar in the project, which I'm not supposed to do. That jar is only for the programs running on the nxt, and not the programs running on the pc communicating with it.

Thanks for your help though.

That should only be a problem if they somehow contain different versions of the same class or the compiled version number is wrong for the system its running on.

Gbanfalvi
Jul 23, 2007

Gbanfalvi posted:


Err yeah, no one answered my question. Though i found a pretty ugly solution that solves it, i was wondering if it was because it wasn't clear, it was retarded, or... ?

This is just because I might ask questions in the future, and having some form of response might be cool then.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Gbanfalvi posted:

Err yeah, no one answered my question. Though i found a pretty ugly solution that solves it, i was wondering if it was because it wasn't clear, it was retarded, or... ?

This is just because I might ask questions in the future, and having some form of response might be cool then.

I didn't have any useful suggestions. The obvious problem was that you were drawing multiple translucent objects on top of each other. The obvious solution is to combine the objects instead of painting them separately, but I didn't have a good suggestion for how to do that while not causing excessive flicker on large objects, and I figured someone else here might have done it before.

I mean, once you've got a single shared shape, there are three things you should try. First, you might want some sort of point-culling algorithm to eliminate unnecessary segments — if you're actually adding a point per mouse event, that can add up to a lot of redundant points. Second, you should investigate how to request redraw of only the affected region of the path, not the entire thing. Third, you might want to batch redraw requests to some manageable frequency — not one per mouse event, say.

Outlaw Programmer
Jan 1, 2008
Will Code For Food

Gbanfalvi posted:

Err yeah, no one answered my question. Though i found a pretty ugly solution that solves it, i was wondering if it was because it wasn't clear, it was retarded, or... ?

This is just because I might ask questions in the future, and having some form of response might be cool then.

Take a look at the setComposite() method of the Graphics2D object. This page is pretty helpful: http://java.sun.com/docs/books/tutorial/2d/advanced/compositing.html

Specifically, take a look at the "Destination-Over" mode. When you draw pixel on a Graphics2D object, normally you expect your pixels to overlap whatever already exists on the surface. Using this Composite class, you can change this behavior. With the "Destination-Over" composite mode, when you draw on the surface, new pixels will only show up where no previous pixels existed. This should keep you from drawing pixels that overlap the previous stuff, making the color darker.

Outlaw Programmer fucked around with this message at 01:28 on Jan 22, 2009

Jmcrofts
Jan 7, 2008

just chillin' in the club
Lipstick Apathy
I'm really new to Java, and am learning it for a CS class. I installed the Java SDK on my home computer, and whenever I try to run my compiled code through the command prompt I get an error message that says
"Exception in thread "main" java.lang.NoClassDefFoundError"

I looked this up and tried some solutions about editing my CLASSPATH in system settings, but I still haven't been able to get it work. Any help would be much appreciated!

lamentable dustman
Apr 13, 2007

ðŸÂ†ðŸÂ†ðŸÂ†

Jmcrofts posted:

I'm really new to Java, and am learning it for a CS class. I installed the Java SDK on my home computer, and whenever I try to run my compiled code through the command prompt I get an error message that says
"Exception in thread "main" java.lang.NoClassDefFoundError"

I looked this up and tried some solutions about editing my CLASSPATH in system settings, but I still haven't been able to get it work. Any help would be much appreciated!

Going to need more info like what command are you running to compile? javac MyClass.java ? Are you using packages or any external libraries?

ynef
Jun 12, 2002

Jmcrofts posted:

I'm really new to Java, and am learning it for a CS class. I installed the Java SDK on my home computer, and whenever I try to run my compiled code through the command prompt I get an error message that says
"Exception in thread "main" java.lang.NoClassDefFoundError"

I looked this up and tried some solutions about editing my CLASSPATH in system settings, but I still haven't been able to get it work. Any help would be much appreciated!

What you're probably doing is that you type "java MyClass.class", when you should type "java MyClass" (without the ".class" suffix). This of course assumes that you follow your tutorial precisely and have a method like "public static void main(String[] args)", which you may consider the "entry point" of a program.

Jmcrofts
Jan 7, 2008

just chillin' in the club
Lipstick Apathy

ynef posted:

What you're probably doing is that you type "java MyClass.class", when you should type "java MyClass" (without the ".class" suffix). This of course assumes that you follow your tutorial precisely and have a method like "public static void main(String[] args)", which you may consider the "entry point" of a program.

This was pretty much my problem. Or rather, I guess I was trying to run the source code file rather than the compiled class file, which in retrospect was pretty stupid of me. Thanks for the help!

Citanu541
Dec 1, 2008
Well, this is really embarassing but I can not find any logical answer to my problem in my textbook, nor google. I don't think I so much have a problem with code, as I do with the setup of my program. I' only 3 days into Java, so please, excuse the noobishness of this question, we all gotta start some where, right? Anyway, I'm using Netbeans to write and compile code but on multiple occasions I've had the program flag me when compiling for not having a main class set. As far as I can tell, I have one. I honestly am a little confused on the setup of Java programs and classes when starting a project. Here's the tiny program I am currently working on that will not compile because there is no main class.

code:
import java.applet.Applet;
import javax.swing.*;
import java.awt.*;


public class HelloTest extends Applet {

    Container Con = getContentPane();
    JLabel greeting = new Label("Who are you?");
    Font headlineFont = new Font ("Helvetica");
    JTextField answer = new JTextField(10);
    JButton pressMe = new JButton("Press Me");
 
   public void init() {
    
       
        greeting.setFont(headlineFont);
        con.add(greeting);
        con.add(answer);
        con.add(pressMe);
        con.setLayout(new FlowLayout());
         
    }
}

Im sorry if it's something glaringly obvious, I'm still new.

Citanu541 fucked around with this message at 22:37 on Jan 23, 2009

lamentable dustman
Apr 13, 2007

ðŸÂ†ðŸÂ†ðŸÂ†

Citanu541 posted:

Well, this is really embarassing but I can not find any logical answer to my problem in my textbook, nor google. I don't think I so much have a problem with

....

You have several problems with the code. The method call getContentPane() is in JApplet not Applet so instead of "extends Applet" it should be "extends JApplet"

JApplet is part of Swing, Applet is part of awt.


Next you have "JLabel greeting = new Label("Who are you?");" Notice that your types are mismatched. Either make them both JLable or Lable.

Last issue is that your constructor for the Font object is wrong. Look here for the correct constructors http://java.sun.com/javase/6/docs/api/java/awt/Font.html


About the main class problem, you don't need one when making an applet or JFrame or whatever. I don't use netbeans so I'm not sure how it is there but in Eclipse they give you the option of "Run as applet" instead of "Run as application."

Bellow is probally what you wanted your code to look like

code:
import java.applet.Applet;
import javax.swing.*;
import java.awt.*;


public class HelloTest extends JApplet {

    Container Con = getContentPane();
    JLabel greeting = new JLabel("Who are you?");
    Font headlineFont = new Font ("Helvetica",Font.BOLD,10);
    JTextField answer = new JTextField(10);
    JButton pressMe = new JButton("Press Me");
 
   public void init() {
    
       
        greeting.setFont(headlineFont);
        Con.add(greeting);
        Con.add(answer);
        Con.add(pressMe);
        Con.setLayout(new FlowLayout());
         
    }
}
It is also bad form to start the objects that you create with a capital letter so the object Con should be con.

lamentable dustman fucked around with this message at 23:00 on Jan 23, 2009

Citanu541
Dec 1, 2008
Ah, thank you. I started debugging the obvious, but still ran into the no main class problem. I didn't realize all my syntax errors before posting that, but as I said, I didn't think the code was the problem. When every inch of the code is underlined in red, you start to feel the problem is else where.

I appreciate you going over my code, however, plugging it into my current project, it STILL errors out with the class error. I hate this crap, I don't know what I'm not picking up, this is my second attempt at Java, but this is the exact same problem that plagued and stopped me last time.

lamentable dustman
Apr 13, 2007

ðŸÂ†ðŸÂ†ðŸÂ†

Citanu541 posted:

Ah, thank you. I started debugging the obvious, but still ran into the no main class problem. I didn't realize all my syntax errors before posting that, but as I said, I didn't think the code was the problem. When every inch of the code is underlined in red, you start to feel the problem is else where.

I appreciate you going over my code, however, plugging it into my current project, it STILL errors out with the class error. I hate this crap, I don't know what I'm not picking up, this is my second attempt at Java, but this is the exact same problem that plagued and stopped me last time.

I launched NetBeans and had a look. When you create a project in NetBeans it makes a 'Main.java' class. You should probably just delete that. In the right click on the java file in the left pane (or hit shift+F6) you have the option to run the code. It launches just fine in the applet viewer.

Citanu541
Dec 1, 2008
Dammit. Well, every project I create, even with the simplest bit of code runs as <no main classes found>

I don't get it, I'm not as inept as this is making me out to be. This is making me more frustrated than anything, best to give up for now. Thank you for your help, though.

e: I'm guessing I got a bunk instillation, because Netbeans never compiled anything correctly.

Citanu541 fucked around with this message at 00:04 on Jan 24, 2009

Outlaw Programmer
Jan 1, 2008
Will Code For Food

Citanu541 posted:

Dammit. Well, every project I create, even with the simplest bit of code runs as <no main classes found>

I don't get it, I'm not as inept as this is making me out to be. This is making me more frustrated than anything, best to give up for now. Thank you for your help, though.

e: I'm guessing I got a bunk instillation, because Netbeans never compiled anything correctly.

Just tested in my version of Netbeans (6.1 I believe), and I think I see what's going on. A "main" class is a class that can be used as a starting point for a program. This means the class either has a "public static void main(String[] args)" method OR, for applets, a "public void init()" method.

However, it seems that Netbeans is only flagging classes that have the main() method, not the init() method. That means that you can't just click the "Run Project" button (defaults to F6 key I think). You CAN still run your applet. When you have YourApplet.java open, right click anywhere in the editor and click the "Run YourApplet.java" item. Alternatively, you can just press Shift-F6.

Citanu541
Dec 1, 2008
Ha! That was exactly the problem, so it was the IDE. I think I'm starting to prefer Eclipse, but class requires NetBeans. That's really odd, though, how were we supposed to know that? (We've not created Applets except for this first assignment.)

Thanks for the help, guys.

cyberburrito
Apr 4, 2005
Hey Guys, I am new to java (some experience with C) and I am having trouble coming up with a solution. I have a program that reads in scores to find the lowest highest and average score. What I need is for it to only accept numbers 1-100 into the array, any others will need to display "Invalid, try again" . I am currently trying a catch for Input mismatch, which works, but it ends the program instead of getting a new input Any ideas?

code:
import java.util.*;
import java.lang.Integer;
public class Main {	
        public static void main(String[] args ) {
		// TODO Auto-generated method stub
		final int SENTINEL =-1;
		final int MAX = 120;
		int total = 0;
		double average = 0;
		int highest = 0;
		int lowest = 0;
		int n=-1;
		int next =0;		
		int [] grade = new int[MAX];
		Scanner keyboard =	new Scanner(System.in); 
		System.out.println("Welcome to the test score program");
		while(next != SENTINEL)
		{
			n = n+1;
			System.out.println("Please enter a test score (-1 to exit)");
			try{

			next = keyboard.nextInt();
		}
			catch(InputMismatchException nFE) {
				     System.out.println("Not an Integer");
												}
			//if(next > 100 || next <0 || )
			if(next != -1)
			{
				if(next > 100 || next < 0)
				{
					System.out.println("Invalid choice");
					break;
				}
				grade[n] = next;
				total = total + next;
				//System.out.println(total);
			}
			
		}	
}
}

1337JiveTurkey
Feb 17, 2005

The most obvious problem is that you don't close the catch block after the println().

A few points: Scanner is for parsing out more complex files for just the data you're interested in. You'd probably just want System.getConsole() to get the console for this program or use a BufferedReader created from the System.in input stream. Integer.parseInt() can parse any input string to tell if it's an integer. Typically you'd put a try-catch block around that and catch any NumberFormatExceptions. For situations where you don't know how many inputs you're going to have, an ArrayList<Integer> is usually cleaner. It uses auto-boxing to act like the ArrayList<Integer> really is an int[]. Finally, using -1 as a sentinel value is more trouble than it's worth when you can read in and recognize "q", "quit", "exit" or whatever.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!
Fake Edit: Or just do what 1337JiveTurkey says. Though you did close the catch block, it just didn't look like it because the indentation was messed up.

cyberburrito posted:

looping stuff
I have never used java before, but break, well, breaks out of the loop. If you want to skip back to the beginning of the loop, you want to use the continue statement.

Also, I think it would make more sense to put the rest of the logic inside the try block, because otherwise you catch the exception and then keep going inside the loop as if everything were alright, which it isn't.

And this isn't a java issue, but I'd put the increment of n at the end of the loop. Otherwise, every time someone tries a bad input, you skip a number, which I assume is not desired.

So, 'my' code would look like
code:
import java.util.*;
import java.lang.Integer;
public class Main {	
        public static void main(String[] args ) {
		// TODO Auto-generated method stub
		final int SENTINEL =-1;
		final int MAX = 120;
		int total = 0;
		double average = 0;
		int highest = 0;
		int lowest = 0;
		int n=0;
		int next =0;		
		int [] grade = new int[MAX];
		Scanner keyboard =	new Scanner(System.in); 
		System.out.println("Welcome to the test score program");
		while(next != SENTINEL)
		{
			n = n+1;
			System.out.println("Please enter a test score (-1 to exit)");
			try{

				next = keyboard.nextInt();
			
				if(next != SENTINEL)
				{
					if(next > 100 || next < 0)
					{
						System.out.println("Invalid choice");
						continue;
					}
					grade[n] = next;
					total = total + next;
					//System.out.println(total);
					n = n+1;
				}
			}
			catch(InputMismatchException nFE) {
				     System.out.println("Not an Integer");
			}
		}
	}
}

lamentable dustman
Apr 13, 2007

ðŸÂ†ðŸÂ†ðŸÂ†

I'm having an issue with having javascript communicating with a java applet I'm writing. The poo poo was working fine 3 weeks ago and apparently I've changed some things to break. I got the code cut down to bellow to test.

code:
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextArea;


public class WaterTempGrid extends JApplet implements ActionListener{
	private static final long serialVersionUID = -6921859578015711379L;

	private JPanel map;
	private JPanel bottom;
	private JTextArea awaitingDataMessage;
	private ArrayList<Double> newCoords;
	private String message;
	private JButton but;
	private JButton test;
	
	public void init(){
		map = new JPanel();
		map.setLayout(new BorderLayout());
		
		bottom = new JPanel();
		bottom.setLayout(new BorderLayout());
		
		map.add(bottom, "South");
		but = new JButton("Update Coords");
		test = new JButton("Get Data");
		but.addActionListener(this);
		test.addActionListener(this);
		bottom.add(but,"West");
		bottom.add(test,"East");
		
		awaitingDataMessage = new JTextArea("waiting on data");
		map.add(awaitingDataMessage);
		
		message = "stop initlizing gently caress YOU";
		
		add(map);
	}
	
	public void newCoordinates(String lllat, String lllon, String urlat, String urlon){
		System.out.println( lllat + " " +  lllon + " | " + urlat + " " + urlon);
		
		newCoords = new ArrayList<Double>();
		newCoords.add(Double.parseDouble(lllat));
		newCoords.add(Double.parseDouble(lllon));
		newCoords.add(Double.parseDouble(urlat));
		newCoords.add(Double.parseDouble(urlon));
		

		message = newCoords.get(0) + " " +  newCoords.get(1) + " " +
		"| " + newCoords.get(2) + " " + newCoords.get(3);

		awaitingDataMessage.setText(message);
	}
	

	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == but){
			awaitingDataMessage.setText("**************************");

		}else if(e.getSource() == test){
			System.out.println(message);
		}
	}
}
and the HTML

code:
<html>
	<head>
		<title>applet test</title>
		
		<script type="text/javascript">
			function updateCoords(){
				document.applet.newCoordinates(
					document.getElementById('lllat').value,
					document.getElementById('lllat').value,
					document.getElementById('lllat').value,
					document.getElementById('lllat').value
				);
			}
		</script>
	</head>
	<body>
		<form>
			<table>
				<tr><td></td><td></td>
					<td>
						<input type="text" id="trlat"/>
					</td>
					<td>
						<input type="text" id="trlon"/>
					</td>
				</tr>
					<td>
						<input type="text" id="lllat"/>
					</td>
					<td>
						<input type="text" id="lllon"/>
					</td>
					<td></td><td></td>
				</tr>
			</table>
		<input type="submit" value="test" onClick="updateCoords();"/>
		<br/>
		<applet
			name="applet"
			code="WaterTempGrid.class"
			width="600" height="600"
			archive="test.jar"
		>applet here i hope
		</applet>
	</body>
</html>
The Update Coords JButton just changes the JTextArea to just a bunch of ****************. The Get Data button is just to sysout what the string message is currently set to. The problem is with the javascript call to put the content of the text boxes into the applet. When I hit the button the whole applet reinitialize. I see the content of the JTextArea flash the correct content for a spit seconds before reverting to the initial value of "Waiting for data." If I hit the Get Data button the string message is "stop initlizing gently caress YOU" again.

In the full applet this updates a map which flashes for a split second before going back to the initial state like this example is showing.

Any ideas why this is happening? It was working fine before.

lamentable dustman
Apr 13, 2007

ðŸÂ†ðŸÂ†ðŸÂ†

gently caress, just realized it is because I'm using a form tag and that is causing the whole page to reload. Took it out and it worked properly.....



I had to remake the page after my workstation was reloaded and I forgot to back up that part....




that loving poo poo cost me over 6 hours of time....

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost
So has anyone else messed around with dependency injection frameworks / libraries in Java? Google Guice seems to be fine for the jobs we've got, but we've got ourselves a home-brew dependency injection framework that is extremely clunky and I'm trying to get a better grasp on other options before overhauling the clunkiness we've got. I'm trying to keep it simple, but I do know I'm going to have to write a code generator to use any framework since what I'm working with is generated code that would take basically forever to perform the bindings manually. There aren't any dependency injectors that load class files and generate code for found classes according to some rules by chance, are there?

Adbot
ADBOT LOVES YOU

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

necrobobsledder posted:

So has anyone else messed around with dependency injection frameworks / libraries in Java? Google Guice seems to be fine for the jobs we've got, but we've got ourselves a home-brew dependency injection framework that is extremely clunky and I'm trying to get a better grasp on other options before overhauling the clunkiness we've got. I'm trying to keep it simple, but I do know I'm going to have to write a code generator to use any framework since what I'm working with is generated code that would take basically forever to perform the bindings manually. There aren't any dependency injectors that load class files and generate code for found classes according to some rules by chance, are there?

Spring has a DI framework and I've found it decently powerful. With annotations it's not too bad to use, and configuration with Groovy is pretty easy.

To answer your last question, do you have an example of what you're trying to do? If I understand you correctly, you want to do something similar to what Grails does. Grails (uses Spring) will load (and reload) arbitrary classes based on className by introspecting all classes in a given location. The "rules" are basically that the classes have to exist in a certain location. I'm sure you could do something similar.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply