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
Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Hey guys I have a question about GlassFish that I can't really find the answer to. I just want to clarify if it's necessary to use a load balancer with a cluster.

What happens when I try to just access the cluster without a load balancer? Or is that not even possible, I would have to specify a specific server?

In the case that it is required, what software load balancer would you recommend?

Adbot
ADBOT LOVES YOU

Riff
Oct 2, 2005

...
I'm working in netbeans at the moment trying to build a gui for a simple higher lower guessing game. I can't for the life of me find any resources on how to bind the gui I've designed to the code. I understand how to put code in when an event is performed (like clicking a button), but how do I then get values from drop down boxes, check to see whether a box is checked etc...

There's plenty of examples of how to do it all manually, but none for using netbeans.

Edit: actually this is probably a stupid question and I'm just being lazy. Java gets a little overwhelming at times and it'd just be nice to have a list of common useful functions.

Riff fucked around with this message at 19:03 on Feb 15, 2010

yatagan
Aug 31, 2009

by Ozma

Riff posted:

I'm working in netbeans at the moment trying to build a gui for a simple higher lower guessing game. I can't for the life of me find any resources on how to bind the gui I've designed to the code. I understand how to put code in when an event is performed (like clicking a button), but how do I then get values from drop down boxes, check to see whether a box is checked etc...

There's plenty of examples of how to do it all manually, but none for using netbeans.

Edit: actually this is probably a stupid question and I'm just being lazy. Java gets a little overwhelming at times and it'd just be nice to have a list of common useful functions.

I literally just assigned that to a class earlier this morning, are you in Chicago?

You must do it manually if you're learning basic Java, if you rely on a fancy IDE tool to learn you will be burned when you have to do something it's not capable of or is really annoying to do with it.

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat
I have a question that deals with Hibernate + Spring. I am working on a project that has two types of users. One is a parent, one is a child. A parent can register and create a new account and log in. Then, a parent can also create child users, which it has control to add and delete. These users can then log in.

How can I safely protect the user accounts from the client but still allow for this relationship in the ORM? The main issue is that I'd be serializing this collection to the client, which would then expose all these Account classes.

EDIT: I guess I should have clarified this, but my biggest concern is returning the password field to the client, which I would like to avoid doing.

CRIP EATIN BREAD fucked around with this message at 22:39 on Feb 15, 2010

Riff
Oct 2, 2005

...

yatagan posted:

I literally just assigned that to a class earlier this morning, are you in Chicago?

You must do it manually if you're learning basic Java, if you rely on a fancy IDE tool to learn you will be burned when you have to do something it's not capable of or is really annoying to do with it.

Nope, all the way over in England. I guess it's a popular teaching method. You're probably right, the thing is it's a pretty poor course and netbeans is all I know. The class is on software design rather than straight programming, so they're more interested in how we structure it rather than the end result.

Mill Town
Apr 17, 2006

CRIP EATIN BREAD posted:

I have a question that deals with Hibernate + Spring. I am working on a project that has two types of users. One is a parent, one is a child. A parent can register and create a new account and log in. Then, a parent can also create child users, which it has control to add and delete. These users can then log in.

How can I safely protect the user accounts from the client but still allow for this relationship in the ORM? The main issue is that I'd be serializing this collection to the client, which would then expose all these Account classes.

EDIT: I guess I should have clarified this, but my biggest concern is returning the password field to the client, which I would like to avoid doing.

Use a one-way hash on the passwords?

Edit: You should always hash your passwords. never store them in cleartext anywhere.

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat

Mill Town posted:

Use a one-way hash on the passwords?

Edit: You should always hash your passwords. never store them in cleartext anywhere.

I'm currently hashing with a salted MD5, but I still would prefer to not even send that back to the user.

However, I think I figured out what I needed to do, it turns out that my externalizer/serializer has an ability to ignore fields in an entity bean, so I am ignoring the password field and setting and creating a separate service call for updating the password.

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

CRIP EATIN BREAD posted:

I'm currently hashing with a salted MD5, but I still would prefer to not even send that back to the user.

However, I think I figured out what I needed to do, it turns out that my externalizer/serializer has an ability to ignore fields in an entity bean, so I am ignoring the password field and setting and creating a separate service call for updating the password.

Can't you just mark the field transient (or @Transient) and it won't be sent with the bean data?

Boz0r
Sep 7, 2006
The Rocketship in action.
I'm trying to learn Java RMI by implementing a basic Bank + Accounts system. I just can't get the most basic part of this poo poo to work.



code:
import java.rmi.Remote;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import RMIserver.*;

public class Server {
	
	public static void main(String[] args) {
		try {
			String name = "Bank";
			Bank bank = new ConcreteBank();
			Bank stub = (Bank) UnicastRemoteObject.exportObject(bank, 0);
            Registry registry = LocateRegistry.getRegistry();
            
            registry.rebind(name, stub);
            System.out.println("Account broadcast");
		} catch (Exception e) {
			System.out.println ("Account broadcast failed: \n\n" + e);
		}
	}
}
code:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class Client {
	public static void main(String args[]) {
		if (System.getSecurityManager() == null) {
			System.setSecurityManager(new SecurityManager());
		}
		try {
			String name = "Account";
			Registry registry = LocateRegistry.getRegistry("127.0.0.1");
			Account account = (Account) registry.lookup(name);
			System.out.println (account.getName() + ": " + account.getBalance());
		} catch (Exception e) {
			System.out.println ("HelloClient exception: " + e);
		}
	}    
}
code:
import java.rmi.Remote;
import java.rmi.RemoteException;

public interface Bank extends Remote {
	public Account getAccount(String name) throws RemoteException;
}
code:
import java.rmi.Remote;

public interface Account extends Remote {
	public String getName();
	public double getBalance();
	public void deposit(double amount);
	public void withdraw(double amount);
}
Everytime I try to compile and run the Server class I get this exception:

code:
Account broadcast failed: 

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
	java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
	java.lang.ClassNotFoundException: RMIserver.Bank
I have rmiregistry running in the background, else I got another exception.

What am I doing wrong/missing, how do I get this to work?

epswing
Nov 4, 2003

Soiled Meat
I remember getting a lot of mileage out of the Cajo Project (wikipedia link) when writing an internal client/server app. I suppose if your goal is to learn RMI, you should continue without the aid of such a framework, but as I recall Cajo made RMI much easier to deal with.

Shavnir
Apr 5, 2005

A MAN'S DREAM CAN NEVER DIE
I haven't done anything with RMI but at a glance it looks like its trying to resolve the Bank interface in the RMIserver package. Try switching to explicit imports from there and see if it can't pick up on Bank being in the same package then.

Boz0r
Sep 7, 2006
The Rocketship in action.
Yeah, my instructor has asked me to use RMI so I guess there's no way around that. I've gotten the server up and running, though. Now it's the client that's giving me poo poo:

code:
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
import java.util.*;
import RMIserver.*;

public class BankServer extends UnicastRemoteObject implements Bank {
	
	private static final long serialVersionUID = 62824L;
	List<Account> accounts;
	
	protected BankServer() throws RemoteException {
		accounts = new ArrayList<Account>();
	}
	
	@Override
	public Account getAccount(String name) throws RemoteException {
		Account tempAccount = null;
		for(int i = 0; i < accounts.size(); i++) {
			if(accounts.get(i).getName().equals(name)) {
				tempAccount = accounts.get(i);
			}
		}
		if (tempAccount != null) {
			return tempAccount;
		}
		else {
			Account account = new AccountServer(name);
			accounts.add(account);
			return account;
		}
	}
	
	public static void main (String[] args) throws Exception {
		if (System.getSecurityManager() == null)
			System.setSecurityManager(new SecurityManager());
		
		String host = "localhost";
		if (args.length > 0) 
			host = args[0];
		System.out.println("Starting Server at " + host);
		
		BankServer server = new BankServer();
		Naming.rebind("//" + host + "/BankServer", server);
	}
}
code:
import java.rmi.*;

public class BankClient {

	public static void main(String[] args) throws Exception {

		if (System.getSecurityManager() == null)
			System.setSecurityManager(new SecurityManager());

		String host = "localhost";
		if (args.length > 0) host = args[0];
		Bank bank = (Bank) Naming.lookup("//" + host + "/BankServer");
		String name = "Michael";
		Account account = bank.getAccount(name);
		System.out.println(account.getName() + " has a balance of " + account.getBalance() + " Fantasy Land Dollars");
		account.deposit(12598);
		account.withdraw(67);
		System.out.println(account.getName() + " has a balance of " + account.getBalance() + " Fantasy Land Dollars");
	}
}
I have rmiregistry running in the background. I've used rmic to generate stubs/skeletons for BankServer, and I run it with a wide open security policy. I get the following Exception:

code:
C:\RMIserver>java -Djava.security.policy=wideopen.policy BankClient 127.0.0.1
Exception in thread "main" java.rmi.ConnectException: Connection refused to host: 10.198.19.197; nested exception is:
        java.net.ConnectException: Connection refused: connect
        at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
        at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
        at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
        at sun.rmi.server.UnicastRef.invoke(Unknown Source)
        at BankServer_Stub.getAccount(Unknown Source)
        at BankClient.main(BankClient.java:14)
Caused by: java.net.ConnectException: Connection refused: connect
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(Unknown Source)
        at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
        at java.net.PlainSocketImpl.connect(Unknown Source)
        at java.net.SocksSocketImpl.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at java.net.Socket.<init>(Unknown Source)
        at java.net.Socket.<init>(Unknown Source)
        at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
        at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)
        ... 6 more
God drat this RMI stuff sucks donkey balls. Does anyone have an idea as to what's wrong?

Fehler
Dec 14, 2004

.
I'm trying to design a Swing form with auto-resizing components in the Netbeans GUI Designer.

My current version works fine if I enlarge the form (i.e. all the components nicely resize with it), but if I make it smaller beyond a certain threshold, the components stay at a fixed size and the right side is just clipped.

It seems like something is preventing the components from getting smaller, but I cannot for the life of me figure out what. All components and (as far as I can see) all components inside them have horizontal Auto-Resize enabled, but they still seem to get stuck at some point.

Any ideas what might be happening here and what else I could try?

NeerWas
Dec 13, 2004

Everyday I'm shufflin'.

NeerWas fucked around with this message at 21:42 on Aug 9, 2023

8ender
Sep 24, 2003

clown is watching you sleep
jDeveloper, as much as I hated using it, had excellent intellisense. I really don't recommend using it though until it sees about four more updates worth of bug fixes and performance tweaks.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Fly posted:

I'll check out JFreeChart when it comes time to redo our current charts.

I ended up buying the JFreeChart developer guide. They really put a lot of work into it, and you can do pretty much whatever you want with the charts. I'm really liking using it so far.

Cosmopolitan
Apr 20, 2007

Rard sele this wai -->
Does anyone know if it's possible to make Eclipse store the .metadata folder in its executable folder, rather than the workspace folder? It's really annoying having to copy that folder every time I change workspace locations.

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat

TRex EaterofCars posted:

Can't you just mark the field transient (or @Transient) and it won't be sent with the bean data?

This will cause it to not be persisted into the database. But as I mentioned above, I had to do it through the externalizer that was serializing the data over an AMF channel.

epswing
Nov 4, 2003

Soiled Meat
Regarding java/tomcat web development, is the workflow still the same? Make changes, deploy/reload, refresh browser, repeat...until OutOfMemoryError: PermGen space, in which case shutdown (or even kill -9, if necessary), startup, repeat.

I can hardly believe this issue, which affects everyone in the world who develops for the tomcat container, hasn't been solved yet.

Edit: or has it? I heard tomcat 6.0.24 fixes this (by actively reaching into other libs and nulling references, killing off threads, etc), c/d?

epswing fucked around with this message at 18:48 on Feb 19, 2010

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
I'm trying to log some database queries that are generated using a custom class, QueryBuilder. I want to log some information about the user logged into my app executing the query as well as how long the query took etc.

Essentially I'm doing this:

code:
QueryBuilder queryBuilder = new QueryBuilder(bunch, of, stuff);
queryBuilder.setSomething(something);
String query = queryBuilder.getQuery();

Statement statement = connection.prepareStatement(query);
ResultSet resultSet = statement.executeQuery(query);

if (resultSet != null) {
    while (resultSet.next()) {
        //do stuff
    }
}

if (resultSet != null)
    resultSet.close();

if (statement != null)
    statement.close();
I do this all over the place, using my QueryBuilder class to generate a lot of different looking queries, with some similarities. I'm trying to think of a way to add the logging I want in as simple of a way as possible, but everything I come up with seems pretty messy. Any ideas?

edit: How about adding a getResultSet() to my QueryBuilder class? Is there a way to automatically have it call resultSet.close() and statement.close() when the QueryBuilder gets garbage collected? Do I even need to do that?

fletcher fucked around with this message at 20:27 on Feb 19, 2010

Fly
Nov 3, 2002

moral compass

fletcher posted:

I'm trying to log some database queries that are generated using a custom class, QueryBuilder. I want to log some information about the user logged into my app executing the query as well as how long the query took etc.

Essentially I'm doing this:

code:
QueryBuilder queryBuilder = new QueryBuilder(bunch, of, stuff);
queryBuilder.setSomething(something);
String query = queryBuilder.getQuery();

Statement statement = connection.prepareStatement(query);
ResultSet resultSet = statement.executeQuery(query);

if (resultSet != null) {
    while (resultSet.next()) {
        //do stuff
    }
}

if (resultSet != null)
    resultSet.close();

if (statement != null)
    statement.close();
I do this all over the place, using my QueryBuilder class to generate a lot of different looking queries, with some similarities. I'm trying to think of a way to add the logging I want in as simple of a way as possible, but everything I come up with seems pretty messy. Any ideas?

edit: How about adding a getResultSet() to my QueryBuilder class? Is there a way to automatically have it call resultSet.close() and statement.close() when the QueryBuilder gets garbage collected? Do I even need to do that?
Do not rely on the finalizer to do stuff though. Try to avoid a split cleaner by having a finish() or close() method on your query builder that you call from a finally block.

If you're dynamically creating all of the SQL, it's probably not a good idea to prepare the statement as that adds no safety and incurs overhead.

HondaCivet
Oct 16, 2005

And then it falls
And then I fall
And then I know


Quick noob sorta question: Is there a way to compare strings that is case AND space insensitive? Like something that would say "ooga booga" == "OOGA BOOGA" == "oogaBooga" is true?

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

HondaCivet posted:

Quick noob sorta question: Is there a way to compare strings that is case AND space insensitive? Like something that would say "ooga booga" == "OOGA BOOGA" == "oogaBooga" is true?

I don't know what you are doing but maybe strip all the whitespace characters from the string and convert to lower case.

HondaCivet
Oct 16, 2005

And then it falls
And then I fall
And then I know


MEAT TREAT posted:

I don't know what you are doing but maybe strip all the whitespace characters from the string and convert to lower case.

It's really simple, I am just taking input from a text file and making strings out of it, so your suggestion should work I think. Thanks!

stephpwnz
Aug 28, 2006
I need to program a gaussian elimination algorithm. My instructor has specified that the algorithm in main should be:

declarations & initializations
while theres still data in file do
input data
echo print data
do Gaussian elimination
print solution
end while

I'm supposed to read the file name from the command line. The file could be like this:

3
5 -1 -1 11
-1 5 -2 0
-2 -2 4 0
3
0 1 1 1
0 -2 -2 -8
0 0 -6 2
4
2 1 1 -6 -1
-3 6 -1 8 -20
1 1.0 1 -3 0
4 -2 8 -3 43


Where the first integers are the number of unknowns. So there are three gaussian elimination problems, two with 3 unknowns, and the last with 4. Keep in mind he can add up to 10 problems, all with varying unknowns.

I'm not sure how to separate the problems when I read from the file. I'm not supposed to have one huge array with all the numbers in it. I'm supposed to do one problem at a time and then loop to the next problem, using the scanner class.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
stephpwnz: The solution here involves declaring your storage in the scope of your main loop, rather than as "globals". Here's a program fragment that follows a similar pattern- study it, and see if you can figure out how to adapt it to what you're doing.

code:

Random rand = new Random();
int iterations = 5;

// while we still have more iterations to complete...
while (iterations > 0) {

  // allocate an array
  int[] data = new int[rand.nextInt(10)+5];

  // fill it with some data
  for(int index = 0; index < data.length; index++) {
    data[index] = rand.nextInt(10);
  }

  // sum the array
  int sum = 0;
  for(int index = 0; index < data.length; index++) {
    sum += data[index];
  }

  // print out the result
  System.out.println(sum);

  iterations--;
}
Notice that in each iteration of the main loop we allocate a new storage array of a different size.

stephpwnz
Aug 28, 2006
Alright, thanks, I figured out that part. :) Now I'm having a hell of a time with the algorithm I'm supposed to perform. It goes like this:

To solve the nX n linear system
E1 : a11 x1 +a12 x2 + +a1n xn = a1,n+1
E2 : a21 x1 +a22 x2 + +a2n xn = a2,n+1
.
.
. ... ... ... ...
En : an1 x1 +an2 x2 + +ann xn = an,n+1

INPUT number of unknowns and equations n; augmented matrix A = (aij ) where 1
≤ i ≤ n and
1 ≤ j ≤ n + 1.
OUTPUT solution x1 , x2 , . . . , xn or message that linear system has no unique solution

Step 1 For i = 1, . . . , n − 1 do Steps 2 4. (Elimination Process)

Step 2 Let p be the smallest integer with i ≤ p ≤ n and ap,i ̸= 0.
If no integer p can be found then
OUTPUT(singular matrix - no unique solution); STOP.

Step 3 If p = i then perform (Ep ) ↔ (Ei ).

Step 4 For j = i + 1, . . . , n do Steps 5 and 6.

Step 5 Set m = aji /aii .

Step 6 Perform (Ej − mEi ) → (Ej ).

Step 7 If ann = 0 then OUTPUT(no unique solution exists); STOP.

Step 8 Set xn = an,n+1 /ann . (Start backward substitution)

Step 9 For i = n − 1, . . . , 1 set xi = [ai,n-1 - ∑aij*xj]/aii (above the epsilon is n, below is j=i+1)

Step 10 OUTPUT(x1 , . . . , xn ); (Procedure completed successfully)
STOP.

No idea how to structure the nested for loops, what p is supposed to be, and what the swapping of Ep to Ei is. I haven't taken linear algebra yet so forgive me.

RichardA
Sep 1, 2006
.
Dinosaur Gum
^^^^
If you have a matrix A Ai,j refers to the element in the ith row and jth column. For example the A2,3 would be the third element in the second row.

Are you sure you wrote down step 2 correctly? I think it should be Ap,i != 0. Assuming I am correct this step is to just make sure that there is not a zero in the pivot position.(The algorithm would fail on step 6 with a division by zero)


Should the equals signs in step 3 be not equal signs? I believe (Ep) ↔ (Ei) means to swap the row p with row i but that does not make sense unless step 3 is "If p != i" or something similar.

(Ej − mEi ) → (Ej ) is effectively saying to take m times the ith row from the jth row.

The loops may look something like this:
code:
for(int i=1;i<=n;i++){ //Step 1
  //Insert Step 2 (May need a for loop to find p)
  //Insert Step 3
  for(int j=i+1;j<=n;j++){ //Step 4
    //Insert Step 5
    //Insert Step 6
  }
}
//Insert Step 7
//Insert Step 8
for(int i = n-1;i>=1;i--){//Step 9
    //Insert Step 9
}
//Insert Step 10
I have not checked the above for errors so take it with a grain of salt. Out of interest how are you representing the matrix?

RichardA fucked around with this message at 03:36 on Feb 21, 2010

stephpwnz
Aug 28, 2006
code:
	public static double[] gauss(double [][] gauss, int n) {
		
		
		double[] sol=new double[n];
		double[] temp=new double[n+1];
		double m=0;
		int p;
			

		for(int i=0; i<n-1; i++){
			
			p=i+1;
			while(gauss[p][i]==0 && p<=n){
				p++;
			}
		
			if (p!=i){
				for(int z=0; z<n+1; z++){
					temp[z]=gauss[i][z];
					gauss[i][z]=gauss[p][z];
					gauss[p][z]=temp[z];
				}
			}
			
			for(int j=i+1; j<n; j++){
				m=gauss[j][i]/gauss[i][i];
				for(int t=0; t<n+1; t++)
					gauss[j][t]-=(m*gauss[i][t]);
			}
			
		}
			
		sol[n-1]=gauss[n-1][n]/gauss[n-1][n-1];

		for(int i=n-1; i>=0; i--){
			double sum=0;
			for(int j=i+1; j<n; j++){
				sum+=gauss[i][j]*sol[j];
			} 
			sol[i]=(gauss[i][n]-sum)/gauss[i][i];

		}
				
		return sol;
	}
This is the final, working method. I did copy the arguments wrong. Thank you very much.

FateFree
Nov 14, 2003

I'm bored and want to try something a little different. I want to code some people objects, and more importantly try to code their thought process as close as possible to the real thing, which I might expand into a game at a later point but is really just a POC at this point. I'd like to have a virtual room full of them and basically watch them interact.

This is far from what I normally code so my question is how to best architect this. The first things that come to mind are should each person run in their own thread, should I be looking into the Executor class for that? Can anyone give a high level overview or any resources so I can start with the implementation?

pseudopresence
Mar 3, 2005

I want to get online...
I need a computer!
First things first, forget "as close as possible to the real thing". Nobody has much idea how the high-level processes of the mind operate.

These might be good places to read about AI for games:

http://aigamedev.com/
http://www-cs-students.stanford.edu/~amitp/gameprog.html#ai
http://www.aiwisdom.com/

In terms of implementation, no, you don't want each person running in their own thread. That will be a concurrency nightmare with no benefits. You most likely want a simulated world that ticks/updates at regular intervals. If you double-buffer the state of each person, holding the state from the previous frame while you build the state for the current frame, you can easily split up the work of updating persons across multiple threads.

diadem
Sep 20, 2003
eet bugz
I opened a window using window.open. I pass in the argument scrollbars and set the value to either yes or no.

I am now in the child window. My javascript is running. I want to know if the window has scrollbars enabled or not. How do I do this?

- I am in IE so window.scrollbars/this.scrollbars won't return anything
- The windows scrollbars exist outside the body.
- Looking at the document's width will tell me about the document. I can even figure out if there are scrollbars in the document. This will not tell me anything about the window itself.
- The width of the scrollbar in question changes Dependant on what the currently selected Windows Desktop Theme is, for ascetic reasons.

edit: This belongs in the javascript thread

diadem fucked around with this message at 19:00 on Feb 23, 2010

lamentable dustman
Apr 13, 2007

🏆🏆🏆

i don't think those functions exist in Swing but i could be wrong

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
I'm looking at different ways of making objects persistent in Java. I'm not sure if I want to go the RDBMS route and just use MySQL again and write my on SQL. JDO sounds interesting but I think MemcacheDB might be the way to go. What do you guys think? The idea of not having to write any SQL sounds nice, but I feel like I will run into limitations down the road.

Fly
Nov 3, 2002

moral compass

fletcher posted:

I'm looking at different ways of making objects persistent in Java. I'm not sure if I want to go the RDBMS route and just use MySQL again and write my on SQL. JDO sounds interesting but I think MemcacheDB might be the way to go. What do you guys think? The idea of not having to write any SQL sounds nice, but I feel like I will run into limitations down the road.
The Java Persistence Architecture (JPA) looks pretty nice. It appears to be a Java standard similar to Hibernate. You can specify the O-R mapping with Annotations, so you don't need a horrid XML file for configuration.

javax.persistence package: http://java.sun.com/javaee/5/docs/api/index.html?javax/persistence/package-summary.html

You will need to find an implementation of it. I think Hibernate may implement that latest JPA spec as well as its own API. The API itself is quite sensible and useful.

Here is a comparison of some implementations that came up on a quick search: http://terrazadearavaca.blogspot.com/2008/12/jpa-implementations-comparison.html

crazyfish
Sep 19, 2002

Fly posted:

The Java Persistence Architecture (JPA) looks pretty nice. It appears to be a Java standard similar to Hibernate. You can specify the O-R mapping with Annotations, so you don't need a horrid XML file for configuration.

javax.persistence package: http://java.sun.com/javaee/5/docs/api/index.html?javax/persistence/package-summary.html

You will need to find an implementation of it. I think Hibernate may implement that latest JPA spec as well as its own API. The API itself is quite sensible and useful.

Here is a comparison of some implementations that came up on a quick search: http://terrazadearavaca.blogspot.com/2008/12/jpa-implementations-comparison.html

You can use annotations with Hibernate as well. https://www.hibernate.org/397.html

Fly
Nov 3, 2002

moral compass

crazyfish posted:

You can use annotations with Hibernate as well. https://www.hibernate.org/397.html
I've not used Hibernate, but I was looking at it when I stumbled across JPA. I personally prefer the JPA API as it is a bit simpler. The specification documents from Sun are pretty good, too.

Colonel Taint
Mar 14, 2004


I'm trying to implement a basic message passing system for a class project. I have a bit of it set up, but it's not quite doing what I want it to do.

In a nutshell, the system involves an interface
code:
interface IMessageReceiver
{
  void receiveMessage(Message m);
}
Message being an abstract base class.

A message registry which passes messages and keeps a map of recipient IDs and their objects

Some of the relevant functions:
code:
class MessagePasser
{
    //I thought using generics and wildcards might help the issue, but I was wrong
    private HashMap<MessageReceiverID, ArrayList<? extends IMessageReceiver> > idMap;
    
    public <MType extends IMessageReceiver> MessageReceiverID addReceiver(MType  mr)
    {
	ArrayList<MType> mrArray = new ArrayList<MType>(1);
	mrArray.add(mr);
	MessageReceiverID newID = new MessageReceiverID();
	idMap.put(newID, mrArray);
	return newID;
    }
        
    public <MType extends Message> SendResult sendMessage(MType m)
    {
	if(m.recipient != null)
	{
	        Object receiver = idMap.get(m.recipient);
		if (receiver != null)
		{
			idMap.get(m.recipient).get(0).receiveMessage(m);
			return SendResult.OK;
		}
		else
	 	        return SendResult.INVALID_RECIPIENT;
	}
	else
		return SendResult.BAD_MESSAGE;
    }
}
Basically, I want to have a bunch of different Message Types and Message Receivers which deal with the messages based on their type.

I thought a good way to go about this would be to use an overridden receiveMessage method for each message type - i.e.

code:
class MyReceiver implements MessageReceiver
{
...
    void receiveMessage(JoinMessage m) {...}
    void receiveMessage(UpdateMessage m) {...}
    void receiveMessage(Message m) { ... } //for the abstract base class Message
    //This is the method that always gets called right now
}
The problem is, I want the message to be passed through a Message Passing object without having to make a passMessage method for every type of Message. Reason being, there are a lot of Message types.

So, I spent a good amount of time trying different things, most notably fighting with the generic syntax until I settled on putting the receiver in a single-element list.

Basically, I think I need to make the message passer aware of the receiver's full type, but I don't want to add a function for every type of receiver.

The only other thing I can think of would be testing the Message's type on the receiving end, which I know is possible, but would be nowhere near as nice as using a bunch of overridden functions. Does anyone know a way for that to be possible in this scenario?

I hope that's clear enough. I'm pretty tired from dealing with this.

zootm
Aug 8, 2006

We used to be better friends.

crazyfish posted:

You can use annotations with Hibernate as well. https://www.hibernate.org/397.html
More generally Hibernate is an implementation of JPA (and conversely JPA's annotations were based on the Hibernate ones). You don't need to choose between them. JPA is probably the best place to start, but you may find yourself needing more features, which is where you end up leaning on your implementation.

Adbot
ADBOT LOVES YOU

yatagan
Aug 31, 2009

by Ozma

SintaxError posted:

The only other thing I can think of would be testing the Message's type on the receiving end, which I know is possible, but would be nowhere near as nice as using a bunch of overridden functions. Does anyone know a way for that to be possible in this scenario?

Why do you think this? It's perfectly acceptable to check the types in a switch, and your interface pretty much demands it if you can't change that interface.

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