How can Anonymous class inherit ?
I am not much fluent with Inner Classes concept.Only today i read that
"An anonymous class may implement an interface or extend a superclass, but may not be declared to do both. "
JLS Classes Page also couldn't fetch me my answer or may be i could not spot it.I think latter.
I think a in depth study of Inner Classes,Anonymous classes can get me my answer. Can anyone give me any pointers that would clear my doubt ?
Thank you for your consideration.
Edited by: amtidumpti on May 1, 2009 12:58 AM
amtidumpti wrote:
I am not much fluent with Inner Classes concept.Only today i read that
"An anonymous class may implement an interface or extend a superclass, but may not be declared to do both. "
JLS Classes Page also couldn't fetch me my answer or may be i could not spot it.I think latter.
http://java.sun.com/docs/books/jls/third_edition/html/classes.html
I think a in depth study of Inner Classes,Anonymous classes can get me my answer. Can anyone give me any pointers that would clear my doubt ?
Thank you for your consideration.Start writing an anonymous class and you should readily see why it can't do both.
Have you even tried to implement an anonymous class yet? Please clear my doubt.
Similar Messages
-
How can a class extending MouseAdapter override mouseDragged method?
I've found this code from somewhere, don't remember where
private class DragLimiter extends MouseAdapter {
@Override
public void mousePressed(MouseEvent e) {
pressedX = e.getX();
pressedY = e.getY();
@Override
public void mouseDragged(MouseEvent e) {
label.setLocation(
Math.min(
Math.max(label.getX() + e.getX() - pressedX, BORDER),
panel.getWidth() - label.getWidth() - BORDER),
Math.min(
Math.max(label.getY() + e.getY() - pressedY, BORDER),
panel.getHeight() - label.getHeight() - BORDER));
}The question is how can a class extending MouseAdapter override mousedragged()?
I found that MouseAdapter implements MouseListener whose subinterface is MouseMotionListener, I think this has something to do with the question.
But I've always thought you can only override methods of the super classes or interfaces not vice versa.
I believe I have some kind of fundamental misunderstanding of this and would like to have some help in understanding this.
ThanksThis is more a Java question than a Swing question.
I found that MouseAdapter implements MouseListener whose subinterface is MouseMotionListenerThat's not correct: if you look at MouseAdapter Javadoc, you'll find that it implements both MouseListener and MouseMotionListener (and MouseMotionListener is not a subinterface of MouseListener).
Regardless, if you look at the javadoc, you see that MouseAdapter declares a method public void mouseDragged(MouseEvent). It doesn't matter whether this is also declared by an interface, a subclass can override it all the same. -
How can a class be notified when an open file is modified externaly ?
Hi!
Can a class that open a File be notified when that file is modified by another program ? If yes how ?
Thanks!I don't know that any operating system provides facilities to hook into the filestore this way (whatever language you're programming in). Probably the best you can do is to check the last modified time periodically.
-
How can user control inherit a user control?
I have a user control "Cell" with different methods.
I need 2 other user controls to Inherit from "Cell".
I was told to change "Cell" to a class without a xaml, I did it, and to ensure that the subclass inherits from the base class both in the cs code-behind file and in the first tag of the xaml.
how do I do it?
and, how do I know that now the user controls will have the same base class?1. Add a new class to your project where you define the Cell class:
namespace WpfApplication22
public class Cell : System.Windows.Controls.UserControl
2. Add a new UserControl to your project and change the base class in both the XAML and the code-behind (sse the parts in bold below):
UserControl2.xaml:
<local:Cell x:Class="WpfApplication22.UserControl2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfApplication22"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
</Grid>
</local:Cell>
UserControl2.xaml.cs:
public partial class UserControl2 : Cell
public UserControl2() {
InitializeComponent();
3. Add another new UserControl to your project and repeat the steps in 2. above.
That should be it.
Please remember to mark helpful posts as answer to close your threads and then start a new one if you have a new question. -
How can custom classes generate events?
I need to write my own classes that generate an event. (Just like buttons do). Can this be done? If so, how?
Thanks you in advance,
Teun van de BergGenerating events is trivial. There is a little real work, however.
1) Write a class that extends java.util.EventObject, adding any fields specific to your event.
public class MyEvent extends java.util.EventObject {
// field(s) here
MyEvent( Object source /*, other fields here */ {
super( source );
// other fields assigned here
} // end of class MyEvent2) When it comes time to create an event:
MyEvent me = new MyEvent( this /*, other fields here */ );Now the real trouble, which isn't that much trouble. The event generator has to maintain a list of the registered listeners. (There are occasions when there will be only one listener, so you can cheat. If the fact that there's just one is a basic part of the design, go ahead and cheat.) You'll need an interface if the listeners can be different types. (Again, you can skip that if all the listeners are the same type.)
3) Start with the interface:
public interface MyEventListener {
public void handleMyEvent( MyEvent me );
}The nicest interfaces are the simplest to implement, so a one-method interface is really friendly.
4) Then you'll need some code in your event generator that lets people register:
ArrayList listeners = new ArrayList();
public addMyEventListener( MyEventListener mel ) {
listners.add( mel );
}5) Then your event listeners have the usual event code:
public class Whatever implements MyEventListener {
// interface implemented here
public void handleMyEvent( MyEvent me ) {
// do something with the event
// elsewhere, possibly in the constructor
eventGenerator.addMyEventListener( this );Now you're all set to actually respond to the event.
6) Here's your event generator after it finds out that whatever event has happened:
void dispatchMyEvent() { // maybe needs some args?
for ( int j = 0; j < listeners.size(); j++ ) {
MyEventListener mel = (MyEventListener) listeners.get(j);
if ( mel != null ) {
MyEvent me = new MyEvent( this /*, other fields */ )
mel.handleMyEvent( me );
} // end dispatchMyEvent();It looks like quite a bit of trouble initially, but it will give you a very nice result. Good luck! -
How can a class listen to other class's aoutput
I have 2 classes which are both unrelated. but i want one class to listen to the output emitted by the other class. eg, class A continuosly prints messages and these messages, i want to be there in class B ...
Any suggestions?I have 2 classes which are both unrelated. but i want
one class to listen to the output emitted by the
other class. eg, class A continuosly prints messages
and these messages, i want to be there in class B
Any suggestions?Classes do not listen to other classes but objects created from the classes can listen to other objects.
eg.
class A {
public void sendMessage(B b) {
b.setMessage(String aMessageFormA);
public static void main(String[] args) {
A a = new A();
B b = new B();
a.sendMessage(b);
b.printMessageFromA();
} -
How can a class access a variable on a MovieClip's time line?
in my class I declare a linked movie clip:
a_mc = new LinkedMC ();
trace(a_mc.testString);
and on the time line of LinkedMC:
var testString = "test string";
but I can't access testString.
any clues?
Thanks!you're trying to access the variable before it's defined. have your LinkedMC dispatch an event letting your know the variable has been defined and assign a listener to a_mc to detect that event. in the listener function, use your trace() function.
-
How can i convert the object to class~~~????
recently i develop UML drawing tool for drawing UML diagram, i now design a program structure. now i have already defined many classes that represent each shape in UML. each class stores data of the related shape. then i use a vector to store all shape as follow;
Vector shape = new Vector();
shape.addElement(useCase); \\useCase is a Class i defined
shape.addElement(actor);\\actor is a Class i defined
now i want to use all shape's methods stored in the vector before how can i do that in general ways?
i don't want to code like this;
Object o = shape.elementAt(a);
if (o instanceof UseCase)
if (o instanceof Actor)
because i have many classed!! can u all professional help me? i am just a beginer of java programming studentSounds like you need to use an inheritance structure...
Setup a generic class that contains methods (probably blank) which each class (such as actor, useCase) will inherit from. Then make actor/useCase inherit from this base class and provide specific code in each of the general methods.
Then when you retrieve your object from the class, you can cast it as your generic class and access the general methods without caring what the actual class is.
Eg. Basic class "shape". has empty methods "draw" and "setPosition". Class "circle" and "square" both extend "shape" and provide specific implementations of setPosition and draw methods. You can then cast them as class type shape and do draw() and setPosition methods without caring about what type the object actually is. -
How can i display the result of java class in InputText ?
Hi all,
How can i get the result of java class to InputText Or OutputText ???
also can every one in the forum give me road map for dealing with java in oracle adf because i'm beginner in oracle adf
i saw some samples in oracle adf corner but it's difficult for me.User,
Always mention your JDev version, technologies used and clear usecase description (read through this announcement : https://forums.oracle.com/forums/ann.jspa?annID=56)
How can i get the result of java class to InputText Or OutputText ???Can you elaborate on your requirement? Do you mean the return value of a method in a class as output text? Or an attribute in your class (bean?) as text field?
-Arun -
How can i use JWSDP1.6 from Ant tool to convert .wsdl file into Java class
Hi All,
i m very new in the development field.plese help me...
i have a .wsdl file and i have to make some modification in the file and return this file with build file used in Ant tool.
means my requirement is to conver the .wsdl file into java class,modify it and convert back to wsdl file.how can i do it using JWSDP1.6 and Ant tool.
thanks in advance...
Vikram Singhlemilanais wrote:
hello!
I have developpe an animation with flash. before give it to othe person in order to use it, i would like to secure it by integrated a security module inside the software.Secure it from what? Being played? Copied? Deleted? Modified?
Because, i am a java developper, i have choose Netbeans 6.1 to secure it.That has to be the most random thing I've read in some time.
do you know how can i do to integrate my animation .swf inside my java class?Java can't play SWF files and Flash can't handle Java classes, so what you're suggesting here doesn't make a lot of sense. -
How can I hide the class file ??
Hi !
I has a question, when i write a program of Java, then use the command "javac" to compiler to class file for other people using, but the class file can be disassembled and convert to source code. How can I hide the class file and let people can not disassemble, or can not see the source code. ThinksSee these....
http://www.saffeine.com/
http://www.jarsafe.com/
I recently read this. This will help you.
http://developer.java.sun.com/developer/qow/archive/160/index.jsp
Enojy....
Rajesh -
How can I convert a class file to Exe file
hai
How can I convert a class file to Exe filePlease search the forums before asking questions - this has been answered hundreds (really!) of times.
-
How can I assign image file name from Main() class
I am trying to create library class which will be accessed and used by different applications (with different image files to be assigned). So, what image file to call should be determined by and in the Main class.
Here is the Main class
import org.me.lib.MyJNIWindowClass;
public class Main {
public Main() {
public static void main(String[] args) {
MyJNIWindowClass mw = new MyJNIWindowClass();
mw.s = "clock.gif";
And here is the library class
package org.me.lib;
public class MyJNIWindowClass {
public String s;
ImageIcon image = new ImageIcon("C:/Documents and Settings/Administrator/Desktop/" + s);
public MyJNIWindowClass() {
JLabel jl = new JLabel(image);
JFrame jf = new JFrame();
jf.add(jl);
jf.setVisible(true);
jf.pack();
I do understand that when I am making reference from main() method to MyJNIWindowClass() s first initialized to null and that is why clock could not be seen but how can I assign image file name from Main() class for library class without creating reference to Main() from MyJNIWindowClass()? As I said, I want this library class being accessed from different applications (means different Main() classes).
Thank you.Your problem is one of timing. Consider this simple example.
public class Example {
public String s;
private String message = "Hello, " + s;
public String toString() {
return message;
public static void main(String[] args) {
Example ex = new Example();
ex.s = "world";
System.out.println(ex.toString());
}When this code is executed, the following happens in order:
1. new Example() is executed, causing an object to constructed. In particular:
2. field s is given value null (since no value is explicitly assigned.
3. field message is given value "Hello, null"
4. Back in method main, field s is now given value "world", but that
doesn't change message.
5. Finally, "Hello, null" is output.
The following fixes the above example:
public class Example {
private String message;
public Example(String name) {
message = "Hello, " + name;
public String toString() {
return message;
public static void main(String[] args) {
Example ex = new Example("world");
System.out.println(ex.toString());
} -
How can i display my iviews in anonymous page
hi experts,
I have created some iviews and I have created a role for all these i views and assigned this role to anonymous user group.
when i access the anonymous page,i get the info"contents not exsits or not enabled",well how can i display my iviews in anonymous page
best regards,
zlfThis page may help
http://help.sap.com/saphelp_nw04s/helpdata/en/1e/e19f58136e654d9709befa464314f2/content.htm -
How can I make server use single class loader for several applications
I have several web/ejb applications. These applications use some common libraries and should share instances of classes from those libraries.
But applications are being deployed independently thus packaging all them to EAR is not acceptable.
I suppose the problem is that each application uses separate class loader.
How can I make AS use single class loader for a set of applications?
Different applications depend on different libraries so I need a way that will not share library for all applications on the domain but only for some exact applications.
When I placed common jar to *%domain%/lib* - all works. But that jar is shared between all applications on the domain.
When I tried to place common jar to *%domain%/lib/applibs* and specified --libraries* attribute on deploying I got exception
java.lang.ClassCastException: a.FirstDao cannot be cast to a.FirstDaoHere http://download.oracle.com/docs/cd/E19879-01/820-4336/6nfqd2b1t/index.html I read:
If multiple applications or modules refer to the same libraries, classes in those libraries are automatically shared.
This can reduce the memory footprint and allow sharing of static information.Does it mean that classes should be able to be casted ?You didn't specify which version of the application server you are using, but the config is similar as long as you know what to look for. Basically, you need to change the classloader delegation. Here's how it is done in 8.2
http://download.oracle.com/docs/cd/E19830-01/819-4721/beagb/index.html
Maybe you are looking for
-
windows 8.1 64 bit version 6.3 9600 processor
-
Extending VOs with attributes and creating new treetable columns
Hi, I am relatively new to the ADF scene so please bear with if what I have in my mind is not even possible with ADF. I have searched hi and lo for a solution and now I thoughts it time to ask the community. Anyways this is what I want to do. I have
-
Webdynpro ABAP Examples Related to MM/SD/PP etc Module
Hi Can I get some webdynpro ABAP examples based on MM/SD/PP etc Module. Please give me any link. Thanks Amresh
-
DropDownByIndex and structured Node
Hi, I have defined a structure with a field display of type string. I create a context node from that structure so that I have a node attribute named display of type my_struct-DISPLAY Problem is that I would like to display this attribute in a dropdo
-
Problems resetting login password
I have apparently forgotten my login password for my Mac Air. When following the instructions to reset my password using my Apple ID, step 2 says "In the login window, click the question mark in the password field, and then click the arrow in the di