i am triying to write a web based proxy site on google app engine.Displaying the first page of entered url was fairly simple urlFetching api but i am unable to figure out how to proxify the links and requests origionating from this newly displayed page.
I am aware that you can initialize an array during instantiation as follows:
String[] names = new String[] {"Ryan", "Julie", "Bob"};
Is there a way to do the same thing with an ArrayList? Or must I add the contents individually with array.add()?
Thanks,
Jonathan
Some swing code I write in my computer behave different on my colleague's computer, and in my PC, and in my notebook.
I wonder, is there something I can do to my Swing applications behave the same in every computer?
I want to have sure a algorithm I've tested in my computer will work the same way in my clients computers.
E.g.
Problem to focus JTextField
I'm trying to build a GUI window in my application. What I'm trying to do is have a window, with a few buttons at the top, and a large text area. Something like this:
+--------------------------------------------------+
| [button1] [button2] [button3] |
| +----------------------------------------------+ |
| | text area | |
| | | |
| | | |
| | | |
| +----------------------------------------------+ |
+--------------------------------------------------+
I'm almost there, using GroupLayout:
layout.setHorizontalGroup(
layout.createParallelGroup()
.addGroup(layout.createSequentialGroup()
.addComponent(button1)
.addComponent(button2))
.addComponent(closeWindow))
.addComponent(textarea1)
);
layout.setVerticalGroup(
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup()
.addComponent(button1)
.addComponent(button2)
.addComponent(button3))
.addComponent(textarea)
);
The problem is that this ends up with button3 aligned to the left, with the other two. I can't seem to figure out how I can specify the alignment on just that one button. I can do GroupLayout.Alignment.TRAILING on the entire button bar, but that hits all 3 buttons, which is also not quite right.
So what's the correct approach? Since the alignment only applies for Parallel Groups, I don't think having a HorizontalGroup with two Sequential Groups in it will help?
What am I missing?
Hi,
I am creating some multi-threaded code, and I have created a JobDispatcher class that creates threads. I want this object to handle any unhandled exceptions in the worker threads, and so I am using
Thread.setUncaughtExceptionHandler(this);
Now, I would like to test this functionality - how can I generate an unhandled exception in the run() method of my worker object?
Thanks,
Martin
for my application I have to build a little customized time ticker which ticks over after whatever delay I tell it to and writes the new value in my textArea. The problem is that the ticker is running fully until the termination time and then printing all the values. How can I make the text area change while the code is running.
while(tick<terminationTime){
if ((System.currentTimeMillis()) > (msNow + delay)){
msNow = System.currentTimeMillis();
tick = tick + 1;
currentTime.setText(""+tick);
sourceTextArea.append(""+tick+" " + System.currentTimeMillis() +" \n");
}
currentTime and sourceTextArea are both text areas and both are getting updated after the while loop ends.
I appreciate that anything that can be done done by a switch statment can be done by an if else statement.
But are there stylistic rules for when one should use the switch rather than if else statment.
public class PriorityQueue<T> {
private PriorityNode<T> head, tail;
private int numItems;
public PriorityQueue(){
numItems = 0;
head=null;
tail=null;
}
public void add(int priority, T value){
PriorityNode<T> newNode = new PriorityNode<T>(priority,value);
if(numItems == 0){
head = newNode;
tail = newNode;
}
else{
head.setNext(newNode);
head = newNode;
}
}
}
Where PriorityNode is defined as:
public class PriorityNode<T> implements Comparable<T> {
private T value;
private PriorityNode<T> next;
private int priority;
public PriorityNode(int priority,T newValue){
value = newValue;
next = null;
priority = 0;
}
public PriorityNode(T newValue){
value = newValue;
next = null;
priority = 0;
}
public void setPriority(int priority){
this.priority = priority;
}
public int getPriority(){
return this.priority;
}
public T getValue(){
return value;
}
public PriorityNode<T> getNext(){
return next;
}
public void setNext(PriorityNode<T> nextNode){
this.next = nextNode;
}
public void setValue(T newValue){
value = newValue;
}
public int compareTo(int pri) {
// TODO Auto-generated method stub
if(this.priority<pri){
return -1;
}
else if(this.priority == pri){
return 0;
}
else{
return 1;
}
}
}
I'm having a lot of difficulty using the Comparator here and implementing a priority queue - please point me in the right direction.
Assign the following 25 scores to a one dimensional int array called "temp"
34,24,78,65,45,100,90,97,56,89,78,98,74,90,98,24,45,76,89,54,12,20,22,55,66
Move the scores to a 2 dimensional int array called "scores" row wise
-- meaning the first 5 scores go into row 0 etc
Rather new to REST and Jersey, and I'm trying out some basic examples. I've got one particular question though, which I haven't really found an answer for yet (don't really know how to look for this): how would you go about storing/defining common services so that they are stateful and accessible to all/some resources?
For instance, a logger instance (Log4J or whatever). Do I have to manually initialize this and store it in the HttpSession? Is there a "best practice" way of doing this so that my logger is accessible to all/some resources?
Thanks a lot.
I'm curious why the String.indexOf is returning a 0 (instead of -1) when asking for the index of an empty string within a string.
The Javadocs only say this method returns the index in this String of the specified string, -1 if the string isn't found.
System.out.println("FOO".indexOf("")); // outputs 0 wtf!!!
System.out.println("FOO".indexOf("bar")); // outputs -1 as expected
System.out.println("FOO".indexOf("F")); // outputs 0 as expected
System.out.println("".indexOf("")); // outputs 0 as expected, I think
Hello!
I'm referring to this Nimbus reference.
I tried to set global Font to be slightly larger:
UIManager.put("defaultFont", new Font(Font.SANS_SERIF, 0, 16));
...works only for the menu but nothing else (buttons, labels).
I tried to change labels and buttons fonts with
UIManager.put("Button.font", new Font(Font.SANS_SERIF, 0, 16));
UIManager.put("Label.font", new Font(Font.SANS_SERIF, 0, 16));
but the font remains.
The only thing that worked for me was deriving a font:
someButton.setFont(someButton.getFont().deriveFont(16f));
But this is not an option, since this must be done for each
element manually.
Note, that deriving a font for UIManager doesn't work either:
UIManager.put("Label.font",
UIManager.getFont("Label.font").deriveFont(16f));
I tested everything under Linux and Windows: same behavior.
I just can't understand how an API can be so messy. If a method is called
setFont(..) then I expect it to set the font. If this method fails to
set the font in any thinkable circumstances, then it should be deprecated.
EDIT:
The problem not only applies to Nimbus, but also to the default LAF.
how are static method calls handled by the JVM? does it still allocate memory when a call is made? if yes, how does garbage collection treat this allocation after the method call?
I am trying to get the ip of a socket connection in string form.
I am using a framework, which returns the SocketAddress of the recieved message. How can i transform it to InetSocketAddress or InetAddress?
public abstract class Master
{
public void printForAllMethodsInSubClass()
{
System.out.println ("Printing before subclass method executes");
}
}
public class Owner extends Master {
public void printSomething () {
System.out.println ("This printed from Owner");
}
public int returnSomeCals ()
{
return 5+5;
}
}
Without messing with methods of subclass...is it possible to execute printForAllMethodsInSubClass() before the method of a subclass gets executed?
The toArray method in ArrayList , Bloch uses both System.arraycopy and Arrays.copyOf to copy an array .
public <T> T[] toArray(T[] a) {
if (a.length < size)
// Make a new array of a's runtime type, but my contents:
return (T[]) Arrays.copyOf(elementData, size, a.getClass());
System.arraycopy(elementData, 0, a, 0, size);
if (a.length > size)
a[size] = null;
return a;
}
How to compare these two copy method , when to use which ? Thanks.
board image
the above is a board layout done by using gridbaglayout.
i would like insets of 5 pixels around the whole board but not between each label.
i scaned the api and havent come up with something that lets me do this.
does this mean i have to nest my board gui inside another gridbaglayout with the insets desired?
thank you.
Is there a way to set DPI in swing ? For the whole application ? And if there is how do I set it to the value of system DPI ?
I guess there must be a way to do it as I mentioned this feature must have benn added to NetBeans in some of latest versions...
Thank you for reading
Hey,
I have something like the following
TestObjectCreator{
private static Person person;
private static Company company;
static {
person = new Person()
person.setName("Joe");
company = new Company();
company.setName("Apple");
}
public Person createTestPerson(){
return person;
}
public Person createTestCompany(){
return company;
}
}
By applying static{} what am I gaining? I assume the objects are singletons as a result. However, if I did the following:
Person person = TestObjectCreator.createTestPerson();
person.setName("Jill");
Person person2 = TestObjectCreator.createTestPerson();
would person2 be named Jill or Joe?
Is there any difference in efficiency (e.g. execution time, code size, etc.) between these two ways of doing things?
Below are contrived examples that create objects and do nothing, but my actual scenarios may be creating new Threads, Listeners, etc. Assume the following pieces of code happen in a loop so that it might make a difference.
Using anonymous objects:
void doSomething() {
for (/* Assume some loop */) {
final Object obj1, obj2; // some free variables
IWorker anonymousWorker = new IWorker() {
doWork() {
// do things that refer to obj1 and obj2
}
};
}
}
Defining a class first:
void doSomething() {
for (/* Assume some loop */) {
Object obj1, obj2;
IWorker worker = new Worker(obj1, obj2);
}
}
static class Worker implements IWorker {
private Object obj1, obj2;
public CustomObject(Object obj1, Object obj2) {/* blah blah */}
@Override
public void doWork() {}
};
Thank you :)
i have the following class:
public class NewGameContract {
public boolean HomeNewGame = false;
public boolean AwayNewGame = false;
public boolean GameContract(){
if (HomeNewGame && AwayNewGame){
return true;
} else {
return false;
}
}
}
when i try to use it like so:
if (networkConnection){
connect4GameModel.newGameContract.HomeNewGame = true;
boolean status = connect4GameModel.newGameContract.GameContract();
switch (status){
case true:
break;
case false:
break;
}
return;
}
i am getting the error: incompatible types found: boolean required: int on the following switch (status) code.
what am i doing wrong please?