Swing/AWT/SWT :: Does Order Of Concatenation Affect AffineTransforms
Aug 15, 2014
I'm working with AffineTransforms, and am confused by one aspect of their behavior. It appears that the order in which two sequential concatenations are executed effects the final result. Here's a fragment of code to illustrate the concept:
public void draw() {
radius *= 1.1;
if (radius>800) {
radius = 10;
[Code].....
This code has dramatically different results if the two concatenations are reversed in order. I want to understand what's going on. Is it really true that the order of concatenations affects the final result? From my understanding of matrix multiplication, it shouldn't. Have I missed something here?
View Replies
ADVERTISEMENT
May 23, 2015
I am trying to concatenate some strings via: String finalString="(User="+endUserCharge+")";endUserCharge is a string..I get the following error:
caused by: org.codehaus.jackson.JsonParseException: Unexpected character ('(' (code 40)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
at [Source: java.io.ByteArrayInputStream@3d9127a9; line: 1, column: 2]
View Replies
View Related
Jan 27, 2014
User inputs certain variables for the story, the problem I am having is the concatenation is not working as intended. the story part with the + parts all come back with an error. I thought I had it correct but obviously i don't.
import java.util.Scanner;
public class story
{
public static void main(String[] arg)
[code]....
View Replies
View Related
Jan 27, 2014
I am trying to concatenate 4 strings together to later be able to make them all upper case, or lower case or get the length. I keep getting an error on line 16.
import java.util.Scanner;
public class userInput
{
public static void main(String[] arg)
{
Scanner keyboard;
keyboard = new Scanner(System.in);
String msg1, msg2, msg3, msg4;
[Code] ....
View Replies
View Related
Jan 6, 2014
I have a program like below:
final String s1 = "AAA";
final String s2 = "AAA";
String s6 = s1+s2;
String s7 = "AAAAAA";
if ( s6 == s7 ){
System.out.println("s6 and s7 are same" );
}
On running, it prints "s6 and s7 are same". But if i remove the final modifier of s1 and s2 then it's not. What could be the reason?
View Replies
View Related
Feb 1, 2014
the focus traversal policy (hereafter "tab order") in forms and panels doesn't follow the order in which controls were inserted into the container, but is derived from the position of the components on the form or panel. This is very neat (and probably allows sloppy coders and GUI builders to exist without actually ever thinking about the tab order), except when it isn't. As when you actually want to specify a different component order, for example.
In the following example, I've created a form with two columns of buttons. I want the tab order to go through the first column of buttons, followed by second column of buttons (ie. a column-by-column schema). The default tab order is row-by-row, however, and can be obtained for reference by commenting out the setupFocus() call in the constructor.
I had hoped that the ContainerOrderFocusTraversalPolicy would do the job, but there is a couple of problems (which I've addressed in the setupFocus() method). Firstly, the container itself is part of the focus chain. This at least is easily remediable by calling setFocusable(false), but I don't have to do that with the initial focus traversal policy, so I wonder why I have to do it with this one. The other problem is more pressing, though - the ContainerOrderFocusTraversalPolicy lets me (un)hapilly tab through JLabels. Again, I've fixed this, but the initial policy knows all by itself that it's not a good idea to focus a JLabel. Moreover, I'm afraid there might be other components that do not receive focus with the original policy, but ContainerOrderFocusTraversalPolicy might plod though them.
isn't there some focus traversal policy implementation that I could just set and it would tab through exactly the same components as the original policy, except it would order them according to their order in the container?
Code:
package test;
import java.awt.Component;
import java.awt.ContainerOrderFocusTraversalPolicy;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
[code]...
View Replies
View Related
Mar 1, 2014
One of the random number generators in Java extract the higher-order bits of the random number in order to get a longer period.
I'm not sure if I understand how this is done. Suppose that the random number r = 0000 1100 1000 1101. If we extract the 16 most significant bits from r; is the new number r = 0000 1100 or r = 0000 1100 0000 0000?
View Replies
View Related
Jan 26, 2014
Any link to the accurate explanation of binary trees in java?
View Replies
View Related
Feb 14, 2015
I have an ArrayList of employee and ArrayLsit of bosses, and I want to keep those people in a temporary ArrayList , then ordain alphabetically by name, to sort I use the interface comparator.
The problem comes when I will order 2 ArrayList(workers and bosses), because every time I call I use these functions or not is ordered (sortByNameAlphabetical())
public class Employee {
private String name;
public String getName() {
return name;
}
@Override
public String toString() {
return name ;
[Code]...
View Replies
View Related
Sep 17, 2014
I came across this code which proves that variable initialisation occurs before even constructors are called.However, I am confused over some things.
Firstly, from my understanding, when a new House object is created in this line House h = new House(); , the no-arg constructor of the House class is called.
Since the no-arg constructor House() is called, why are all the creation of Window objects being run first ? Shouldn't Java jump straight into the no-arg constructor House() ?
class Window {
Window(int marker) { System.out.println("Window(" + marker + ")"); }
}
class House {
Window w1 = new Window(1); // Before constructor
House() {
// Show that we’re in the constructor:
System.out.println("House()");
w3 = new Window(33); // Reinitialize w3
[code]...
View Replies
View Related
Jan 17, 2014
im new to java and i wanna make a program using java that can add order entries for a restaurant but how to... i was hoping something that would ask to person to input one or two items and before it calculates the total amount to be paid it will ask the guy who inputs the amount whether or not there are additional orders or not before it prints out the total amount... I am pretty sure it will need an if-else statement..
import javax.swing.*;
import java.util.Scanner;
public class OrderCalc {
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame aFrame = new JFrame("OrderCalc");
aFrame.setSize(500,250);
aFrame.setVisible(true);
[code]....
View Replies
View Related
Sep 22, 2014
I'm learning the swing options of Java, and my first exercise was the typical Chat Room. I got everything right: TextField, TextArea, the jpanel at left side and the buttons inside of it. BUT I can't order the 2 buttons (1 north, 1 south). I've already looked for answers, but didn't find anything and I tried to asked the teacher, but she was too lazy to look for the error. Here is my code:
f=new JFrame("Chat Room");
b1=new JButton("Send");
b2=new JButton("Emoticons");
public void showWindow(){
p1=new JPanel();
f.getContentPane().add(p1,BorderLayout.EAST);
p1.add(b1,BorderLayout.NORTH);
p1.add(b2,BorderLayout.SOUTH);
}
View Replies
View Related
Nov 20, 2014
I am unsure of something. In the following class, which is read first; the static field or the main method?
class Test{
static int a = 3;
public static void main(String args []) {
//some code}
}
I put some code in Eclipse and have tried to look at the hierarchy. It would point to all static fields being initialized in order from top to bottom, including the main method.I had thought that the main method was always the first thing in a public class to be initialized, regardless of where in the code it resides. Am I reading the Eclipse hierarchy wrong? I find Eclipse very difficult, especially since I typically code in Textmate. I just want to see how my code is operated upon,
View Replies
View Related
Dec 3, 2014
This is how the for loop works for the row,right?
for(int i=array.length-1;i>=0;i--)
{
}
I want to know how the for loop works for the column?
View Replies
View Related
Dec 29, 2014
I have some codes as below:
public class Hello
{
public static void main(String[] args) {
new Student().fun();
}
}
class Person
[Code] ....
Now the output is "Person". if i hide the "PRIVATE" in class PERSON, that is, method PRINT in class STUDENT override the same method in its father class, then the output is "Student". Why? I mean, how does the program know what PRINT method should be called?
View Replies
View Related
Oct 9, 2014
This is what I have to do:Write a program that takes a string of someone's name and prints it out last name first. Your program must use pointers, not array subscripts. You may use the available string manipulation functions if you find an opportunity.
Example:
"George Washington"
"Washington, George"
I am not sure how to reverse the name, I have been looking in my textbook and online and cannot figure it out. This is what I have put together so far, it does not run. At the end it says unnecessary return value.
import java.util.*;
import java.util.Scanner;
public class Test {
public static void main ( String [] args ) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter name: ");
String name = sc.nextLine();
String lastname = "";
String firstname = "";
for(int i = 0; i < name.length(); i++) {
if(name.charAt(i) == ' ')
View Replies
View Related
Feb 3, 2015
I am trying to sort an array that I have by alphabetical order but I am having problems. Firstly the code that I have used to sort the array may not even do what I need but havn't got far enough to test it yet so go easy on me . I have read in some places when searching how to do this that I would have to create my own bubble sort in order to achieve this but I was hoping that Java had a built in sort method/function. Secondly I lack the knowledge in java to be able to assign an existing array or even a variable to the newly sorted array as I need the unsorted version with the original name and the newly sorted version as another.
code (This is not all of the code, I decided to include only what I thought was relevant):
import java.util.Arrays;
public class Sentence {
private String words[];
public Sentence(String[] words) { this.words = words; }
@Override
public String toString() {
return "Sentence{" +
"words=" + Arrays.toString(words) +
[Code] ....
Is it possible to shorten the sort function to just this?
public String sorted() {
return Arrays.sort(words);
}
View Replies
View Related
Nov 29, 2012
I want to write an application that inputs a sentence, tokenizes the words with method split and reverse the words (not the letters)...I am stuck at the last part: how to reverse them...should I use the method reverse(); ?
Here is my code..
import java.util.Scanner;
import java.util.StringTokenizer;
public class ReversedWords {
//execute application
public static void main( String [] args) {
//get sentence
[code]....
View Replies
View Related
Dec 22, 2014
I am trying to make a program that reads a word and display if the letters are in ascending order or not in ascending order(All kind of letters, capitals ). I have made a code but its not 100% correct. My code:
class Main
{
public static void main(String args[]) {
System.out.print( "#Enter text : " );
String text = BIO.getString();
[code]...
View Replies
View Related
Apr 27, 2014
I need to put my scores in ascending order how do i do that?
public static void main(String[] args) {
char[][] answers = {
{'A', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
{'D', 'B', 'A', 'B', 'C', 'A', 'E', 'E', 'A', 'D'},
{'E', 'D', 'D', 'A', 'C', 'B', 'E', 'E', 'A', 'D'},
{'C', 'B', 'A', 'E', 'D', 'C', 'E', 'E', 'A', 'D'},
[Code] ....
View Replies
View Related
Apr 6, 2015
How do I take the union between an object called on and the object passed in the parameter?I have an interface:
Java Code:
import java.util.Set;
/**
* An extended Set where additional functionality is added
*/
public interface NewSet<T> extends Set<T> {
[code]...
Now, the union method requires a NewSet object to be called on. The Union will be performed between the object called on and the object passed in the parameter, which is set.How do I call on a NewSet object in order to take the union between the object called on and the object passed in?Do I just do:
Java Code:
public NewSet<T> union(NewSet<T> set) {
NewSet<T> calledOn = new ArrayList<T>();
// ...
} mh_sh_highlight_all('java');
View Replies
View Related
Oct 10, 2014
I'm trying to make this code's output display like a sentence, since right now it displays downward and doesn' look right.
public class ReverseOrder {
public static void main(String[] args) {
String phrase = "The rain in Spain falls mainly on the Plain";
char[] phraseArray;
phraseArray = phrase.toCharArray();
for(int i = phraseArray.length - 1; i >= 0; i--){
System.out.println(phraseArray[i]);
}
} // end main
} // end ReverseOrder class
View Replies
View Related
Sep 8, 2014
the dates are printing out of order. It should appear MM/DD/YYYY however with my code its printing DD/YYYY/MM.Here is my code.
public class DateTest {
public static void main(String args[]){
Date date1 = new Date( 7, 4, 2004 );
System.out.print( "The initial date is: " );
date1.displayDate();
[code]....
View Replies
View Related
May 8, 2014
what code I should add to my program in order to get these dice to roll. The program, according to my teacher, is CORRECT so far, so I'm not going to change anything. I just need to know how to roll the 2 dice I added in. I just want to get it done. No math.Random. The direction is: Roll each of the Dice by invoking the roll method on each Dice in the array.
My code:
//Dice.java
package homework3;
import java.util.Random;
public class Dice {
private int numberShowing;
private int numberOfSides;
private static final Random randomNumber = new Random();
[code]....
View Replies
View Related
Jan 8, 2015
I am just learning java now i have a problem where i have to run a test order on my internalOrder class from the orderTester class and i,m not sure how to do this ?
This is the code i have for my order class:
public static void testCase8(){
orders ords = new orders ("Pen", 8, -0.5);
System.out.println("Test Case 8:" + "
" + ords.getOrderDetails());
[Code] ....
This is the code for my Internal class
public final static double DISCOUNT = 0.4;
public InternalOrder(String productName,int quantity ){
super(productName, quantity,DISCOUNT);
}
public void printInternalReport(){
System.out.println("Printing internal report ...");
}
Now my orderTest class is passed though orders class if you need that code i will put it up...
View Replies
View Related
Jun 30, 2014
Just some sample code:
Java Code:
mainPanel.add(background, new Integer(10));
cards.add(king[0] = new Card(200, 200, TILE_SIZE, TILE_SIZE, 0, 0)); mh_sh_highlight_all('java');
Then, when a card is created, it calls:
Java Code: Main.mainPanel.add(this, new Integer(1)); mh_sh_highlight_all('java');
Yet for some reason, the background is always painted OVER the card UNLESS I set the background to -1.
View Replies
View Related