Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #13469 > unrolled thread
| Started by | Maciej Labanowicz <m.labanowicz@gmail.com> |
|---|---|
| First post | 2012-04-11 04:56 -0700 |
| Last post | 2012-04-11 12:18 -0700 |
| Articles | 10 — 8 participants |
Back to article view | Back to comp.lang.java.programmer
[foo.bar.Frame] can not inherit from [java.awt.Frame] Maciej Labanowicz <m.labanowicz@gmail.com> - 2012-04-11 04:56 -0700
Re: can not inherit from [java.awt.Frame] Paul Cager <paul.cager@googlemail.com> - 2012-04-11 05:51 -0700
Re: can not inherit from [java.awt.Frame] Lew <noone@lewscanon.com> - 2012-04-11 08:13 -0700
Re: can not inherit from [java.awt.Frame] Paul Cager <paul.cager@googlemail.com> - 2012-04-11 09:37 -0700
Re: [foo.bar.Frame] can not inherit from [java.awt.Frame] Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2012-04-11 12:59 +0000
Re: [foo.bar.Frame] can not inherit from [java.awt.Frame] markspace <-@.> - 2012-04-11 08:24 -0700
Re: [foo.bar.Frame] can not inherit from [java.awt.Frame] Patricia Shanahan <pats@acm.org> - 2012-04-11 09:34 -0700
Re: [foo.bar.Frame] can not inherit from [java.awt.Frame] markspace <-@.> - 2012-04-11 10:01 -0700
Re: [foo.bar.Frame] can not inherit from [java.awt.Frame] Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-04-11 11:18 -0700
Re: [foo.bar.Frame] can not inherit from [java.awt.Frame] Lew <lewbloch@gmail.com> - 2012-04-11 12:18 -0700
| From | Maciej Labanowicz <m.labanowicz@gmail.com> |
|---|---|
| Date | 2012-04-11 04:56 -0700 |
| Subject | [foo.bar.Frame] can not inherit from [java.awt.Frame] |
| Message-ID | <8d7bedc4-30a8-4dc4-97b6-9ddaafc2e16a@l4g2000vbt.googlegroups.com> |
Hi,
I'm trying to compile simple class, named Frame in package foo.bar:
--[beg]--[Frame.java]-----------------------------------
package foo.bar;
import java.awt.Frame;
public class Frame extends java.awt.Frame {
public static final long serialVersionUID = 1L;
public static void main(String [] args) {
System.out.println("HELLO: args = " + args);
}
}
--[eof]--[Frame.java]-----------------------------------
/> javac Frame.java
Frame.java:2: error: foo.bar.Frame is already defined in this
compilation unit
import java.awt.Frame;
^
1 error
I have also tried with:
- public class Frame extends java.awt.Frame {
+ public class foo.bar.Frame extends java.awt.Frame {
But the error is:
Frame.java:3: error: '{' expected
public class foo.bar.Frame extends java.awt.Frame {
^
1 error
Is there any possibility to create such class in java ?
Regards
--
Maciek
[toc] | [next] | [standalone]
| From | Paul Cager <paul.cager@googlemail.com> |
|---|---|
| Date | 2012-04-11 05:51 -0700 |
| Subject | Re: can not inherit from [java.awt.Frame] |
| Message-ID | <f10bbb58-5fb3-43c1-aea4-452d7f782f05@h5g2000vbx.googlegroups.com> |
| In reply to | #13469 |
On Apr 11, 12:56 pm, Maciej Labanowicz <m.labanow...@gmail.com> wrote:
> /> javac Frame.java
> Frame.java:2: error: foo.bar.Frame is already defined in this
> compilation unit
> import java.awt.Frame;
> ^
> 1 error
That should work. Are you sure you have shown us the whole file?
One problem that would lead to these symptoms is if you had
accidentally duplicated the class declaration in the file, such as
(untested):
package foo;
public class Frame {
// Lots of stuff
}
public class Frame {
// Lots of stuff
}
If that's not the case, which compiler are you using?
[toc] | [prev] | [next] | [standalone]
| From | Lew <noone@lewscanon.com> |
|---|---|
| Date | 2012-04-11 08:13 -0700 |
| Subject | Re: can not inherit from [java.awt.Frame] |
| Message-ID | <jm472q$9g4$1@news.albasani.net> |
| In reply to | #13471 |
On 04/11/2012 05:51 AM, Paul Cager wrote:
> On Apr 11, 12:56 pm, Maciej Labanowicz<m.labanow...@gmail.com> wrote:
>> /> javac Frame.java
>> Frame.java:2: error: foo.bar.Frame is already defined in this
>> compilation unit
>> import java.awt.Frame;
>> ^
>> 1 error
>
> That should work. Are you sure you have shown us the whole file?
No, it shouldn't work.
> One problem that would lead to these symptoms is if you had
> accidentally duplicated the class declaration in the file, such as
> (untested):
>
> package foo;
>
> public class Frame {
> // Lots of stuff
> }
>
> public class Frame {
> // Lots of stuff
> }
>
> If that's not the case, which compiler are you using?
He's using a standards-conforming compiler, which is all that matters in this
case.
--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
[toc] | [prev] | [next] | [standalone]
| From | Paul Cager <paul.cager@googlemail.com> |
|---|---|
| Date | 2012-04-11 09:37 -0700 |
| Subject | Re: can not inherit from [java.awt.Frame] |
| Message-ID | <bd9dfcad-be93-42ab-8ce7-a69b40304ada@m18g2000vbl.googlegroups.com> |
| In reply to | #13480 |
On Apr 11, 4:13 pm, Lew <no...@lewscanon.com> wrote: > On 04/11/2012 05:51 AM, Paul Cager wrote: > > That should work. Are you sure you have shown us the whole file? > > No, it shouldn't work. Ah yes, you're right. I hadn't seen that import.
[toc] | [prev] | [next] | [standalone]
| From | Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> |
|---|---|
| Date | 2012-04-11 12:59 +0000 |
| Message-ID | <slrnjob01i.kvi.avl@gamma.logic.tuwien.ac.at> |
| In reply to | #13469 |
Maciej Labanowicz <m.labanowicz@gmail.com> wrote:
> I'm trying to compile simple class, named Frame in package foo.bar:
> --[beg]--[Frame.java]-----------------------------------
> package foo.bar;
> import java.awt.Frame;
This import statement tells the Java compiler, that when it
encounters a bare Frame literal, that it should consider that
from java.awt.Frame. This obviously cannot work, if you have
a different class Frame (foo.bar.Frame) already.
Solution 1 would be to call your class differently, like MyFrame
Solution 2 would be to remove the "import" statement for java.awt.Frame.
After doing so, ...
> - public class Frame extends java.awt.Frame {
this one ought to work.
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2012-04-11 08:24 -0700 |
| Message-ID | <jm47nd$6en$1@dont-email.me> |
| In reply to | #13469 |
On 4/11/2012 4:56 AM, Maciej Labanowicz wrote:
> Frame.java:2: error: foo.bar.Frame is already defined in this
> compilation unit
I *think* what the compiler is saying using Frame as an unqualified name
collides with the existing foo.bar.Frame usage.
The solution is just to not use the "import" statement.
package quicktest;
class Frame extends java.awt.Frame {
public static final long serialVersionUID = 1L;
public static void main(String [] args) {
System.out.println("HELLO: args = " + args);
}
}
If your compiler can find "import java.awt.Frame", then it can find
java.awt.Frame without the import. You don't need import, it just
allows you to shorten the FQN to just the class name.
[toc] | [prev] | [next] | [standalone]
| From | Patricia Shanahan <pats@acm.org> |
|---|---|
| Date | 2012-04-11 09:34 -0700 |
| Message-ID | <77CdnRMKBtckLxjSnZ2dnUVZ_tGdnZ2d@earthlink.com> |
| In reply to | #13481 |
On 4/11/2012 8:24 AM, markspace wrote:
> On 4/11/2012 4:56 AM, Maciej Labanowicz wrote:
>
>> Frame.java:2: error: foo.bar.Frame is already defined in this
>> compilation unit
>
>
> I *think* what the compiler is saying using Frame as an unqualified name
> collides with the existing foo.bar.Frame usage.
>
> The solution is just to not use the "import" statement.
>
> package quicktest;
>
> class Frame extends java.awt.Frame {
> public static final long serialVersionUID = 1L;
> public static void main(String [] args) {
> System.out.println("HELLO: args = " + args);
> }
> }
>
> If your compiler can find "import java.awt.Frame", then it can find
> java.awt.Frame without the import. You don't need import, it just allows
> you to shorten the FQN to just the class name.
I think a better solution would be to rename foo.bar.Frame. If it did
not have some functional difference from java.awt.Frame, it would not
exist. Presumably, it is Frame specialized in some way, and its name
should indicate that specialization.
Patricia
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2012-04-11 10:01 -0700 |
| Message-ID | <jm4ddl$aqn$1@dont-email.me> |
| In reply to | #13484 |
On 4/11/2012 9:34 AM, Patricia Shanahan wrote: > I think a better solution would be to rename foo.bar.Frame. If it did > not have some functional difference from java.awt.Frame, it would not > exist. Presumably, it is Frame specialized in some way, and its name > should indicate that specialization. Well, its full name "foo.bar.Frame" should indicate its specialization. A better name like com.application.main.Frame would be a more likely choice if this weren't a quick example on the internet. In general I don't have a problem with using common words as class names in different packages. It actually adds to clarity in many cases. OTOH, if the actual use of foo.bar.Frame and java.awt.Frame gets to be a pain to deal with, then it certainly should be renamed. Confusion or even just convenience is a sufficient reason for refactoring the name of a class.
[toc] | [prev] | [next] | [standalone]
| From | Daniel Pitts <newsgroup.nospam@virtualinfinity.net> |
|---|---|
| Date | 2012-04-11 11:18 -0700 |
| Message-ID | <YVjhr.15938$5m.2162@newsfe20.iad> |
| In reply to | #13469 |
On 4/11/12 4:56 AM, Maciej Labanowicz wrote:
> Hi,
>
> I'm trying to compile simple class, named Frame in package foo.bar:
>
> --[beg]--[Frame.java]-----------------------------------
> package foo.bar;
> import java.awt.Frame;
> public class Frame extends java.awt.Frame {
> public static final long serialVersionUID = 1L;
> public static void main(String [] args) {
> System.out.println("HELLO: args = " + args);
> }
> }
> --[eof]--[Frame.java]-----------------------------------
As others have pointed out, the problem is that you import Frame. you
don't need to import something if you use the fully qualified name.
A side note, extending Frame is probably not what you really want to do.
It is unfortunate that so many examples and tutorials have you do this,
but in reality, you just need to compose a Frame with the various
Components you need. For the most part, the only time you need to
extend *any* Component or JComponent is when you are creating a custom
view of a specific type of data. And then you should only extend
JComponent or Canvas as I understand it.
hth,
Daniel.
[toc] | [prev] | [next] | [standalone]
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Date | 2012-04-11 12:18 -0700 |
| Message-ID | <25298982.124.1334171886562.JavaMail.geo-discussion-forums@pbje9> |
| In reply to | #13487 |
Daniel Pitts wrote:
> Maciej Labanowicz wrote:
>> I'm trying to compile simple class, named Frame in package foo.bar:
>>
>> --[beg]--[Frame.java]-----------------------------------
>> package foo.bar;
>> import java.awt.Frame;
>> public class Frame extends java.awt.Frame {
>> public static final long serialVersionUID = 1L;
>> public static void main(String [] args) {
>> System.out.println("HELLO: args = " + args);
>> }
>> }
>> --[eof]--[Frame.java]-----------------------------------
> As others have pointed out, the problem is that you import Frame. you
> don't need to import something if you use the fully qualified name.
>
> A side note, extending Frame is probably not what you really want to do.
> It is unfortunate that so many examples and tutorials have you do this,
> but in reality, you just need to compose a Frame with the various
> Components you need. For the most part, the only time you need to
> extend *any* Component or JComponent is when you are creating a custom
> view of a specific type of data. And then you should only extend
> JComponent or Canvas as I understand it.
This raises another question, OP: Why do you use 'java.awt.Frame' instead of 'javax.swing.JFrame'?
--
Lew
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web