Can I create a JAR that is an Applet and Desktop app at the same time?

Hi mates.
Can I create a JAR that is an Applet and Desktop app at the same time?
Thanks.

Ricardo_Ruiz_Lopez wrote:
..I have one problem, I want a JMenuBar but I can't add it inside a jPanel.
Any idea?
SSCCE
It can be compiled/run as an applet or application something like this (e.g. for a Win command prompt).
C:\Users\Andrew\Hybrid> javac Hybrid.java
C:\Users\Andrew\Hybrid> java Hybrid
C:\Users\Andrew\Hybrid> appletviewer Hybrid.java
C:\Users\Andrew\Hybrid> // YES the previous line requires a '.java'  suffix - trust me.  ;-)Code
// <applet code='Hybrid' width='600' height='400'></applet>
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
public class Hybrid extends JApplet {
    public void init() {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                GUI gui = new GUI();
                getContentPane().add( gui.getMainPanel() );
                setJMenuBar( gui.getMenuBar(false) );
                validate();
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JFrame f = new JFrame("Test Hybrid");
                f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
                GUI gui = new GUI();
                f.setContentPane(gui.getMainPanel());
                f.setJMenuBar(gui.getMenuBar(true));
                f.pack();
                f.setLocationRelativeTo(null);
                f.setVisible(true);
class GUI {
    private JPanel mainGui = null;
    private JMenuBar menuBar = null;
    public JPanel getMainPanel(){
        if (mainGui==null) {
            mainGui = new JPanel( new BorderLayout(3,3) );
            mainGui.setBorder( new EmptyBorder(5,5,5,5) );
            JToolBar tb = new JToolBar();
            for (int ii=1; ii<6; ii++) {
                tb.add( new JButton( "Btn " + ii) );
                if (ii%2==0) {
                    tb.addSeparator();
            mainGui.add(tb, BorderLayout.NORTH);
            mainGui.add( new JSplitPane(
                JSplitPane.HORIZONTAL_SPLIT,
                new JScrollPane(new JTree()),
                new JTextArea(20,20)
                ), BorderLayout.CENTER );
            mainGui.add(new JLabel("Main user interface.."), BorderLayout.SOUTH);
        return mainGui;
    public JMenuBar getMenuBar(boolean isFloating) {
        if (menuBar == null) {
            menuBar = new JMenuBar();
            if (isFloating) {
                JMenu fileMenu = new JMenu("File");
                fileMenu.add( new JMenuItem("Exit") );
                menuBar.add( fileMenu );
            JMenu helpMenu = new JMenu("Help");
            helpMenu.add( new JMenuItem("About") );
            helpMenu.add( new JMenuItem("Help") );
            menuBar.add( helpMenu );
        return menuBar;
The code is not intended to be well designed. It is just written to be brief and demonstrate a few points.
Edit 1:
Added some access keywords in a passing gesture that the sample aimed at encapsulation.
Edited by: AndrewThompson64 on Sep 2, 2010 1:34 PM

Similar Messages

  • HT201338 adaptor that accepts both VGA and ethernet cables at the same time that can be plugged into the Thunderbolt port

    I have my Apple cinema display connected to my MacBook Air via the Thunderbolt port, but I also want to connect an ethernet cable.
    Is there an adaptor that accepts both VGA and ethernet cables at the same time that can be plugged into the Thunderbolt port

    I have my Apple cinema display connected to my MacBook Air via the Thunderbolt port, but I also want to connect an ethernet cable.
    Is there an adaptor that accepts both VGA and ethernet cables at the same time that can be plugged into the Thunderbolt port

  • Can I run a podcast and an app at the same time?

    Can I run a podcast and an app at the same time?

    Yes for most.  You can run a regular app with an audio podcast.  I do not know what could run with a video podcast.

  • Can i add two country holiday on my iCal and see them at the same time?

    Can i add two country holiday on my iCal and see them at the same time? HOW?

    Just subscribe to the appropriate calendars: you can subscribe to as many as you like.
    http://www.apple.com/downloads/macosx/calendars/

  • How can I display my ipad on a remote screen and charg it at the same time

    I need to display my ipad on a remote screen for 10+ hours a day so I need to be able to charge it at the same time. Is this possible?

    The best way to charge the iPad is with its included AC charger. If it is not doing something energy intensive, it can be charged and used at the same time and not deplete the battery, especially if services that are not being used are turned off.
    Can you share more about the situation or environment in which you want to employ the iPad and which model you want to use? The new iPad consumes more energy and takes longer to charge the battery than the iPad 2.

  • How can I create a link to a pdf file and show it in the same webpage or in a new tab

    It is no problem to create a link. But the formats are limited and  - unbelievable -  the pdf format is not supported??!
    Where are the parameter (_blank or _self) to show it for example in the same webpage or in a new tab??!

    PDF is media.  It is not a web document.  Your end users must have plug-ins and helper apps installed on their device to see PDFs in browsers.  Depending on their settings, the PDF file may or may not launch in the browser window.  On my system, PDF files download and launch inside Acrobat Professional; not my browser.
    The safest approach is to provide a screenshot on your page with a direct link to the PDF file so people can handle it as they wish.  See example:  http://www.adobe.com/manufacturing/3dpdfsamples/3dsolutions/
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists 
    http://alt-web.com/

  • Can I use FaceTime and other apps at the same time

    I want my kids to read a book using one ap while they talk to their grandma on FaceTime. Is there a way to do this?

    No. Just talk to grandma. Read a book when she's not available.
     Cheers, Tom

  • Can you create a template that has a header and footer to forms?

    Can you create a template that has a header and footer to forms?

    Yes but how are they going to create the Landscape versions?
    The problem with doing it in Pages '09 as rotated content is that the Headers and Footers are not rotated and there is inherent clumsiness in the rotated content usually being too large for the page when viewed at 90°.
    Best to make it in two or more separate documents.
    Peter

  • Can I create a separate icloud account for my husband but still use the same itunes account?  I want our contacts, photos and storage capacity to be separate but be able to share music and apps we purchase.

    can I create a separate icloud account for my husband but still use the same itunes account?  I want our contacts, photos and storage capacity to be separate but be able to share music and apps we purchase.

    Welcome to the Apple community Pammy.
    Yes, that's exactly what I'd suggest for the vast majority of users.

  • Hello i hav an ipad mini and i was in the middle of the ios 8 update and i held the sleep and home button at the same time to cancel the update and now it wants me to connect to itunes i dont no how to do that can someone pleaze help me

    hello i hav an ipad mini and i was in the middle of the ios 8 update and i held the sleep and home button at the same time to cancel the update and now it wants me to connect to itunes i dont no how to do that can someone pleaze help me?

    RECOVERY MODE
    1. Turn off iPad
    2. Turn on computer and launch iTunes (make sure you have the latest version of iTune)
    3. Plug USB cable into computer's USB port
    4. Hold Home button down and plug the other end of cable into docking port.
    DO NOT RELEASE BUTTON until you see picture of iTunes and plug
    5. Release Home button.
    ON COMPUTER
    6. iTunes has detected iPad in recovery mode. You must restore this iPad before it can be used with iTunes.
    7. Select "Restore iPad"...
    Note:
    1. Data will be lost if you do not have backup
    2. You must follow step 1 to step 4 VERY CLOSELY.
    3. Repeat the process if necessary.

  • HT1550 I'm having trouble with importing them into iTunes and converting them at the same time. when i hold down option over the files i can't find where its supposed to say create new version. is this if you're in iTunes?

    I'm having trouble with importing them into iTunes and converting them at the same time. when i hold down option over the files i can't find where its supposed to say create new version. is this if you're in iTunes?

    You can't do it in one step. Add to iTunes first, Once the tracks are in iTunes you may convert to a different format.
    tt2

  • IS there a way to load and purchase different photos from iPhoto and ship them at the same time? the only way that I can find is to purchase each photo (or multiple of one) at a time, which increases the cost of shipping, as I want to get one print of 20

    Is there a way to order multiple different prints in any quantity from Iphoto? it appears currently like I would have to ship each separately, even if only one print... is there a way around this so I can can get several DIFFERENT prints of any quantity and ship all at the same time?

    Sure - easiest way is to make an album for photos you want to order and drag photos to it - when it is complete open the album, select all and order
    LN

  • How can I connect to Oracle and SQL server at the same time?

    I have been trying to find a way to connect to Oracle Database through the developer 2000 and SQL server at the same time. I need to return some data from Oracle Database and some from the Sql Server Database. And update both through SQL. I find there is such a thing as the Oracle Transparent Gateway for SQL server. I can't find it on any of my CD's or through OTN downloadable files. If anyone can point me where to get this. Or tell of another way this can be accomplished I would appreciate it. TIA.
    [email protected]

    I have been trying to find a way to connect to Oracle Database through the developer 2000 and SQL server at the same time. I need to return some data from Oracle Database and some from the Sql Server Database. And update both through SQL. I find there is such a thing as the Oracle Transparent Gateway for SQL server. I can't find it on any of my CD's or through OTN downloadable files. If anyone can point me where to get this. Or tell of another way this can be accomplished I would appreciate it. TIA.
    [email protected]
    As far as I know you have 3 options depending on your specifications. I don't think option #3 will work if you need to actually join a
    SQL Server table to an Oracle table.
    1. Oracle Transparent Gateway. I haven't used the Oracle Transparent Gateway but my understanding is that Oracle gateways are
    separate purchased products from Oracle. I've never seen any free/development versions of it anywhere. You'll need to contact
    your Oracle sales rep about it.
    2. Heterogeneous Connectivity. There's something called Heterogeneous Connectivity that could work for you - depends on what
    version of Oracle you're on and what OS. You basically set up an ODBC data source on the Oracle server and modify the listener.ora
    and tnsnames.ora files. You can then create a database link to SQL Server just like you would to any other Oracle database. You can
    check your Oracle documentation for how this works. There's also some very good documents on Metalink that tell you how to do this
    as well as a Heterogeneous Connectivity forum on this site.
    3. Use the exec_sql package available in Developer 2000. This allows you to open and execute cursors to remote databases within
    Developer. We have an account validation process that uses this - when a person enters an account number in a form while logged
    into Oracle it validates the account is valid in our main accounting DB2 database. We also pull HR information from DB2 into Oracle
    this way. If you're using Forms 6i exec_sql is a built-in command, in Forms 5.0 and 5.5 you have to add it as an attached library to
    the form. I think you also need the OCA options installed from the Developer software to have access to the library in Forms 5.0 and
    5.5. The library will be in the $ORACLE_HOME\oca20\plsqllib directory for these versions. The Developer documentation should have
    additional information.
    HTH

  • How can I do to acquire and save date in the same time and in the same file when I run continual my VI without interrupti​on.

    I've attached a VI that I am using to acquire amplitude from Spectrum analyzerse. I tried to connect amplitude ouput to the VI Write Characters To File.vi and Write to Spreadsheet File.vi. Unfortunately when I run continual this VI without interruption, labview ask me many time to enter a new file name to save a new value.
    So, How can I do to aquire and save date in the same time and in the same file when I run continual my VI for example during 10 min.
    Thank you in advance.
    Regards,
    Attachments:
    HP8563E_Query_Amplitude.vi ‏37 KB

    Hi,
    Your VI does work perfectly. Unfortunately this not what I want to do. I've made error in my last comment. I am so sorry for this.
    So I explain to you again what I want to do exactly. I want to acquire amplitude along road by my vehicle. I want to use wheel signal coming from vehicle to measure distance along road. Then I acquire 1 amplitude each 60 inches from spectrum analyzer.
    I acquire from PC parallel port a coded wheel signal coming from vehicle (each period of the signal corresponds to 12 Inches). Figure attached shows the numeric signal coming from vehicle, and the corresponding values “120” and “88” that I can read from In Port vi.
    So I want to acquire 1 time amplitude from spectrum analyser each 5
    period of the signal that I am acquiring from parallel port.
    So fist I have to find how can I count the number of period from reading the values “120” and “88” that I am acquiring from In Port (I don’t know the way to count a number of period from reading values “120” and “88”).
    Here is a new algorithm.
    1) i=0 (counter: number of period)
    2) I read value from In Port
    3) If I acquire a period
    i= i+1 (another period)
    4) If i is multiple of 5 (If I read 5 period)
    acquire 1 time amplitude and write to the same
    file this amplitude and the corresponding distance
    Distance = 12*i). Remember each period of signal
    Corresponds to 12 Inches).i has to take these
    values: 5,10,15,20,25,35,40,45,50,55,60............
    5) Back to 2 if not stop.
    Thank you very much for helping me.
    Regards,
    Attachments:
    Acquire_Amplitude_00.vi ‏59 KB
    Figure_Algorithm.doc ‏26 KB

  • Can i listen to i tunes and use another app at the same time on ipad 4 ?

    I've been trying to figure out how to listen i tunes, or listen to music on a web music site, and play a game at the same time, is that possible to do on an iPad 4 ?

    I can listen to Tunein Radio and play Coin Dozer and Burst Bubble at the same time.
    I can also play music on iTune an play Coin Doser and Bubble Burst at the same Time.

Maybe you are looking for

  • How to authorize my macbook air

    Ive looked at the other questions related to the same thing, i know i need the menu bar and i need to go to store but how do i get my menu bar to appear with the latest version of iTunes. i tried pressing the alt key or control and neither worked. pl

  • Oracle Solaris 10 x86 64bit Client Installation Possibly Missing A File

    Does anyone know if the download at: http://www.oracle.com/technology/software/products/database/oracle10g/htdocs/10201solx8664soft.html named: 10201_client_solx86_64.zip (551,795,800 bytes) (cksum - 2931690409) Should have a file named oraparamsilen

  • AirPlay on iPad 3

    When I double click the start button and swipe to the right, there is no longer an airplay button. I'm on the same network as my Apple TV any ideas? 

  • Share Button Not Showing up in Album View

    I've been trying to figure out how to send multiple photos via e-mail or mms on my iPhone 4 when I realized there is NO share button appearing anywhere on the screen when I open the Photo app. Does anyone know how to make this show up? Edit: Just to

  • Looking up Serial Number or other details of my stolen macbook

    Hello, My house was broken into last week and my macbook was stolen. I have insurance but I don't have any of the details of my macbook (stupid, I know). I bought it second-hand but brand-new in January 2008, so I don't have a reciept. I've moved cou