Subclass with interface can't be used in place of superclass?
So I've searched through the forums and haven't found much of a real answer to this yet--at least, the keywords I tried resulted in nothing. This should also be a quickie--it seems pretty simple, but I'm stumped after spending so long working.
So the problem is as follows. I need to ensure that certain Swing components in my application always implement a certain set of methods, so naturally this lends itself to an interface. I don't think an abstract class would be necessary in this case since these objects are going to be pretty radically different from each other in terms of function.
I create my interface, we'll call it "Presentation". I create an object "PaintingPanel" which implements the interface, and since I'll need to add it to my Swing application, I have it extend JLabel, or some other JComponent.
I thought this would work, however, JBuilder complains about the following lines of code. The instantiation is fine, but adding it gives me trouble.
Presentation myPres = new PaintingPanel();
myJPanel.add(myPres);What am I doing wrong exactly? Should I scrap the interface then and go with an abstract class? I can't just cast this, can I?
Thanks in advance.
I don't have a "this is the right way to do it" answer for you, but look at it this way.
First, you're saying "Presentation myPres..." so all you're promising about myPres is that it "is-a" Presentation, and that it "is-a" everything the Presentation extends/implements.
Then you want to call JPanel.add(myPres), but JPanel.add requires a Component (I think). As far as the compiler knows, myPres is a Presentation, which, since it doesn't extend Component, "isn't-a" Component.
There are a couple things you could do.
* Declare it as MyClassThatImpelmentsPresentationAndExtendsComponent or whatever it is. If you're expecting to treat this thing as both a Presentation and a Component, this seems to make the most sense.
* Cast it, as stevejluke suggested.
* Call add(myPres.getComponent()), where the getComponent is a method you add in case you[i] don't want all your Presentation implementations to have to extend Component, but[i] do want to be able to use the Presentation (or something associated with it) in a Component context. For those Presentation implementations that do extend Component, you can just have the method return this.
There are probably other options, depending on your actual requirements. No matter what though, the key is to be driven by the fact that add requires a Component, so you need some way to guarantee the compiler that that's what you're passing.
Similar Messages
-
with CC can i still use all the machines or do i have to take out an individual license for each?
Your LR5 license allows for activated installations on two machines. Of those two machine, only one can be using the licensed software at a given time. The same applies with CC, except with CC you won't be able to sneak in the third machine. What you can do though with CC is have it installed on all three and sign in and out of the different machines as needed.
If you intend to be using all three machines at the same time then you do need three separate licenses/subscriptions to be in compliance with the license agreement. -
If I plug a guitar into iPhone GarageBand using an interface, can I still use the built in microphone to record vocals and guitar at the same time?
Hi John,
I think the only way is to get an iMic...
http://www.bhphotovideo.com/bnh/controller/home?O=&sku=797644&is=REG&Q=&A=detail s -
Hi, I have creative cloud on mac
with photoshop, Can I use this on another PC I have with paying for it again?As long as you only run one at a time, you can.
-
I was setting up an account on the time capsule so I can have other people have their own private folder. My question is, Can I still back up my data on my time capsule by using time machine?
Sorry the account feature is irrelevant.. You do not want to use it.. you can migrate your data to your computer.. The account feature is not needed, required, useful or anything to do with restoring your files..
You use account access to stop everybody being able to see your files.. the problem is.. it is not itself secure.. so if i get hold of your TC I can delete your accounts with a soft reset and access all your files.. so it is useless.. don't bother using it.. ignore it.. !!
If you wish to have secure backups use the Time Machine Encrypt backup feature. -
If upgrade from CS2 to CS 3 can I still use GoLive ?
If I upgrade from CS2 to CS3 with Dreamweaver, can I still use/run GoLive to maintain existing GoLive files for a time, until I make the transition ?, or once I install CS3 I need to transition right quick ?
thanks if anyone knows the answer to this ... Laura> In my case, once I installed and activated CS3 my CS2 apps stopped working. Was GL CS2 excluded from this shutdown?
What do you mean by stopped working? Did you get an error message when launching the apps?
John -
Hi,
I have to communicate CANopen device with other CAN device which uses GMLAN.
So in general, How do I communicate CANopen device with anyother CAN device?
What things needs to be made compatible with 2 CAN devices (i.e, one is CANopen and anyother CAN device) to communicate?
Please reply.
Thanks,
NajmuHello,
The two devices need to be connected with a CAN cable and while carrying out the communication, one device should be the master and the other should be the slave. Also you should maintain the same protocol (Baud rate, Arbitration ID etc.) at the two devices.
Regards
Akshat Jain -
Can evgts be used to pull a total based on a property value?
can evgts be used to pull a total based on a property value?
for example evgts(act,cc,pc,,time,acct.property='PPE")Hi Steven,
I assume you want to "EVGTS" the total value af accounts whose property is "PPE". This is not possible as any retrieval requires value readily available from the cube.
In such case you may need to use dimension formula (calculated account) to roll up data based on property. Quick and dirty option is to fetch the data with EVDRE (can only be used with small quantities of data) and summarize on the worksheet.
Hope this helps,
Madis -
I am facing problem regarding graphical user interface. I am using text box for editing files. I want to show the line numbers and graphical breakpoints along with text box. Can anybody help me in this? Thanks.
Thanks for you reply.
But actually I don't want to show the \ (backslashes) to the user in my text box.
Ok let me elaborate this problem little more.
I want to show my text box as it is in normal editors e.g. In Matlab editor. There is a text box and on left side the gray bar shows the line numbers corresponding to the text. Further more i want that the user should be able to click on any line number to mark specific line as breakpoint (red circle or any graphical indication for mark).
Regards,
Waqas Ahmad -
GroupLayout can only be used with one Container at a time
Dear all,
I am a beginner so please don't throw rocks at me...
I have created two frames with NetBeans. One is the main frame (extends from JPanel) and the other frame I put it to be started when pressing a button from the main frame (the second frame extends from JFrame). Both frames are created using the designer in NetBeans, so the code for creating the GUI is automatically generated by NetBeans, so both frames use the same layout (GroupLayout).
Here is the code of the button from the main frame to start the second one:
private void manageCustomersActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
CustomerGUI custGUI1=new CustomerGUI();//CustomerGUI is the second frame
custGUI1.setVisible(true);
}When I press this button from the main frame I get this runtime exception: Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: GroupLayout can only be used with one Container at a time. The second frame is not opened.
How should I handle this?
What I want to do: I want to have a main frame, from which I can start additional ones (the main frame must be always opened, while the additional ones can be closed after performing certain actions). I read a little about internal frames and I think this can be a solution, but I must edit the existing design...
Thank you
With respect,
Don
Edited by: don1983p on Dec 16, 2008 2:21 AMAndrewThompson64 wrote:
There are those that maintain that JFrame should never be extended. I am not convinced, but most cases where a JFrame is extended would be better coded as simply configuring the JFrame within the main(). GUI builders such as found in NetBeans seem to extend JFrame as a matter of course.I too am not rigorous or religious about this either, but try to adhere to this as a matter of practicality and convenience, I find that if I don't extend a JComponent but rather use composition rather than inheritance, it's much easier to use objects of my class when programming in Eclipse. For instance in Eclipse (and in most IDEs), if I type my object name and then a period, it will show all of the method's available for me to use on this object. If I subclass JPanel or JFrame, I'll see a gazillion methods most I don't want to see, and thus most are clutter. On the other hand if I use composition, I'll only see a small number of methods and these will be only the methods that I want to see and need to use. -
Fedex can only be used with dreamweaver using metric, not pounds (lbs)
Fedex can only be used with dreamweaver using metric, not pounds (lbs), evidently?
This as per their tier 2 tech suport.
They say I should just convert to metric, no joke!
Any ideas would be greatly appreaciated?
Also a warning to anyone thinking of using business catalyst for their site, sorry, their business.
Their note to me:
Your request (# 82816) has been solved. To reopen this request, reply to this email or go to the Help & Support page.
Silviu Ghimposanu (Adobe Business Catalyst Support)
Apr 14 15:23
Thanks for contacting us Michael
Our engineering team has detected some problems when doing weight conversions (from the quantities entered in the interface to what’s used when making the API calls to FedEx) -
He have added this to our internal bug tracker to be fixed for one of the future releases.
I realise that this might not be what you wanted to hear,but at this moment we do't have a workaround in order to send the
dimensions in pounds and not in KG
Sorry for this inconvenience!
Kind regards,If you're in US it will be in pounds. If your site is set any other country
in the rest of the world it will be metric. So BC or as you call it
Dreamweaver will look at the site country, which you set when creating the
site -
WLC CT2504: Interface IP can not be used as internal DHCP server IP
Hello all,
I've got a new CT2504 controller with software version 7.0.220.0
Regarding to
http://www.cisco.com/en/US/products/ps6366/products_tech_note09186a0080af5d13.shtml
I've tried to configure the internal DHCP on a dynamic-interface, but this is not possible:
(Cisco Controller) >config interface dhcp dynamic-interface vlan401 primary 172.16.x.3
vlan401 Interface IP can not be used as internal DHCP server IP
It works, if I use another IP (aka DHCP server) in the same subnet or in another subnet. It works also for the management interface.
(Cisco Controller) >show interface detailed management
Interface Name................................... management
MAC Address...................................... d0:c2:82:xx:xx:xx
IP Address....................................... 10.2.x.135
IP Netmask....................................... 255.255.255.240
IP Gateway....................................... 10.2.x.129
External NAT IP State............................ Disabled
External NAT IP Address.......................... 0.0.0.0
VLAN............................................. 400
Quarantine-vlan.................................. 0
Active Physical Port............................. 1
Primary Physical Port............................ 1
Backup Physical Port............................. Unconfigured
Primary DHCP Server.............................. 10.2.x.135
Secondary DHCP Server............................ Unconfigured
DHCP Option 82................................... Disabled
ACL.............................................. Unconfigured
AP Manager....................................... Yes
Guest Interface.................................. No
L2 Multicast..................................... Disabled
Scopes are defined and Proxy is enabled.
(Cisco Controller) >show dhcp summary
Scope Name Enabled Address Range
ap Yes 10.2.x.137 -> 10.2.x.140
intern Yes 172.16.x.20 -> 172.16.x.30
(Cisco Controller) >show dhcp proxy
DHCP Proxy Behaviour: enabled
Has somebody an explanation for this issue?
Thanks in advance,
Regard,
RobertYou can use the internal dhcp, but you need to set the primary dhcp as the management ip. So in your dynamic interface, your primary dhcp is configure with the wlc management ip address. Dhcp proxy also needs to be enabled and is enabled by default.
Thanks,
Scott Fella
Sent from my iPhone -
the problem I have since I upgraded to Mavericks version 10.9.1
The problem appears only with Mail not with other programs, not even with my browser.
When I try to zoom the text of an e-mail I received or sent , I can no longer use the keys Command + to enlarge the text, although I can reduce it with Command -.
As I have a problem with my eyes, This is a serious matter for me.
When I write an e-mail, if I select text and press Command +, it just displaces the text to the right.
Now, my husband has a USB keyboard. If he connects it to my computer, his regular Command + does not work either, but he uses the extended keyboard, then it works. Unfortunately, he needs it for a musical application which does not work with a wireless keyboard.Firefox 3.6.4 and 3.6.6 use a process called, "plugin-container.exe" which was using up most of my CPU when I opened up multiple tabs that contained Adobe Flash files, and caused Firefox to lock up.
My solution was to use Firefox 3.5.10 which you can get from the Mozilla website at [http://www.mozilla.com/en-US/firefox/all-older.html]
I am using Adobe Flash 10.1.53.64 without any problem in this version of Firefox. Check the release notes, I believe it contains all the latest security fixes in "Firefox 3.6.4".
Hopefully, they will fix Firefox 3.6 in the next version (e.g. Firefox 3.6.7), until then you should probably use "Firefox 3.5.10". -
Hi, my MacBook Air is not working anymore if it's not connected with the power cable. It's pretty new so I can't imagine that the battery is dead already. Why can't I use my MacBook Air without the power cable even though I charged it for hours?
Please take the Mac to Apple store to have it checked out.
Genius Bar reservation
http://www.apple.com/retail/geniusbar/
Best. -
I dropped my 17" macbook pro and the screen is broken. Can I still use it with an external monitor? When I plugged it into a monitor I had used it with before, I'm not able to see anything on the macbook screen to control it. It came on but I just got the blue screen with nothing else after typing in my password. (Didn't see the password form just assumed it was there somewhere and it did go from space to blue screen but no desktop icons, files, dock strip at top or anything else, just blank blue screen) so I can't access the system preferences.
Or can I / or how do I, transfer hard drive files to my mac mini? If not salvageable as is can I pull out the hard drive and make it an external harddrive? In otherwords is anything salvageable? It seems it's coming on I just can't access anything. BTW I was told it would cost aprox $1000 to replace the screen! I paid almost $4000 for this thing and it was running great - makes me sick to lose it!I'd like to promise you that everything will be fine if you just get the monitor going - but it's hard to know what the hardware damage might be. It might be the monitor, or the damage might be greater.
Your best solution would be visit your local Apple Store and let them know what your situation is. They have access to diagnostics you don't, and they might be able to the best way to save your data and keep you computing. It's still not covered, but they can tell you what your current options are.
Um, you might consider investing in a backup drive.
And there other repair options, too. Powerbook Medic http://www.powerbookmedic.com/xcart1/pages.php?pageid=67 offers reliable repairs, and quotes prices well under Apple's.
Maybe you are looking for
-
IPhone 6 Plus IOS v8.1 Slow Motion BROKEN
Film in either of the two slow motion speeds and plays back ok on phone. I put the files in the computer (grab the raw file via explorer), on Win 7 Professional, and played with both windows media player AND Quicktime player (up to date players) and
-
Remote.app -No gesture control TV (Gen1)
I've deleted and re-added my iTunes library on the TV as well as deleting and re-adding my iPhone 4S as a remote and still do not have the option to gesture control within the App. AppleTV says it's software is up to date and this is with the curren
-
Error when connect to OracleDB (RAC)
Hi all I've installed Oracle RAC 10.2.0.3 for sun 64 bit When I connect to this server sometime (~20%) it appear error (80% is OK) Oracle client: Oracle 9i client Oracle client tool: sqlplus, SQLNav5.... Test on some pc, server Network from client to
-
After prompted to update 10.9.1, my MacBook Pro updates and went thru restart but failed...I tried to start my book and gray screen, Apple logo both on, chime sounded, then went to progress bar, less than half macbook shuts down...did few times, same
-
Hi dear people, I have a problem with installing a font in Mountain Lion (10.8.2). It is a TTF font called Segoe UI. The weird thing is that the preview in the Finder shows the font correct, but as soon I try to install it shows arabic looking charac