Since JDK 1.5 Properties can be loaded from a simple XML file (see IBM article). Is it possible to use XInclude in one of these XML properties files to compose multiple files?
I'm using a JTree to browse the content of a folder and I want that when a user click on a file, the software shows a preview of it (a screenshot of its first page).
The files are mostly Office documents and PDF.
I manage to do it for PDF file using a module downloaded from Sun, but I'd like to know if there is a way to do it using any software (JARs preferably) or even the built-in Windows API.
I was thinking of converting the file to PDF then do a preview of this PDF but this isn't optimal.
Any ideas ?
I have the following code to display a message :
JLabel A_Label=new JLabel("Updating channels ...");
A_Label.setFont(new Font("Times New Roman",0,16));
A_Label.setForeground(Color.BLUE);
A_Label.setHorizontalAlignment(SwingConstants.CENTER);
JOptionPane pane=new JOptionPane(A_Label);
Object[] options=new String[]{"OK"};
pane.setOptions(options);
JDialog dialog=pane.createDialog(new JFrame(),"Updating Channels");
dialog.setModal(false);
dialog.setVisible(true);
When the program runs, other windows displayed on top of it, how can I make it the top window ? I wonder if I can call "pane" or "dialog" to be on top ?
Frank
is there a way to get the top level container of a component? For example I have a JToolbar and I want to know at one monent the top level container of that JToolbar is my JFrame or is its own window, a JDialog.
Hi all.
Problem:
I have CaretListener and DocumentListener listening on a JTextPane.
I need an algorithm that is able to tell which line is the caret at in a JTextPane, here's an illustrative example:
Result: 3rd line
Result: 2nd line
Result: 4th line
and if the algorithm can tell which line the caret is in the JTextPane, it should be fairly easy to substring whatever that is in between the parentheses as the picture (caret is at character m of metadata):
--
This is how I divide the entire text that I retrieved from the JTextPane into sentences:
String[] lines = textPane.getText().split("\r?\n|\r", -1);
The sentences in the textPane is separated with \n.
Problem is, how can I manipulate the caret to let me know at which position and which line it is in? I know the dot of the caret says at which position it is, but I can't tell which line it is at. Assuming if I know which line the caret is, then I can just do lines[<line number>] and manipulate the string from there.
In Short: How do I use CaretListener and/or DocumentListener to know which line the caret is currently at, and retrieve the line for further string manipulation? Please help. Thanks.
Do let me know if further clarification is needed. Thanks for your time.
I'm using a JTree to browse the content of a folder and I want that when a user click on a file, the software shows a preview of it (like in the Windows Explorer).
I manage to do it for PDF file using a module downloaded from Sun, but I'd like to know if there is a way to do it using the built-in Windows API.
Here is a small currency converter piece of code:
public enum CurrencyType {
DOLLAR(1),
POUND(1.2),
RUPEE(.25);
private CurrencyType(double factor) {
this.factor = factor;
}
private double factor;
public double getFactor() {
return factor;
}
}
public class Currency {
public Currency(double value, CurrencyType type) {
this.value = value;
this.type = type;
}
private CurrencyType type;
private double value;
public CurrencyType getCurrencyType() {
return type;
}
public double getCurrencyValue() {
return value;
}
public void setCurrenctyValue(double value){
this.value = value;
}
}
public class CurrencyConversion {
public static Currency convert(Currency c1, Currency c2)
throws Exception {
if (c1 != null && c2 != null) {
c2.setCurrenctyValue(c1.getCurrencyValue()
* c1.getCurrencyType().getFactor()
* c2.getCurrencyType().getFactor());
return c2;
} else
throw new Exception();
}
}
I would like to improve this code to make it work for different units of conversion, for example: kgs to pounds, miles to kms, etc etc. Something that looks like this:
public class ConversionManager<T extends Convertible> {
public T convert(T c1, T c2)
{
//return null;
}
}
Appreciate your ideas and suggestions.
Hello there,
As you may know, res.sendRedirect(url) on the servlet side does not work because the GWT client does not process it.
Does anybody knows how to do this?
Thanks you.
Daniel
This is some sample code from an example. What I need to know is when call() gets called on the callable? What triggers it?
public class CallableExample {
public static class WordLengthCallable
implements Callable {
private String word;
public WordLengthCallable(String word) {
this.word = word;
}
public Integer call() {
return Integer.valueOf(word.length());
}
}
public static void main(String args[]) throws Exception {
ExecutorService pool = Executors.newFixedThreadPool(3);
Set<Future<Integer>> set = new HashSet<Future<Integer>>();
for (String word: args) {
Callable<Integer> callable = new WordLengthCallable(word);
Future<Integer> future = pool.submit(callable); //**DOES THIS CALL call()?**
set.add(future);
}
int sum = 0;
for (Future<Integer> future : set) {
sum += future.get();//**OR DOES THIS CALL call()?**
}
System.out.printf("The sum of lengths is %s%n", sum);
System.exit(sum);
}
}
I'm doing some large integer computing, and I need to raise a BigInteger to the power of another BigInteger. The .pow() method does what I want, but takes an int value as an argument. The .modPow method takes a BigInteger as an argument, but I do not want an answer congruent to the value I'm trying to compute.
My BigInteger exponent is too large to be represented as an int, can someone suggest a way to work around this limitation?
When I use a boolean method in the Main body, my program freezes and stops working. I've tried putting the method at different places but the exact same thing happens - it freezes.
The method is really simple and well-written, I'm not sure what's causing the problem.
P.S. The method is on the bottom of the code.
Thanks for your help!
Edit: That was a dumb question now that I look at it. Thanks again everyone!
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int stringNumber = 0;
String[] stringArray = new String[10];
for (int i = 0; i <= stringArray.length; i++) {
boolean itemExists = false;
boolean AddItem = AddItem();
if (AddItem == true) {
out.println("\nEnter a string");
String input = keyboard.next();
if (i > 0) {
for (int j = 0; j < stringArray.length; j++) {
if (input.equalsIgnoreCase(stringArray[j])) {
itemExists = true;
out.println("Item \"" + input + "\" already exists.");
break;
}
}
}
if (itemExists == false) {
stringArray[stringNumber] = input;
out.println("\"" + stringArray[stringNumber] + "\"" + " has been stored.\n");
} else {
out.println("Try again.");
i--;
}
PrintArray(stringArray);
stringNumber++;
}
}
}
// This is the method I was talking about //
public static boolean AddItem() {
Scanner keyboard = new Scanner(System.in);
int input = keyboard.nextInt();
out.println("If you want to add an item, Press 1");
if (input == 1) {
return true;
} else {
out.println("Invalid input.");
return false;
}
}
This subject is pretty often asked here and the Sun tutorial is too concise about the subject. So I thought, let's post a CW question and answer about this so that it can if necessary be referenced in other topics.
Others are of course free to add more hints and best practices here.
Is it bad to write:
if (b == false) //...
while (b != true) //...
Is it always better to instead write:
if (!b) //...
while (!b) //...
Presumably there is no difference in performance (or is there?), but how do you weigh the explicitness, the conciseness, the clarity, the readability, etc between the two?
Note: the variable name b is just used as an example, ala foo and bar.
Hi, all.
I've got a class, "Accumulator", that implements the Comparable compareTo method, and I'm trying to put these objects into a HashSet.
When I add() to the HashSet, I don't see any activity in my compareTo method in the debugger, regardless of where I set my breakpoints. Additionally, when I'm done with the add()s, I see several duplicates within the Set.
What am I screwing up, here; why is it not Comparing, and therefore, allowing the dupes?
Thanks,
IVR Avenger
Hi, I am working on some code were I need to add a Node into a doubly linked-list, this is the code I have so far:
Node tempNext = cursor.getNext();
temp = new Node(item, null, cursor, tempNext);
tempNext.setPrev(temp);
cursor is the Node that is right before the new added Node should go.
Hi.
Suppose that I have a method called doSomething() and I want to use this method in a multithreaded application (each servlet inherits from HttpServlet).I'm wondering if it is possible that a race condition will occur in the following cases:
doSomething() is not staic method and it writes values to a database.
doSomething() is static method but it does not write values to a database.
what I have noticed that many methods in my application may lead to a race condition or dirty read/write. for example , I have a Poll System , and for each voting operation, a certain method will change a single cell value for that poll as the following:
[poll_id | poll_data ]
[1 | {choice_1 : 10, choice_2 : 20}]
will the JSP/Servlets app solve these issues by itself, or I have to solve all that by myself?
Thanks..
If I have systems that are based on realtime data, how can I ensure that all the information that is current is redundantly stored in a file? So that when the program starts again, it uses this information to initialize itself back to where it was when it closed.
I know of xstream and HSQLDB. but wasn't sure if this was the best option for data that needs to be a literal carbon copy.
Hello,
I have a page that uses https and when i do a redirect from the bean that uses that https page to some http page. Then my session id changes. How can i stop this from happening? Please help me. Thanks in advance :)
We are working on a lab assignment for my CS&E class and I think I can ask this question without going into detail of the entire lab requirements, but is it possible for an array to be inside of an array? For example, would this work:
int [] arrayOne = new int[3];
arrayOne[0] = Start of an array
If this is possible how do you go about doing it?
Assume you have a small project which on the surface looks like a good match for an ETL tool like Talend.
But assume further, that you have never used Talend and furthermore, you do not trust "visual programming" tools in general and would rather code everything the old fashioned way (text on a nice IDE!) with the help of an appropriate language & support libraries.
What are some language patterns & support libraries that could help you stay away from the ETL tool temptation/trap?
I would like to write the following code:
boolean found = false;
search(new SearchCallback() {
@Override void onFound(Object o) { found = true; }
});
Obviously this is not allowed, since found needs to be final. I can't make found a member field for thread-safety reasons. What is the best alternative? One workaround is to define
final class MutableReference<T> {
private T value;
MutableReference(T value) { this.value = value; }
T get() { return value; }
void set(T value) { this.value = value; }
}
but this ends up taking a lot of space when formatted properly, and I'd rather not reinvent the wheel if at all possible. I could use a List<Boolean> with a single element (either mutating that element, or else emptying the list) or even a Boolean[1]. But everything seems to smell funny, since none of the options are being used as they were intended.
What is a reasonable way to do this?
Typically, I've seen people use the class literal like this:
Class<Foo> cls = Foo.class;
But what if the type is generic, e.g. List? This works fine, but has a warning since List should be parameterized:
Class<List> cls = List.class
So why not add a <?>? Well, this causes a type mismatch error:
Class<List<?>> cls = List.class
I figured something like this would work, but this is just a plain ol' a syntax error:
Class<List<Foo>> cls = List<Foo>.class
How can I get a Class<List<Foo>> statically, e.g. using the class literal?
I could use @SuppressWarnings("unchecked") to get rid of the warnings caused by the non-parameterized use of List in the first example, Class<List> cls = List.class, but I'd rather not.
Any suggestions?
Thanks!