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
1337JiveTurkey
Feb 17, 2005

TRex EaterofCars posted:

I'm curious what that client's excuse for sticking with Java 1.3 is. Did they use some Sun internal API that got removed?

We only guarantee certain versions of our software against certain JVMs, and nobody wants to do the full testing process against 1.4.2 even though in principle it shouldn't break anything. Moving them up to a newer version would be tough since they've got lots of bugfixes by the custom development team (my group) which should have been backports by the core development team. Since there have been a huge number of bugfixes and tweaks in the years between releases, there's a lot of risk that the two sets of bugfixes would be incompatible. Since there's a major release that will break compatibility with most of our older code coming around the corner next week, the hope is that we can leapfrog the previous versions and go straight to Java 1.5. It's an improvement at least.

Adbot
ADBOT LOVES YOU

Foodchain
Oct 13, 2005

Edit2:

I've ran in to this and have given up for the night.
code:
         array[0] = new Employee();
         ((Employee)array[0]).fillEmployee(input.readLine());
         System.out.println(array[0]);
         array[1] = new Employee();
         ((Employee)array[1]).fillEmployee(input.readLine());
         System.out.println(array[1]);
         array[2] = new Employee();
         ((Employee)array[2]).fillEmployee(input.readLine());
         System.out.println(array[2]);         
         System.out.println(array[1]);
Stores the employee stuff in element 0, prints it fine. Stores another employee in element 1, prints it fine. Stores another employee in element 2, prints it fine. When it tries to print any element such as 1 or 0 it just prints the data from element 2. Why?

Here's the full code to this if it helps you help me:

http://www.undergallows.com/Employee.java
http://www.undergallows.com/Company.java


-- end of edit -- the rest is old stuff that I figured out

Hey guys. So I'm working on a java homework project and I've come to a stop because I can't quite figure something out.

Why does this work (wage is set correctly)

code:
private int employeeID;
private int hours;
private double payRate;
private double wage;
    
public void fillEmployee(String input) {
    StringTokenizer in = new StringTokenizer(input);
    employeeID = Integer.parseInt(in.nextToken());
    hours = Integer.parseInt(in.nextToken());
    payRate = Double.parseDouble(in.nextToken());
    wage = payRate*hours;
}

public void computeWage() {
   wage = (payRate*hours);
}
and this does not (wage is just getting set to 0.00)

code:
private int employeeID;
private int hours;
private double payRate;
private double wage;

public void fillEmployee(String input) {
    StringTokenizer in = new StringTokenizer(input);
    employeeID = Integer.parseInt(in.nextToken());
    hours = Integer.parseInt(in.nextToken());
    payRate = Double.parseDouble(in.nextToken());
   // wage = payRate*hours;
}

public void computeWage() {
   wage = (payRate*hours);
}
I keep looking at it, and I just don't get it. It's probably some small newbie coder mistake that I'm missing here. I don't understand why I can set the wage from the fillEmployee method, but I can't set it from the computeWage method.

Edit: A little more thought and I solved my problem. I wasn't calling the computeWage method anywhere v:shobon:v I'm a terrible terrible programmer

Foodchain fucked around with this message at 07:00 on Mar 24, 2008

FearIt
Mar 11, 2007
How do I pass objects to a method in another class so that when I manipulate the values in the method the original object isn't modified?

My example code would be far too long to post but it's basically something like:

ObjectA A = new ObjectA(blah, blah blah);
ObjectB B = new ObjectB();
int crazyCalculations = B.doSomeCalculationsWithA(A);

Is there a quick way to make it so the original A won't be changed by B's method?
Hopefully some sort of way that won't make me rewrite all my methods completely but simply just kinda add a keyword or something..

tef
May 30, 2004

-> some l-system crap ->
X.clone() creates a copy of the object, and you can pass it to your destructive methods.

FearIt
Mar 11, 2007
I'm typing 'objectsName.' in my IDE (eclipse) and when the list of methods comes up none of them are clone(). The object is a class I defined myself, would I need it to implement something for .clone() to work? Or alter my class in someway?

F'Nog
Jul 21, 2001

FearIt posted:

I'm typing 'objectsName.' in my IDE (eclipse) and when the list of methods comes up none of them are clone(). The object is a class I defined myself, would I need it to implement something for .clone() to work? Or alter my class in someway?

clone() is protected in Object, you need to open it up yourself in the class you want to clone.

1337JiveTurkey
Feb 17, 2005

FearIt posted:

I'm typing 'objectsName.' in my IDE (eclipse) and when the list of methods comes up none of them are clone(). The object is a class I defined myself, would I need it to implement something for .clone() to work? Or alter my class in someway?

You want to implement the java.lang.Cloneable interface. That's enough to clone() an object without any work on your part. Many people dislike it because they feel that it allows you to gloss over the implications of clone() with regards to how your objects behave. In particular a shallow copy of the fields might not be what you wanted. There are a couple of alternatives which work: Creating a constructor which takes another instance of the object (or even an implemented interface) offers you the chance to make it a deep copy if you want to as well as share any immutable data. Immutable objects are also a possible alternative. If you're not constantly modifying a class of objects, you can get around all of that by just creating a new object for every change. Immutable objects work well with each other because any two objects can share a third object without needing to worry if the third object will change underneath them. This reduces memory usage requirements and makes it easier to turn other objects immutable if all of their fields are immutable.

FearIt
Mar 11, 2007
I like this constructor idea, it seems to be the neatest codewise and would require the least amount of revision of my broken code. In the constructor how would I go about creating a copy if everything is passed by reference still? Is it more complicated if my class serves as a ArrayList container for sub classes?

the onion wizard
Apr 14, 2004

FearIt posted:

Is it more complicated if my class serves as a ArrayList container for sub classes?

Probably; as you'll need to manually copy any data you require in the copy-contructor.

If you're not concerned with performance you could use the apache commons SerializationUtils; as mentioned in the javadoc, all objects you want cloned must implement Serializable (which ArrayList implements already).




vvv I agree 100%, I was considering adding a disclaimer to that effect. vvv

the onion wizard fucked around with this message at 22:51 on Mar 25, 2008

Brain Candy
May 18, 2006

triplekungfu posted:

If you're not concerned with performance you could use the apache commons SerializationUtils; as mentioned in the javadoc, all objects you want cloned must implement Serializable (which ArrayList implements already).

Use it if you aren't concerned about good programming or sanity either. This seems like a horrible abuse of Serialization, which is supposed be about passing objects across a network. ArrayList also has a copy-constructor so if the data is immutable its very easy, otherwise use foreach loops. Manually copying data from one instance to another is not going to be that bad.

There is an problem with marker interfaces (interfaces that don't actually require methods, including Cloneable and Serializable) in that you can't get rid of them in subclasses.

1337JiveTurkey posted:

Immutable objects are also a possible alternative. If you're not constantly modifying a class of objects, you can get around all of that by just creating a new object for every change. Immutable objects work well with each other because any two objects can share a third object without needing to worry if the third object will change underneath them. This reduces memory usage requirements and makes it easier to turn other objects immutable if all of their fields are immutable.

Immutable objects definitely nice for many things, but they come at a price. Strings, for example are immutable and the JVM does all sorts of optimization with them. But you'll also notice that there are special helper classes, StringBuilder and StringBuffer, just to create new Strings. In general, every time you change an immutable field you have to create a new object.

Brain Candy fucked around with this message at 12:05 on Mar 25, 2008

zootm
Aug 8, 2006

We used to be better friends.

Brain Candy posted:

Immutable objects definitely nice for many things, but they come at a price. Strings, for example are immutable and the JVM does all sorts of optimization with them. But you'll also notice that there are special helper classes, StringBuilder and StringBuffer, just to create new Strings. In general, every time you change an immutable field you have to create a new object.
On the other hand, so long as you make properly immutable objects they're pretty cheap in comparison to normal objects for the JVM; their behaviour in the garbage collector is much more favourable since they stay in the "young" generation and are readily collected.

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
What is the best way to go about parsing XML in Java? I've been going about rewriting a project I have written, and it uses the org.w3c.dom.* classes to do so. This was mainly because I found information on it, but with all things Java it seems like there is a lot of outdated information out there. Basically, whats the best API for doing this, since any way I can simplify the code for this project would be extremely helpful.

zootm
Aug 8, 2006

We used to be better friends.
It entirely depends on what you want to do, and what your requirements are. Java has support for pretty much every method of parsing XML out there.

DOM allows you to traverse and manipulate an XML document as an object representing its structure.
SAX and StAX are stream parsers which scale well but essentially mean you have to maintain any state that you need yourself. StAX is a more modern "pull" parser which is a lot easier to use.
JAXB allows you to bind structured XML documents to and from corresponding basic "bean" objects automatically.
XPath allows you to query a loaded XML document for a given "path" allowing you to quickly query parts of the document.

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

zootm posted:

It entirely depends on what you want to do, and what your requirements are. Java has support for pretty much every method of parsing XML out there.

DOM allows you to traverse and manipulate an XML document as an object representing its structure.
SAX and StAX are stream parsers which scale well but essentially mean you have to maintain any state that you need yourself. StAX is a more modern "pull" parser which is a lot easier to use.
JAXB allows you to bind structured XML documents to and from corresponding basic "bean" objects automatically.
XPath allows you to query a loaded XML document for a given "path" allowing you to quickly query parts of the document.

Thanks for the information. This really helps me out, since I have been having difficulties locating the information I needed. It looks like I will be sticking with DOM, since my documents will never be excessively large and I am going to be parsing the XML generated from a program that makes a simple task extremely difficult due to it creating two separate nodes that contain slightly overlapping information by using reference IDs to identify the correlation.

tef
May 30, 2004

-> some l-system crap ->
If you are just rewriting the output of a program from xml to xml, there are other options like xpath+xsl.

Although xsl is pretty useful it can be quite awkward being declarative.

Red Oktober
May 24, 2006

wiggly eyes!



I'm horribly confused with Calendar objects in java.

At the minute I'm parsing a file off the internet which has a couple of fields like:
"2/6/2008","4:00pm" to represent times.

I think pick these out into a set of fields, year, month, day, hour and minutes with a parser.

I get a new instance of Calendar. (calendar = calendar.getCalendar());

clear it (calendar.clear())

and set it

calendar.set(year, month, day, hour, minutes);

However, when I attempt to get the millisecond value, it appears to be wrong by about a month.

To check I used the calendar.toString(); method, and got this:

java.util.GregorianCalendar[time=1209221820000,areFieldsSet=true,areAllFieldsSet=false,
lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/London",offset=0,dstSavings=3600000,
useDaylight=true,transitions=242,lastRule=java.util.SimpleTimeZone[id=Europe/London,offset=0
,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,
ERA=?,YEAR=2008,MONTH=3,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DAY_OF_MONTH=26,DAY_OF_YEAR=?,DAY_OF_WEEK=?,DAY_OF_WEEK_IN_MONTH=?,AM_PM=?,HOUR=?,HOUR_OF_DAY=15,MINUTE=57,SECOND=?,MILLISECOND=?,ZONE_OFFSET=?,DST_OFFSET=?]

1209221820000 as a millisecond time is Sat, 26 Apr 2008 14:57:00 GMT, but the toString method also gives the correct time, the 26th of March 2008 at 15:57 GMT.

I'm sure I can solve the hour (BST or DST or something) but the entire month off is stumping me.

Any have any ideas?

10011
Jul 22, 2007
January is month zero, so you'll need to subtract one from the months before setting the calendar.

Anphear
Jan 20, 2008
So I have a minor test tomorrow that require me to write a memorised piece of code in 25 minutes, which I'm finishing now. How ever I cannot for the life of me remember how to get my dam scanner class working. NB programming is not my strong point, which leads me to missing out the most simple things...

Code;
code:
package lab08;
import java.util.Scanner;
public class TestApp{
  public static void main (String[] args){
    NumberList n = new NumberList(10);
    Scanner s = new Scanner(System.in);
    n.add(s.nextInt);
    
    if(!n.isEmpty()){
     System.out.println("The average is " + n.calcAverage());
    }
     System.out.println(n.toString());    
  }
  public static int readInt(String message){
    Scanner sc =  new Scanner(System.in);
    return sc.nextInt();
  }
}
The problem that I'm currently having is the scanner class isn't 'working right' and that my array remains empty. With the toString method simply printing [] and if I remove the isEmpty() method I get a NaN return.
code:
package lab08;
public class NumberList{
  
  private int[] nList;
  private int count = 0;
  public NumberList(int maxsize){
    nList=new int[maxsize];   
    
  }
  public void add(int item){
    if(count < nList.length){  
      nList[count]=item;
      count++;      
    }
  }
[i]rest of class[/i]
Heres the add array method.

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

tef posted:

If you are just rewriting the output of a program from xml to xml, there are other options like xpath+xsl.

Although xsl is pretty useful it can be quite awkward being declarative.

I'm not sure, the way this works is fairly obtuse, such as
code:
<part1>
 <element id="123">
    <attribute></attribute>
    <link id="456" />
 </element>
 <links>
   <link idref="456" name="junk" />
 </links>
</part1>
<part2>
 <element idref="123">
   <samefuckingattributewithextrainfo>
      <whyisntthisabove />
   </samefuckingattributewithextrainfo>
 </element>
</part2>
obviously there can be more elements, but it's driving me nuts.

Red Oktober
May 24, 2006

wiggly eyes!



10011 posted:

January is month zero, so you'll need to subtract one from the months before setting the calendar.

:facepalm:

I've spent far too long looking at this, thank you!

the onion wizard
Apr 14, 2004

Anphear posted:

The problem that I'm currently having is the scanner class isn't 'working right' and that my array remains empty. With the toString method simply printing [] and if I remove the isEmpty() method I get a NaN return.

First, you're only ever reading in one number. To read in more than one number you'll need to loop on the input. Something like this:
code:
while (s.hasNextInt()) {
    n.add(s.nextInt());
}
Can you post calcAverage() and toString() from NumberList? Edit: or the whole thing if it's not too long.

Anphear posted:

code:
  public static int readInt(String message){
    Scanner sc =  new Scanner(System.in);
    return sc.nextInt();
  }
What's this method for?

Edit: I'm going to bed, but I wrote this while looking at Scanner; it might help, or it may just confuse matters further.

the onion wizard fucked around with this message at 14:44 on Mar 27, 2008

tef
May 30, 2004

-> some l-system crap ->

CRIP EATIN BREAD posted:

I'm not sure, the way this works is fairly obtuse, such as
...
obviously there can be more elements, but it's driving me nuts.

What is it meant to look like in the output? If you can paste them into a paste bin I can either knock up an xsl attempt or tell you it's impossible.

Anphear
Jan 20, 2008

triplekungfu posted:

code:
while (s.hasNextInt()) {
    n.add(s.nextInt());
}
What's this method for?
Edit: I'm going to bed, but I wrote this while looking at Scanner; it might help, or it may just confuse matters further.

Thanks Triple, With the while loop and a pastbin code I got mine working. Also when I visually compared, my getAv and add methods they were pretty much the same.

Fehler
Dec 14, 2004

.
I'm working on my first Java GUI application with SWT right now, so please excuse the presumably stupid questions.

1) I need to create dialogs from a thread and handle the return values. I think I can use Display.getDefault().syncExec(new Runnable() {...}); for that, but how would I get the dialog's return value from the Runnable?

2) Are there premade functions for displaying dialogs and message boxes or do I have to write them myself?

3) Would users just need the JRE to run my program or does SWT require additional software to be installed?

Kerris
Jul 12, 2006
Don't you fucking dare compliment a woman's voice on the forums, you fucking creepy stalker.
2) The JOptionPane class should be what you want. [link]

3) The users will just need the JRE to run your program. SWT does not require additional software to be installed.

Fehler
Dec 14, 2004

.
Thanks, but I thought Swing and SWT were different things. Can I actually use Swing classes together with SWT?

zootm
Aug 8, 2006

We used to be better friends.

Fehler posted:

Thanks, but I thought Swing and SWT were different things. Can I actually use Swing classes together with SWT?
They are, I think Kerris is a little confused. I wouldn't advise using both SWT and Swing in one program, but I've not too much experience with SWT so don't know what class you want for doing that form of popup.

As regards the SWT-and-extra-software thing, SWT does require extra stuff to be bundled per-platform since it has native components. Swing does not because it comes with the JRE.

Kerris
Jul 12, 2006
Don't you fucking dare compliment a woman's voice on the forums, you fucking creepy stalker.
Aw crumbs, sorry abut it Fehler, I shouldn't have skimmed your post. zootm is correct.

Fehler
Dec 14, 2004

.
It seems like the whole bundling of native software for SWT would be a bit annoying, so do you think I should just move to Swing? It's not like I put much thought into what to use when I started...

Are there any good Swing tutorials out there that explain the basics for somebody who knows nothing about Java GUIs?

Also, is it correct that Swing is the one with that ugly blue-silverish GUI? Any way around that?

zootm
Aug 8, 2006

We used to be better friends.

Fehler posted:

It seems like the whole bundling of native software for SWT would be a bit annoying, so do you think I should just move to Swing? It's not like I put much thought into what to use when I started...
Use both and see which one you like. I don't think packaging it is too hard, but if you use custom controls sometimes that can be a pain.

Fehler posted:

Are there any good Swing tutorials out there that explain the basics for somebody who knows nothing about Java GUIs?
I'm afraid not, but Netbeans has a GUI designer for Swing and I'm pretty sure there's a bunch of tutorials on its site.

Fehler posted:

Also, is it correct that Swing is the one with that ugly blue-silverish GUI? Any way around that?
Yes, but it also has a native look-and-feel for Windows, OS X, and GTK+ (Linux), you can turn it on programmatically. The blue thing is just guaranteed to work on all platforms (I think it's been replaced with something marginally nicer recently, too).

oh no computer
May 27, 2003

Fehler posted:

Also, is it correct that Swing is the one with that ugly blue-silverish GUI? Any way around that?
That's the "Motif" look and feel. You can change the look and feel of Swing to whichever suits you best. If you go to your java folder and go to /demo/jfc/swingset2 you can run an applet that shows you some look and feel examples, although there are more than that available.

Edit: beaten

epswing
Nov 4, 2003

Soiled Meat
The scenario: MyApp (console application) would like to run another program (SomeProgram, but this can really be any program which works with stdin and cmd-line args) in a new console window. My current platform is Windows XP and java version "1.6.0_03".

MyApp uses Runtime.getRuntime().exec to launch the other program. Assuming the other program is a java program SomeProgram, I'd want to execute the command "cmd /C java SomeProgram arg1 arg2 arg3", send some stdin data, and this works great with my current code. To launch the other program in a new console window, I'd want to execute the command "cmd /C start java SomeProgram", note the 'start'. You can try this yourself by opening a console and typing "cmd /C start echo hi there" or "cmd /C start pause".

The trouble is, when using cmd's "start", the stdin I send never makes it to the launched program.

Save the following to MyApp.java
code:
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;

public class MyApp {
	
	public static final String newline = System.getProperty("line.separator");
	
	public static void main(String[] args) throws Exception {
		
		// works:
		String[] command = { "cmd", "/C", "java", "SomeProgram", "arg1", "arg2", "arg3" };
		
		// doesn't work:
		//String[] command = { "cmd", "/C", "start", "java", "SomeProgram", "arg1", "arg2", "arg3" };
		
		File path = new File(".");
		
		StringBuffer stdin = new StringBuffer();
		stdin.append("hey here are some lines" + MyApp.newline);
		stdin.append("that should be coming in on stdin" + MyApp.newline);
		stdin.append("" + MyApp.newline);
		stdin.append("empty line above me" + MyApp.newline);
		stdin.append("ok we're done" + MyApp.newline);
		
		System.out.println("executing process");
		Process process = Runtime.getRuntime().exec(command, null, path);
		
		System.out.println("sending stdin");
		InputStream in = new ByteArrayInputStream(stdin.toString().getBytes());
		OutputStream out = process.getOutputStream();
		int len = 32;
		int count = 0;
		byte[] buffer = new byte[len];
		while ((count = in.read(buffer, 0, len)) != -1)
			out.write(buffer, 0, count);
		out.close();
		in.close();
		
		System.out.println("collecting stdout and stderr");
		StringBuffer stdout = new StringBuffer();
		StringBuffer stderr = new StringBuffer();
		StreamGobbler.newStreamGobbler(process.getInputStream(), stdout);
		StreamGobbler.newStreamGobbler(process.getErrorStream(), stderr);
		
		System.out.println("waiting for process to finish");
		process.waitFor();
		
		System.out.println("process finished");
		System.out.println("stdout: [" + stdout.toString() + "]");
		System.out.println("stderr: [" + stderr.toString() + "]");
	}
	
}

/**
 * A quick class to empty out the stdout/stderr streams of a running process,
 * appending them to a StringBuffer.
 */
class StreamGobbler extends Thread {
	
	public static StreamGobbler newStreamGobbler(InputStream input, StringBuffer output) {
		StreamGobbler s = new StreamGobbler(input, output);
		s.start();
		return s;
	}
	
	private InputStream input;
	private StringBuffer output;
	
	private StreamGobbler(InputStream input, StringBuffer output) {
		this.input = input;
		this.output = output;
	}
	
	public void run() {
		try {
			InputStreamReader isr = new InputStreamReader(input);
			BufferedReader br = new BufferedReader(isr);
			String line = null;
			while ((line = br.readLine()) != null)
				output.append(line + MyApp.newline);
			br.close();
			isr.close();
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}
}
Save the following to SomeProgram.java
code:
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class SomeProgram {
	
	public static void main(String[] args) throws Exception {
		
		System.out.println("Command-line arguments:");
		for (String arg : args)
			System.out.println("\t" + arg);
		
		System.out.println();
		
		System.out.println("Standard in:");
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		while ((line = br.readLine()) != null)
			System.out.println("\t" + line);
	}
}
Simply compile both java files and run "java MyApp" to see it in action. To see where I'm having trouble, comment/uncomment the two versions of String[] command near the top of MyApp.java.

SomeProgram could really be any program that deals with stdin. I happen to be launching TCL scripts, so my command looks more like "cmd /C start tclsh SomeScript.tcl arg1 arg2 arg3".

Any other comments would be appreciated, for example I'm not sure if I need to be sending stdin like I am, considering it'll always be string data.

Edit: What I'm suspecting is that "start" is cockblocking the program I wish to execute out of the stdin I want to pass it. There's no way to pass the stdin through start?

epswing fucked around with this message at 15:41 on Apr 2, 2008

zootm
Aug 8, 2006

We used to be better friends.
"start" ignores input. Your Java code is working fine, but start spawns and starts a new console window for you and that's all it does.

What is it you're trying to do? There's bound to be a better way to do this?

epswing
Nov 4, 2003

Soiled Meat

zootm posted:

"start" ignores input. Your Java code is working fine, but start spawns and starts a new console window for you and that's all it does.

What is it you're trying to do? There's bound to be a better way to do this?

In short (really short), MyApp is a server which schedules and launches scripts. MyApp, among other places, logs to the console, so it would be nice to pop up a new console window to allow visual monitoring of currently-executing scripts without polluting the main console window.

One solution would be to launch a JFrame with the process and dump stdout/stderr to a textarea as it rolls out. I didn't want to use Swing in this piece of my puzzle, but it would probably work well, now that I think about it.

I'm betting I could make the JFrame look pretty close to a real console too...

zootm
Aug 8, 2006

We used to be better friends.
That would be a better idea, yeah. If you could invoke something like tail -f (I realise that's not a Windows program) it'd also follow the output of a log file.

If you're just wanting to catch logging, however, use a standard logging toolkit like log4j or java.util.logging or Commons Logging or whatever and write a log "target" for that which just outputs the logging information to a window or whatever you like. There's no good reason not to use "proper" logging and doing this right will give you a lot more freedom if this is important to you. Popping up an "echo" window natively doesn't seem like a good solution.

zootm fucked around with this message at 17:45 on Apr 2, 2008

epswing
Nov 4, 2003

Soiled Meat

zootm posted:

If you're just wanting to catch logging, however, use a standard logging toolkit like log4j or java.util.logging or Commons Logging or whatever and...

Yep, I'm using log4j extensively, this is just to present the user with some visual feedback that what MyApp is running is actually running.

zootm
Aug 8, 2006

We used to be better friends.

epswing posted:

Yep, I'm using log4j extensively, this is just to present the user with some visual feedback that what MyApp is running is actually running.
You don't need to capture stderr or stdout then, surely? Just capture the logging information directly and display it in whatever component you want.

epswing
Nov 4, 2003

Soiled Meat
What do you mean by "Just capture the logging information directly"? I'm spawning a process, how else do you propose I capture it's stdout/err?

zootm
Aug 8, 2006

We used to be better friends.

epswing posted:

What do you mean by "Just capture the logging information directly"? I'm spawning a process, how else do you propose I capture it's stdout/err?

Ah, I had thought you were running it in the same JVM, presumably you've a reason for not doing so. Just capture in and out, yeah.

Adbot
ADBOT LOVES YOU

Edmond Dantes
Sep 12, 2007

Reactor: Online
Sensors: Online
Weapons: Online

ALL SYSTEMS NOMINAL
Ok, let's see if I can actually phrase this question...

I have 3 comboboxes, each of them with the same options, let's say they're "name", "surname", "address", "age", "country".

Now, I need those 3 boxes to filter each other out. For example, if on the first combo box I choose "name", the second and third should not display the "name" option, and so on.

Any ideas?

Thanks.

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