Andrew Keidel

Greenhorn
+ Follow
since Dec 06, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Andrew Keidel

Hi! Below is my code (it's short) and the output/error I get. Any ideas wtf is going on???

CODE:
public void print() throws PrinterException {
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(this, this.pageFormat);
PrintRequestAttributeSet pset = new HashPrintRequestAttributeSet();
pset.add(new PrinterResolution(760, 1110, ResolutionSyntax.DPI));
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
DocAttributeSet aset = new HashDocAttributeSet();
PrintService[] pservices = PrintServiceLookup.lookupPrintServices(flavor, null);
for (int i = 0; i < pservices.length; i++) {
System.out.println(i + ": " + pservices[i].getName() + " |||| "
+ pservices[i].getSupportedDocFlavors() + " |||| "
+ pservices[i].hashCode());
}
PrintService pservice = pservices[1];
System.out.println("looked up service: " + pservice);
if (pservice != null) {
System.out.println("got service");
DocPrintJob pj = pservice.createPrintJob();
Doc doc = new SimpleDoc(this, flavor, aset);
try {
System.out.println("trying to print");
pj.print(doc, null);
} catch (Exception e) {
e.printStackTrace();
}
}
}

OUTPUT & ERROR:
0: \\regs\HP LaserJet 4050 Series PCL |||| [Ljavax.print.DocFlavor;@c791b9 |||| 1273058671
1: ZTC Z4M-200dpi |||| [Ljavax.print.DocFlavor;@b15692 |||| 775228905
2: Symantec Fax Starter Edition |||| [Ljavax.print.DocFlavor;@aa9f99 |||| -1486058539
3: HP LaserJet 1200 |||| [Ljavax.print.DocFlavor;@d42d08 |||| 1922980968
looked up service: Win32 Printer : ZTC Z4M-200dpi
got service
trying to print
java.lang.ArrayIndexOutOfBoundsException
at sun.print.Win32PrintService.getDefaultAttributeValue(Win32PrintService.java:786)
at sun.print.Win32PrintJob.printableJob(Win32PrintJob.java:413)
at sun.print.Win32PrintJob.print(Win32PrintJob.java:342)
at com.mixonic.admin.print.ShipLabel.print(ShipLabel.java:146)
21 years ago
Hi!
I have designed and implemented an administrative tool for handling generic orders, but it is performing poorly so I'm looking for suggestions.
I'm using BMP (and don't want to use CMP). I have an order entity bean (called OrderBean) that I use to hold a list of lists of orders (new orders are in one list, shipped orders in another list, canceled orders in a third). Each order is an object, but this order entity bean is used to hold in memory all orders at once.
When the OrderBean is loading up, it does one query to the database for all orders of a given status (eg, new orders) and then loops thru the ResultSet of orders and for each order, makes a call to another entity bean (called CustomerBean) from which it gets the customer info associated with that order.
The CustomerBean works the same way as the OrderBean.... it loads up all customers on its ejbLoad instead of just a single customer. Granted that uses lots of memory, but that's not a problem for the system, and the advantage (ideally) is that after the first load, all customers are cached and I don't have to hit the database again at all. IF, later on, a customer id comes up that is not in the CustomerBean's cached hashtable of customers, I redo the entire database load (effectively refreshing the cache) to get the new customer(s).
So maybe there are lots of problems with this design. Or maybe it's fairly standard for the purpose it serves. But I'm having issues... for one thing, on JBoss-3.0.2, for some reason the CustomerBean is getting ejbStored immediately after I get a customer from it. That means that if I have a list of 50 orders, and I loop thru that list to get the customer info for each order, I'm loading up the ENTIRE customer table from the database 50 times. That is SLOW and BAD. But using JBoss-2.4.4, the EJB container works differently and it only loads up the customers once, which makes it more efficient to have them all cached.
I suppose my question boils down to this: With lots of orders and customers (and potentially other objects), what is a very good way to design the administrative system to optimize performance?
Also, how can I control how often the EJB container calls ejbStore/ejbLoad? Can I control this at all?
Thanks!
Andy
Hi,
I'd like to run a background process in my company's ejb architecture to update entity beans periodically. For example, I'd like to update an entity bean with any new database table rows once every 10 minutes.
I've read that bean-managed threads are not supported in EJB, so how can I do this?
Thanks,
Andy
More specifically, I'm wondering about this code:
LinkedList list = <whatever>;
for (int i=0; i<list.length(); i++) {
list.get(i);
}
Is the above code linear? Or is it O(n^2)? In other words, for each call to get, is the LinkedList starting at the first element and moving through i elements? If it is, then it's O(n^2), which is bad.
If, on the other hand, the LinkedList object is smart enough to remember the last element that was referenced, it will always be in position for the next get call, and the code above will run in linear time.
I suppose the "preferred" way to write the code above is to use an Iterator object, which I'm sure is linear. Problem there is, if the linked list is modified as you go through the Iterator, you get an exception. I'd like to be able to have other threads modify the list as I go through it without synchronizing it. (I know that sounds odd, but please just assume there's a reason for it.)
Thanks for any help,
Andy
21 years ago
Also --
Perhaps I was using the scrollToReference(String) method incorrectly. It was protected, so I couldn't access it. So first I subclassed JEditorPane and overrode it with a *public* version that just calls super.scrollToReference(String).
So I'm actually using this subclassed version of JEditorPane. For the string argument, it's unclear to me what it should be. I'm currently using this:
jep.scrollToReference( "<a href=\"#top_marker\" target=\"_self\">" );
... and in the html I have an anchor right inside the <body> tag that is as follows:
<a name="top_marker">
So, is that right? I bet it isn't, but couldn't find the right way to do it.
- Andy
21 years ago
Hi Nate,
Thanks for the tips. They make sense and look like they should work, but they're not working for my application.
My JEditorPane is inside a JScrollPane. When I don't use the JScrollPane, the initial layout works even without the tips--except I can't scroll down.
Any ideas for how to get the JScrollPane to display from the top? (Currently it's still displaying the bottom of the html initially.)
Thanks again,
Andy
My code looks like this:
jep = new JEditorPane();
jep.setContentType(HTML_CONTENT_TYPE);
jsp = new JScrollPane(jep);
this.add(jsp, BorderLayout.CENTER);
...
jep.setText(sb.toString());
21 years ago
Hi all,
The code below shows what I think is a bug with TableLayout. The TableLayout class file--which is needed to try out the code given below--can be downloaded from here: http://java.sun.com/products/jfc/tsc/articles/tablelayout/Download.html
The problem is this: If you add a panel to a table layout in location (x1,y1), then remove it, and then add the same panel to location (x2,y2), it instead gets put back in location (x1,y1). Does anyone know a fix? Does anyone have suggestions?
After compiling the code below, run it in two ways. Type "java Gui" to run it and show the problem of re-adding a panel. Type "java Gui arg" to run it and show how if a panel not yet used is added, it goes in a different place from one that has been used.
Thanks,
Andy
CODE:
import javax.swing.*;
import java.awt.*;
import java.util.Vector;
import javax.swing.*;
// TableLayout stuff
import layout.*;
class Gui extends JPanel {
protected JPanel panel1, panel2, panel3, panel4;
protected double myLayout[][] = {{0.5, 0.5}, {0.5, 0.5}};
protected TableLayout tableLayout;
protected Gui() {
super();
tableLayout = new TableLayout(myLayout);
this.setLayout(tableLayout);
panel1 = new JPanel();
panel2 = new JPanel();
panel3 = new JPanel();
panel4 = new JPanel();
panel1.setBackground(new Color(200,0,0,255));
panel2.setBackground(new Color(0,200,0,255));
panel3.setBackground(new Color(0,0,200,255));
panel4.setBackground(new Color(150,150,0,255));
}
protected void render(int i, boolean flag) {
if (i == 0) {
this.add(panel1, "0,0,0,1");
this.add(panel2, "1,0");
this.add(panel3, "1,1");
}
else {
this.remove(panel1);
this.remove(panel2);
this.remove(panel3);
if (!flag) this.add(panel3, "0,0,1,1");
else this.add(panel4, "0,0,1,1");
}
this.repaint();
this.validate();
}
public static void main(String args[]) {
boolean flag = false;
if (args.length != 0) flag = true;
Gui gui = new Gui();
JFrame f = new JFrame();
f.getContentPane().add(gui);
f.setSize(640, 480);
f.setVisible(true);
for (int i=0; i<2; i++) {
try { Thread.sleep(1000); } catch (Exception e) { }
gui.render(i, flag);
}
}
}
[ May 12, 2002: Message edited by: Andrew Keidel ]
21 years ago
Hi,
I am writing an application with a gui that displays questions. It shows one question at a time--the user clicks through the test question-by-question. Each question is generated from XML into an html string (using my own code)... and then I put it all inside a JEditorPane which is inside a JScrollPane. Unfortunately, whenever I go to a question, the question window is scrolled all the way down to begin with. So instead of seeing the first part of the question, the user starts out seeing the end of the question and has to scroll up each time.
I am pretty clueless why this happens, although one guess is that it's due to the way I'm filling the content of the JEditorPane.
In any case, is there a simple method that can be called on the JEditorPane or the JScrollPane that will immediately put the user at the top of the question each time?
Thanks,
Andy
21 years ago
One more thing... Manfred and Cindy, sorry if I sounded rude before. I do greatly appreciate your input. I think I got a little surprised by the explanations and especially the use of the word "obvious." That's all.
Cheers,
Andy
21 years ago
An explicit example of the problem being discussed is given below. Compiling and running this will give a runtime error (NullPointerException).

class Base {
Base() {
doIt();
}
public void doIt() {
System.out.println("BASE");
}
}
public class Derived extends Base {
public Integer myInt;
public Derived() {
super();
myInt = new Integer(77);
}
public void doIt() {
System.out.println("DERIVED");
System.out.println(myInt.toString());
}
public static void main(String args[]) {
Derived d = new Derived();
}
}
21 years ago
Hi Dirk,
We are not mistaken.
The code you've provided is exactly my point. Sure, constructing a new Base works as we'd expect. The question was whether constructing a new Derived uses the doIt() method from Base or from Derived.
The initial explanations given in this thread said "new Derived()" used the doIt() method from Base. That is incorrect. In fact, it uses the doIt() method from Derived. The problem here is that if Derived has its own member variables that get initialized in its constructor and that are used by its doIt() method, we will be calling a method that incorrectly assumes it is using initialized variables.
21 years ago
Thanks, Geoffrey!
So, Manfred and Cindy, it seems that you are both mistaken. Indeed, the method of the derived class is called from the constructor of the base class!
Manfred, you should not state something as "OBVIOUS" unless it is both obvious *and* correct.
Below is sample code for proving that Java works as Geoffrey and I fear. I am still hoping that someone can explain this question: *WHY* DOES JAVA WORK THIS WAY? Manfred, I believe that Java perhaps ought to work the way you describe, and the way C++ works, but apparently it does not. And the article Geoffrey points out highlights the problems that can result from this peculiarity of the Java language.
SAMPLE CODE:
class Base {
Base() {
doIt();
}
public void doIt() {
System.out.println("BASE");
}
}
public class Derived extends Base {
public void doIt() {
System.out.println("DERIVED");
}
public static void main(String args[]) {
Derived d = new Derived();
}
}
21 years ago
Howdy!
I think this question is an interesting one.
Imagine this situation:
1. We have a class Base with public method makeReady().
2. Base calls makeReady() from within its constructor.
3. We make a class Derived that extends Base and overrides the makeReady() method.
My question is this: What happens when we try: "Derived d = new Derived();"? More specifically, when the constructor in Derived calls Base's constructor (which is always done because Base is its parent class), Base's constructor calls the makeReady() method... who's makeReady() method does it call?
If you think the answer is obviously that in this case, Derived's makeReady() method is called by Base's constructor, you may be right about the answer (I'm not sure), but you're wrong that it's obvious. In C++, the above scenario does NOT work this way. Instead, in C++, when Base's constructor is called through Derived's constructor, the virtual makeReady() method call in Base's constructor will use Base's own makeReady() method.
I don't understand why this happens in C++, and I don't know what happens in Java. It's easy enough to test this out with code, but what I'm more curious about is the REASON why each language works the way it does.
Here is a link to the C++ explanation, which I don't fully understand:
http://www.research.att.com/~bs/bs_faq2.html#vcall
Help, please! Thanks!
21 years ago
Howdy!
I think this question is an interesting one.
Imagine this situation:
1. We have a class Base with public method makeReady().
2. Base calls makeReady() from within its constructor.
3. We make a class Derived that extends Base and overrides the makeReady() method.
My question is this: What happens when we try: "Derived d = new Derived();"? More specifically, when the constructor in Derived calls Base's constructor (which is always done because Base is its parent class), Base's constructor calls the makeReady() method... who's makeReady() method does it call?
If you think the answer is obviously that in this case, Derived's makeReady() method is called by Base's constructor, you may be right about the answer (I'm not sure), but you're wrong that it's obvious. In C++, the above scenario does NOT work this way. Instead, in C++, when Base's constructor is called through Derived's constructor, the virtual makeReady() method call in Base's constructor will use Base's own makeReady() method.
I don't understand why this happens in C++, and I don't know what happens in Java. It's easy enough to test this out with code, but what I'm more curious about is the REASON why each language works the way it does.
Here is a link to the C++ explanation, which I don't fully understand:
http://www.research.att.com/~bs/bs_faq2.html#vcall
Help, please! Thanks!
21 years ago