Oleg Korsakov

Greenhorn
+ Follow
since Jan 14, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Oleg Korsakov

My big thanks to Mr. Stan and yes I'll show it here later (in this topic)
17 years ago
I mean the class structure... and realisation of the link between nodes - (class structure too)...
Thanks,
Oleg
17 years ago
Hello!
Very needed help....)

I have to represent a graph. It has nodes connected with arrows from the top node towards the lower ones. How can I using java language to model this graph. Which class should be used for the node and how to represent the arrows between nodes also.
Node can have two downward arrows... How to describe this...

Thanks,
Oleg.
17 years ago
Hello!

I have to represent a graph. It has nodes connected with arrows from the top node towards the lower ones. How can I using java language model this graph. Which class should be used for the node and how reprent the arrows between nodes also.
Thanks,
Oleg.
17 years ago
My thanks to you. I didn't know that class in applet is created implisitly.
17 years ago
Yes, thank you...
One remark only: when the creation of that class instance happened?
( I guessed that only after creation implicit reference this appears )
17 years ago
Hello )
One thing from the Class JApplet SDK 5.0 that the setLayout method is not static:
public void setLayout(LayoutManager manager)

Why does the calling setLayout (also add) happen without creating object by new operator? setLayout is not static and even if it is static we need to write JApplet.setLayout, is it?
the example below:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;

public class WelcomeApplet extends JApplet
{
public void init()
{
* setLayout(new BorderLayout());

JLabel label = new JLabel(getParameter("greeting"), SwingConstants.CENTER);
label.setFont(new Font("Serif", Font.BOLD, 18));
* add(label, BorderLayout.CENTER);

JPanel panel = new JPanel();

JButton oneButton = new JButton("First Button");
oneButton.addActionListener(makeURLActionListener(
"http://www.javaranch.com"));
panel.add(oneButton);

JButton twoButton = new JButton("Second Button");
twoButton.addActionListener(makeURLActionListener(
"mailto:xxx@yyy.com"));
panel.add(twoButton);

* add(panel, BorderLayout.SOUTH);
}

private ActionListener makeURLActionListener(final String u)
{
return new
ActionListener()
{
public void actionPerformed(ActionEvent event)
{
try
{
getAppletContext().showDocument(new URL(u));
}
catch(MalformedURLException e)
{
e.printStackTrace();
}
}
};
}
}
Excuse me for long example - I saw it in a book...
Thanks.
17 years ago
My special thanks to Ernest too, especially in "A cast of a reference type never changes the actual object".
17 years ago
Thank you, Jeanne, for your answer but let me concretize a little to get
real clarification ...
So we have to cast LightBulb down to SpotLightBulb ( 'dog' to 'poodle' )
But it is not correct in that book. Is it correct really ?
( to cast to the type that is lower in the hierarhy )

And if objectRef is higher, it will return false ... then the downward
direction of casting will be lost. I guess we have to check to true before casting whether we can cast downward <objectRef> to <targetType> that is lower (i mean <targetType> here is a poople and objectRef here refers to a dog so let me guess that 'dog instanceof poodle' gives 'true')
17 years ago
Hello!

There is one competent book ( let me note that they recommend JavaRanch also - http://www.ii.uib.no/~khalid/pgjc2e/resources.html )
where I found small example:

class Light { /* ... */ }
class LightBulb extends Light { /* ... */ }
class SpotLightBulb extends LightBulb { /* ... */ }
class TubeLight extends Light { /* ... */ }
class NeonLight extends TubeLight { /* ... */ }

public class WhoAmI {
public static void main(String[] args) {
boolean result1, result2, result3, result4, result5;
Light light1 = new LightBulb(); // (1)
// String str = (String) light1; // (2) Compile time error.
// result1 = light1 instanceof String; // (3) Compile time error.

result2 = light1 instanceof TubeLight; // (4) false. Peer class.
// TubeLight tubeLight1 = (TubeLight) light1; // (5) ClassCastException.

result3 = light1 instanceof SpotLightBulb; // (6) false: Superclass
// SpotLightBulb spotRef = (SpotLightBulb) light1;// (7) ClassCastException

light1 = new NeonLight(); // (8)
if (light1 instanceof TubeLight) { // (9) true
TubeLight tubeLight2 = (TubeLight) light1; // (10) OK
// Can now use tubeLight2 to access object of class NeonLight.
}
}
}

I thought that in lines (6)&(7) was true because light1 is the reference of the supertype Light and that it must be higher in the instanceof operator than type of the subtype SpotLightBulb (last one - lower - in the inheritance hierarchy). And the purpose of casting is to cast the supertype to the type of the subtype ( (<subtype> <supertypeRef> ),
but line (7) is invalid. Why? And in the instanceof operator where must be
<objectRef> in the inheritance hierarchy higher or lower than the target type ( <objectRef> instanceof <targetType> ) ?
And vice versa in lines (8),(9) I guess that here is executing the casting
of the subtype to supertype and that this casting can be execute by using an assignment: tubelight2 = light1;
Where are my thoughts wrong?
17 years ago
... I have to put digits as a result of a % operation into string
to accumulate there in cyrcle by putting one digit by another and using concatenation
declare: String mstr = result % n; //result has int type
then in cycle
mstr += result % n; // symbol by symbol

n = 2 (5,...)

Which casting I have to do in the cycle and in the declaration ?
ps
If I write: String mstr = (String)result % 2; //-- incompatible types

My thanks for any help
17 years ago
Thank you, also for welcome!
17 years ago
Hello.
It's I know simple but how to make a number from a command line:

int int1 = (int)args[0];

required: int
int int1 = (int)args[0];
^
1 error
I guess data casting has another method here
Thank you
17 years ago