|
yes i study documentation but there is no example that show this way of message passing is correct or not correct. i want to know my code do message passing though the simulation or i pass message directly between nodes.
thanks,
|
|
|
|
|
Then you need to test your code; we cannot tell you whether it is correct or not.
Veni, vidi, abiit domum
|
|
|
|
|
How can I select the check box and press the submit bottom and only search for the selected check box option.?
|
|
|
|
|
No idea whatsoever, provide a proper explanation of your problem. Also, your title is "Php", so what does this have to do with Java?
Anf finally, please do not put your question in bold, this is considered rude.
Veni, vidi, abiit domum
|
|
|
|
|
Is your question related to java or php?
|
|
|
|
|
package exam804;
class Base
{
public static void foo(Base bObj)
{
System.out.println("In Base.foo()");
bObj.bar();
}
public void bar()
{
System.out.println("In Base.bar()");
}
}
class Derived extends Base
{
public static void foo(Base bObj)
{
System.out.println("In Derived.foo()");
bObj.bar();
}
public void bar()
{
System.out.println("In Derived.bar()");
}
}
class OverrideTest
{
public static void main(String[] args)
{
Base bObj = new Derived();
bObj.foo(bObj);
}
}
why the output is
"In Base.foo() In Derived.bar()" and not
"In Derived.foo() In Derived.bar()" ?
|
|
|
|
|
Why is foo declared as static ?
Veni, vidi, abiit domum
|
|
|
|
|
i don't know .i take this question from exam
|
|
|
|
|
Asaf Shay wrote:
i don't know .i take this question from
exam
However that is the clue as to the answer to the question.
|
|
|
|
|
You do not need to create the instance into base class. If you have base class, leave it, every class, which extends the base class as father class makes instances to it automatically. All you need is to put "super" modifier, if u need to call any function from your base class.
I suggest you to do like this in this case:
public class OverrideTest{
public static void main(String[] args){
Derived dObj = new Derived();
dObj.foo();
}
}
public class Derived extends Base{
public void foo(){
System.out.println("In Derived.foo()");
super.foo();
}
}
public class Base{
public void foo(){
System.out.println("In Base.foo()");
}
}
Now your output will be:
"In Derived.foo()"
"In Base.foo()"
You do not need to use this:
Base bObj = new Derived();
If You want to call the foo() method of Base class directly from yor Main class, remove the foo() method from your Derived class. In this case, the foo() method will be called from Base class automatically.
modified 19-Sep-13 9:53am.
|
|
|
|
|
this question is from exam .so i don't want to make the code better or different . i only want to know what i ask .
|
|
|
|
|
שלום אסף --
אלה התיקונים שצריך להכניס כדי שהתוצאה תראה כפי שרצית
1] Derived bObj = new Derived() ;
2] class Derived extends Base
public static void foo(Derived bObj)
אני חושב שהתוצאה הלא נכונה נגרמת בגלל "דריסה" לא נכונה של המחלקה היורשת
|
|
|
|
|
foo() in Base class is declared as Static. Therefore it is not belonged to specific object but common for all objects.
bObj is an object of Base class, therefore it will call foo() in Base class, because foo() is Static.
|
|
|
|
|
To explain that, take a look at what is executed and why.
First of all, you create a new Derived-Instance as an instance of Base.
Take a look at how you call the static method foo():
You dont access it in a static way (to use exact the phrase the compiler will warn you with) - which would be Base.foo() or Derived.foo() - but you call it on an instance.
As mentioned, bObj is an instance of Base (because you declared it as that) and thus the static Method Base.foo() is called, which prints the "In Base.foo()"-Part of your output.
If you declared it as an instance of Derived, the static method Derived.foo() would have been called there.
To explain the part "In Derived.bar()" take a look at what is called next:
In Base.bar() you call bObj.bar();
bObj was instantiated with new Derived(), so the method bar() on that object is overriden with the implementation in Derived, which prints then "In Derived.bar()".
I hope that explains inheritance a bit better.
ab
|
|
|
|
|
|
i'm still new to java, but i want to create a java application for mobile phones, which will perform the following functions for sending sms online
get Username and password of the user
Message Sender ID,
Recipient numbers or select from contact list
the message
then the send button which will make use of sms API
|
|
|
|
|
Please use Google to do some research first. It is not possible to provide all this information in a technical forum.
Veni, vidi, abiit domum
|
|
|
|
|
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
public class server extends Frame implements ActionListener, Runnable
{
Image Icon = Toolkit.getDefaultToolkit().getImage("hi.gif");
ServerSocket ss;
Socket s;
BufferedReader br;
BufferedWriter bw;
TextField text;
Button sendBut, exitBut;
List list;
public server(String m) // class constructor
{
super(m);
setSize(300, 130);
setLocation(0,0);
setIconImage(Icon);
setResizable(false);
setBackground(new Color(192, 192, 192));
this.setLayout(new GridLayout(2, 1));
Panel panels[] = new Panel[2];
panels[0] = new Panel();
panels[1] = new Panel();
panels[0].setLayout(new BorderLayout());
panels[1].setLayout(new FlowLayout(FlowLayout.LEFT));
sendBut = new Button("Send");
exitBut = new Button("Exit");
sendBut.addActionListener(this);
exitBut.addActionListener(this);
list = new List();
list.addItem("Server up & Listening on port plz wait...");
text = new TextField(25);
panels[0].add(list);
panels[1].add(text);
panels[1].add(sendBut);
panels[1].add(exitBut);
add(panels[0]);
add(panels[1]);
setVisible(true);
try
{
ss = new ServerSocket(1053);//some port number, better be above 1000
s = ss.accept();
br = new BufferedReader(new InputStreamReader(s.getInputStream()));
bw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
bw.write("Hi! ASL plz??");
bw.newLine();
bw.flush();
Thread th;
th = new Thread(this);
th.start();
}catch(Exception e){}
}
public void run()
{
while (true)
{
try
{
list.addItem(br.readLine());
}catch (Exception e){}
}
}
public static void main(String arg[])
{
// create an object instance
// by sending the title as a parameter
new server("Server Applicaton");
}
public void actionPerformed(ActionEvent ae)
{
if (ae.getSource().equals(exitBut))
System.exit(0);
else
{
try
{
bw.write(text.getText());
bw.newLine();bw.flush();
text.setText("");
}catch(Exception x){}
}
}
}
|
|
|
|
|
How would I get the JSpinner value into database?,
the value is in alphanumeric
Like
1month
2month
String[] monthStrings = {"1Month","3Month","6Month","1Year"};
SpinnerListModel monthModel = new SpinnerListModel(monthStrings);
JSpinner spinner = new JSpinner(monthModel);
|
|
|
|
|
chdboy wrote: How would I get the JSpinner value into database? The same way you would put any value into the database; what exactly is the difficulty? Given also that it is just a short list, maybe storing the index value rather than the string would be the best idea.
Veni, vidi, abiit domum
|
|
|
|
|
Here is the code ,how I'm saving the JSpinner value
statement.setString(27,JSpinner.getValue());
Under setString red line and the error is
The method setString(int, String) in the type PreparedStatement is not applicable for the arguments (int, Object)
and Under
JSpinner.getValue() red line and error says
Cannot make a static reference to the non-static method getValue() from the type JSpinner
|
|
|
|
|
You cannot use JSpinner.getValue() , you need to call getValue() on an instance of the JSpinner class.
Veni, vidi, abiit domum
|
|
|
|
|
I tried
statement.setString(27,(String)spinner.getValue());
and I get
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
EDIT:
It worked with
statement.setString(27,(String)spinner.getValue().toString());
modified 17-Sep-13 9:54am.
|
|
|
|
|
You should go back to your Java documentation or tutorials and learn why and when it is possible to use casts. Simply stated, you cannot use a cast to convert one object type to another. You also need to decide in advance what object type you want to store in the database, and write the code to handle that specific situation.
Veni, vidi, abiit domum
|
|
|
|
|
can i join your grope ?
longkimnoy
|
|
|
|