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 ?
public static void ejemplosString(String palabra){
char[] letras = palabra.toCharArray();
int contadorVocales = 0;
for (int i = 0; i < letras.length; i++) {
if (char[i] == 'a') {
contadorVocales++;
}
if (char[i] == "e") {
contadorVocales++;
}
if (char[i] == "i") {
contadorVocales++;
}
if (char[i] == "o") {
contadorVocales++;
}
if (char[i] == "u") {
contadorVocales++;
}
}
}
Getting the error on every If statement. Any guidance?
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.
Is it possible in jax-ws to have a webmethod that creates a new object (of a service class)
and returns a reference to it to the client caller (for the client, it's a remote reference)
so that the client and this new service object maintain a session?
(Therefore each client is served by a different instance).
Schematically:
client server o:Session
-------- -------- ----------
s = server.access() ------------------>
o = new Session()
return o
<---
o.doSomething() ---------------------------------------------->
make it
<---
o.doMore() -------------------------------------------------->
make it
<---
I have attached a ModifyListener to a Combo box and it works fine. But how do I trigger it through source code? Is there a better way than this?:
int selected = myCombo.getSelectionIndex();
myCombo.select(selected + 1);
myCombo.select(selected);
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.
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?
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.
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);
}
}
Hi,
I need to learn C++ in order to learn building Nokia WRT and or maemo application.
I need to know what gotchas and what aspect of C++ that I need/have to learn or focus more.
One thing I got in my mind is that C++ doesn't have garbage collector. Therefor, I need to focus on variable type. But, is there any others that really important and I can't ignore it?
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.
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.
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.
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;
}
}
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
When i create a JCheckBox in my Swing application i leave some extra space after its label, so if the JCheckBox label is for example 100 pixels width, i make the JCheckBox 120 pixels for safety.
The problem as at runtime, it's not nice that a user can click on the empty space after the JCheckBox label and it can be actually clicked, like this :
I wonder if there is a way to resize the JCheckBox at runtime to exactly fit the text inside it, depending on the font type/size used ?
This seems fancy a bit, but i like to make things look perfect :)
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!
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 :)
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.
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'm able to rotate an image that has been added to a JLabel. The only problem is that if the height and width are not equal, the rotated image will no longer appear at the JLabel's origin (0,0).
Here's what I'm doing. I've also tried using AffineTransform and rotating the image itself, but with the same results.
Graphics2D g2d = (Graphics2D)g;
g2d.rotate(Math.toRadians(90), image.getWidth()/2, image.getHeight()/2);
super.paintComponent(g2d);
If I have an image whose width is greater than its height, rotating that image using this method and then painting it will result in the image being painted vertically above the point 0,0, and horizontally to the right of the point 0,0.