|
This seems like a rather advanced test program for someone who is new to Java. I suggest you take a look at The Java Tutorials[^] for help on reading and writing files. As to the format of your data file, you will need to decide that yourself, and will depend on what fields you need. For example suppose you need to get the name and age of a crewman, the line in the textfile could be:
CREW, Mr Spock, 750
Your program then needs to read this line and split the content into the correct fields so that you can create a Crewman object.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
JLayerPane - three problems
1 - I need fix row and column in layer pane and when mouse click it return my coordinates, not actual?
2 - I want to draw in this Layer, But could't?
3 - When i try AffineTransform, my coordinate origin does not moved?
If anybody have solution please reply........
class LayerPane extends JComponent
{
void LayerPane(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4,int recW,int recH)
{
JLayeredPane lp = new JLayeredPane();
f.setLayeredPane(lp);
GridLayout grid = new GridLayout(1600, 1440,recW,recH);
lp.setLayout(grid);
lp.setBounds(x1-5, y1-30, recW, recH);
lp.setLocation(x1-5,y1-30);
lp.setOpaque(true);
Color color = new Color(0, 0, 0, 0.4F);
lp.setBackground(color);
MyListenerLP myListener2 = new MyListenerLP();
lp.addMouseListener(myListener2);
lp.setVisible(true);
}
public void paintComponent(Graphics g)
{
g.setColor(Color.blue);
g.drawLine(x,y,x+50,y+50);
System.out.print("\nx,y is = "+x);
System.out.print(", "+y);
}
class MyListenerLP extends MouseInputAdapter
{
public void mouseClicked(MouseEvent e)
{
int x = e.getX();
int y = e.getY();
System.out.print("\nX,Y = "+x);
System.out.print(", "+y);
repaint(x,y,x,y);
}
}
}
|
|
|
|
|
Hi All,
I have a doubt.
I was just trying out some basic things in Core Java.
Here is the code
public class Test {
public static void main(String args[]) {
String a = "Hai";
String b = "Hai";
if(a == b) {
System.out.println("Equal");
} else {
System.out.println("Not Equal");
}
}
}
I Assumed that the result would be "Not Equal" as == does reference comparison. But I got the answer as "Equal".
Then I tried the second code
public class Test {
public static void main(String args[]) {
String a = "Hai";
a += "";
String b = "Hai";
if(a == b) {
System.out.println("Equal");
} else {
System.out.println("Not Equal");
}
}
}
Now i could get "Not equal". But logically both codes are same.
Why is this so?? Does Java share similar Objects??
Can anyone give an explanation on this??
Thanks,
Annns... modified on Thursday, February 11, 2010 8:38 AM
|
|
|
|
|
As you guess the objects are the same, as they both point to the exact same constant; this is the Java compiler optimising your code. Then when you add another character to a it becomes a new object and is no longer the same as b , even though, in human terms it has not changed.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
|
To add to Richards earlier answer, == checks that the objects are the same and equals(Object) should be overriden for ALL classes and checks that the contents are the same [this is the case with String ].
Try this to see:
public class TestEquals
{
public static void main(String args[])
{
String a = new String("Hai");
String b = new String("Hai");
if(a == b)
{
System.out.println("a == b true");
} else {
System.out.println("a == b false");
}
if(a.equals(b))
{
System.out.println("a.equals(b) true");
} else {
System.out.println("a.equals(b) false");
}
}
}
Panic, Chaos, Destruction.
My work here is done.
or "Drink. Get drunk. Fall over." - P O'H
|
|
|
|
|
Nagy Vilmos wrote: // Make sure we have two DIFFERENT objects:
String a = new String("Hai");
String b = new String("Hai");
Thanx...You are right. We should make sure that we make two different objects. But I have a doubt in my mind....both a and b should refer to same objects if we write b = a...why they are refering to same object if we say a="Hai" and b="Hai"??
|
|
|
|
|
What I think you are asking is why, when we write...
String a="Hai";
String b="Hai";
...are a and b the same object and not just the same value?
When you use a literal string, there will only be one created unless you explicitly create a new instance. m Think of the literal as a constant referencing an object.
Panic, Chaos, Destruction.
My work here is done.
or "Drink. Get drunk. Fall over." - P O'H
|
|
|
|
|
Hi,
Am using a File upload tag in a JSP page.
(Input type="file")
After clicking submit(),after usual validation,sometimes user is getting error validation message.at this point of time, the content in the textbox is clearing and system is focusing the the textbox next to browse button.
Here am validatiing the page click with image comparision which is Serverside.
so is there anyway to hold the content(path)in the text box.Have a Nice Day Dudes
|
|
|
|
|
session variable or cookies.
|
|
|
|
|
This is not a Java question (JavaScript != Java), so you may get a better response in the ASP.NET or Web Development forum. Please read the guidelines[^] to make sure you post in the right place. MVP 2010 - are they mad?
|
|
|
|
|
Richard MacCutchan wrote: JavaScript != Java
yet you can use both together.
|
|
|
|
|
4277480 wrote: yet you can use both together.
You can use WPF with VB.NET or C#, but WPF is still not either of those languages.
However, my main point is that this question stands a better chance of an answer in a more appropriate place. I don't think many of the Web developers look at the Java forum.MVP 2010 - are they mad?
|
|
|
|
|
I know what you mean and your absolutely correct, I only wanted to mention it.
|
|
|
|
|
Can someone tell me how this can be done in Java? It's a PERL Web service call in Phyton, there is no WSDL available. Any suggestions will be appreciated.
server = SOAP.SOAPProxy("https://xyz:xyz@soap.abc.com/mod_soap",namespace="somenamespace")
test=('connection_test','')
a=apply(server.dynamic, test)
print a
|
|
|
|
|
|
I have to create a Slot Machine in java for college and am having problems with the last bits of it.
It contains 3 classes, the main slotMachine class(which contains the main logic for the game, calling on the other 2 classes), a Column Class and a slot Class.
here is the code for each:
slotMachine - (Very incomplete - last thing to do!)
import java.io.IOException;
public class slotMachine
{
public static void main(String[] args) throws NumberFormatException, IOException
{
int initialBalance = 10;
Stream in = new Stream(System.in);
System.out.println("*****WELCOME TO MY SLOT MACHINE*****");
System.out.println("Your initial balance is: " + initialBalance + " credits");
System.out.println("Please enter an amount to bet: ");
int betAmount = in.readInt();
}
}
Column -
import java.util.Random;
public class Column
{
int faceInt;
public void newFace()
{
Random newFace = new Random();
faceInt = newFace.nextInt(3);
}
public String toString()
{
switch(faceInt)
{
case 0:
return ("|APPLE|");
case 1:
return ("|ORANGE|");
case 2:
return ("|PEAR|");
}
return null;
}
}
Slot -
public class Slot
{
Column column1, column2, column3;
public Column pullHandle()
{
column1.newFace();
column2.newFace();
column3.newFace();
return column1;
}
public boolean fullHouse()
{
if(column1.equals(column2) && column2.equals(column3))
{
return true;
}
else
{
return false;
}
}
public boolean halfHouse()
{
if(column1.equals(column2) || column2.equals(column3) || column1.equals(column3))
{
return true;
}
else
{
return false;
}
}
}
I am trying to call the pullHandle method (located in the Slot class) in the slotMachine class, but don't know how! When I put Slot.pullHandle(); in the main class, it doesn't work, giving me the error of can't reference a static type, from a non static source (or something like that), so I change it to static, then when I run it I get an error saying:
Exception in thread "main" java.lang.NullPointerException
at Slot.pullHandle(Slot.java:8)
at slotMachine.main(slotMachine.java:18)
Also, in the Slot class, for the pullHandle class I want to return the 3 columns, but keep getting a code unreachable error.
This is stressing me out! Help me please!modified on Monday, February 8, 2010 5:40 PM
|
|
|
|
|
Your pullHandle() method is using the variables column1, 2, 3 but nowhere do you initialize them, hence the NullPointerException. As to the static/nonstatic problem, you need to create instances of all your classes and call methods on those instances.
Try reading through some of these tutorials[^] to get a better grasp of how classes operate.
MVP 2010 - are they mad?
|
|
|
|
|
Did I not initialize them in the collumn class and then call them in the slot class?
|
|
|
|
|
bmnot wrote: Did I not initialize them in the collumn class and then call them in the slot class?
Not that I could see, although it was not easy given that you posted your code in three separate places. Try to post the entire code in your original message (use the edit link), and don't forget to enclose it in <pre></pre> tags (use the "code block" button).
I think in your slot class you have a statement like Column column1, column2, column3; which creates the three variables but does not initialise them to anything.MVP 2010 - are they mad?
|
|
|
|
|
i called a method from a different class on them(.newface), does that not initialise them?
|
|
|
|
|
bmnot wrote: i called a method from a different class on them(.newface), does that not initialise them?
Since I have no idea what that code does, I cannot answer the question. Your comments suggest you need to spend some time rereading your Java manual on classes, objects and their use.MVP 2010 - are they mad?
|
|
|
|
|
no, this does not modify the value as the newFace() method does not return a value and/or modify any given value.
try to set the values like this:
Column column1=0;
Column column2=0;
Column column3=0;
It's alwasy good to not have uninitilzed values, give'em at least some "empty" value.
Also always include getter and (if needed or might be needed in future) setter:
public int getColumn1(){
return column1;
}
public void setColumn1(int _column1){
column1 = _column1;
}
do you know how to debug your code?
greets
TorstenI never finish anyth...
|
|
|
|
|
Hello Friends
I created a 3d viewer.I loaded one object tht is centerd at some other than (0,0,0) but MouseRotate is rotating around only(0,0,0).
Is there any way to change the center of Rotation?
Or any way to change the center of object to worldCordinate(0,0,0)?
Thanks IN Advance.
Regards
Yogesh
|
|
|
|
|
No Body Replied.
But it helps me to find myself.We can do it with OrbitBehaviour class method that is setRotationCenter().
AnyWay,Thanks who viewed my Thread().
But now i am having one more question,if u guys can help me in this.I am having one point3d() that is the center of object.I want to convert it into WorldCordinates.
I read abt getLocaltoVWorld().But it return Transform3d() and I am having my local points in Point3d().Please Advice me Something.
Thanks In Advance.
Regards
Yogesh
|
|
|
|
|