Open a JFrame from an applet

I have an applet in which I have a JButton.
When you click the button, I want a new window to open with a JFrame. Is that possile?
I've written as follow but nothing happens when I click the button.
1. In the applet, I've written:
public class MyApplet extends Applet {
if (e.getActionCommand() == myButton) {
frame.getContentPane().add(new Blabla(), BorderLayout.CENTER);
2. In the frame, I've written:
public class Blabla extends JFrame {

Thanks.
Now a new window is opened when I click the button, but it's empty....
In the frame I have a container, is that a problem? I don't know where to put "your":
"getContentPane().setLayout(new BorderLayout());"
I've written:
public class Blabla extends JFrame {
boolean inAnApplet = true;
private boolean laidOut = false;
private JButton b1, b2, b3;
private JLabel fnamn;
public Blabla() {
Container contentPane = getContentPane();
contentPane.setLayout(null);
b1 = new JButton("some text");
contentPane.add(b1);

Similar Messages

  • [NEWBIE] How to open a frame from an Applet?

    Hi, I'm trying to open a JFrame from an Applet. Basically, I would like that, once the user selects an option from a JMenu, a Frame would be shown with a text box where user could type some content.
    I built both the Applet and the Frame, and singularly they work. When I execute the main method from the JFrame, the window appears, but when I execute something like the following from the applet:
    MyFrame mf = new MyFrame();
    mf.setVisible(true);nothing is shown. I'm sure that I don't know something, but I just started with applets.
    Thanks for any help,
    Marco

    If MyFrame is a subclass of JFrame, then it should not
    make any difference.
    What do you need the JFrame for? Can this be done
    using another "screen" by using a CardLayout?From a menu, when the user selects 'Start game' I need a text box coming out so that the user can insert a word. This word should then evaluate an instance member of the Applet.
    Marco

  • Opening a browser from an applet

    I got a problem, I want to open a browser from my applet, but I just found one way:
    getAppletContext().showDocument(new URL(
    "http://www.java.sun.com"), "_blank");
    but the problem is: with this, the default browser with defaul settings is opened, and that's what I don't want...
    how can I open the browser with some settings (for example size, or no-url-bar, etc)
    thx for help

    hi,
    try this code:
    public void showDocument(java.net.URL url, String targetWindow)
    when targetWindow can be:
    "_blank" Display the document in a new, nameless window.
    "windowName" Display the document in a window named windowName. This window is created if necessary.
    "_self" Display the document in the window and frame that contain the applet.
    "_parent" Display the document in the applet's window but in the parent frame of the applet's frame. If the applet frame has no parent frame, this acts the same as "_self".
    "_top" Display the document in the applet's window but in the top-level frame. If the applet's frame is the top-level frame, this acts the same as "_self".

  • Opening a socket from an applet

    I tried to open a socket from an applet to a server on a remote computer and I've got a refusal message.
    When I try it on a server in the local machine, it works.
    What could be the problem ?
    P.S. : when I open the socket from an application in the Java environment, to the same remote server it works ok.

    this is part of the security system built into java and Applets
    unless you sign an Applet it cannot do many "dangerous" things, like..
    access the loacl file system
    connect to any server except the server that it came from

  • Opening a frame from an applet

    Hi,
    I want to open a frame in my applet. If I'm using swing, JApplet opening a JFrame, is it possible to keep the frame open if the user browses away from the page that holds the applet?
    Are there any tricks? I've tried opening it in a new Thread, but it still goes away when the the browser's page changes.
    Could I call getParent() from the applet until I get an instance of Frame (which would be the browser) and set my JFrames' parent? Or does that only work with the old Netscape and old AWT Frames?
    I basically want to know if I can keep my JFrame open until the browser is closed. Any ideas or suggestions would be greatly appreciated.
    thank you very much

    Do you want to open a jsp application in a frame when you click on the applet?If so, there is a programme in http://www.globalleafs.com -Java-Java Applets 's download section. Check it out.

  • Open web pages from an applet

    I'm developing an applet that has to open some web pages.
    The only way I know is to use the method showDocument that
    needs and URL. So, how to pass parameters to the web page?
    I don't want to put them in the URL: everyone can see
    "secret data"!
    Help me, please.

    Take a look at this example that uses a JEditor pane to hold the HTML page.
    //Create a new JEditor Pane
    jep = new JEditorPane( );
    //Ensure the pane is not editable
    jep.setEditable(false);  
    //Use this to get local HTML file
    URL fileURL = this.getClass().getResource("Manual/Manual.htm");
    //add the html page to the JEditorPane
    jep.setPage(fileURL);Ok the core line of code here is this.
    URL fileURL = this.getClass().getResource("Manual/Manual.htm");The standard method for accessing a html file via a URL is thus. As you can see its very similar.
    URL fileURL = new URL("http://www.comp.glam.ac.uk/pages/staff/asscott/progranimate/docs/Manual/Manual.htm");this.getClass().getResourse() will return the file location of the class you are working with.
    By doing the following you can access manual.html in a folder called Manual that sits in the same file location as the class file you are using.
    URL fileURL = this.getClass().getResource("Manual/Manual.htm");I hope this helps.
    Andrew.

  • Opening a jsp from an applet in a frame?

    this is the code i'm using to open a new jsp and send some stuff in the header. it works fine but it does not support the frameset i am using... any ideas how i can open this page in the frame?
    thanks
    URL url = getCodeBase();
    try{
    getAppletContext().showDocument (new URL (url+"AcceptHousePos.jsphouse="+myHouse.getString()));
    catch(MalformedURLException e) {
    showStatus("URL not found");

    Do you want to open a jsp application in a frame when you click on the applet?If so, there is a programme in http://www.globalleafs.com -Java-Java Applets 's download section. Check it out.

  • How does one open a JFrame from a JSP or servlet?

    Hi,
    I have a fairly complex Java app that includes a JFrame that I want to integrate into a Web app. Specifically, I want to enable the user to open a dialog window, which is in the form of a JFrame. Can this be done easily? TIA!
    Bob
    Edited by: FractalBob on Jan 4, 2010 7:48 PM

    FractalBob wrote:
    I like option 3, but I don't see how to implement it. For example, my app includes a JTree embedded in a JScrollPane, so the Web app needs to be able to register an event handler to detect selections on the tree. How is that done?Depends on your choice of web framework. JSF is extensible with richfaces which has a tree control among other controls.
    GWT would allow you to write Swing like code complete with listeners e.t.c.
    You should preview and compare a few of them before selecting one. This should be an easy exercise since you already know what the application needs are.

  • How do I open a url from an applet?

    is it done the same way with HTTPUrlConnection as with an application or is it done in a different way? I'm getting a "ClassCastException"

    Now I'm trying to call a CGI script and past things in through the post method... I still get a ClassCastException. This exact same code worked in the applet, once again. here is the code I am using:
                   URL url = new URL ("http://address.pl");
                   HttpURLConnection cxn = (HttpURLConnection) url.openConnection();
                   cxn.setRequestMethod("POST");;
                   cxn.setUseCaches(false);
                   cxn.setDoOutput(true);
                   cxn.setDoInput(true);
                   ByteArrayOutputStream bytes = new ByteArrayOutputStream(400);
                   PrintWriter writer = new PrintWriter (bytes,true);
                   writer.print("hello=world&food=good");
                   writer.flush();
                   cxn.setRequestProperty("Content-Length",String.valueOf(bytes.size()));
                   cxn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
                   bytes.writeTo(cxn.getOutputStream());

  • Opening frames from an applet

    Me and a friend are making an applet, and would like it to open a new frame at some point.
    It works perfectly* on his WIN 2k IE 5.0 but somehow it does not on my WIN 2k IE 6.0
    Is it no longer legal to open new windows from an applet?
    Thanks.
    *Except for the warning. Btw, is that warning removable?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    If the window doesnt show up, you might have an exception thrown somewhere. I assume you are using a Java Plug-In since you are using IE6.0. You can bring up the java console, if you open the Java Plug-In icon in the Control Panel and enable "Show Java Console". Restart your browser and try again and see if you are getting a stacktrace in the java console.You can also see what version of java you are using in the control panel, or change it in the Java Plug-In options (Advanced tab) if you have more than one installation installed.

  • Opening and closing a frame from an applet security problem

    can I open a frame or a window from an applet and close the frame by using
    System.exit(0) for the frame or will it throw a security problem.

    I am using system.exit(0) to exit the JVM.
    dispose()
    Releases all of the native screen resources used by this Window, its subcomponents, and all of its owned children. That is, the resources for these Components will be destroyed, any memory they consume will be returned to the OS, and they will be marked as undisplayable.
    If this frame have to be close and open again don't use dispose.
    there is no check whether a frame is active? what you can do is set the the new frame to null (frame = null) and also when you dispose it, this will let you know if the frame is active or not.
    Noah

  • Print HTML doument without open it from an applet

    I need to know how I can print an HTML document from an applet developed with Jbuilder 4. I'm not a very expert developer and I need a detailed information about this problem. Important is that the HTML document is printed without open it.
    I use: win 2000 pro
    J2RE 1.4.0
    thanks in advance for your help
    Mauro Losa

    Thanks for your help but my problem is that i want print the document without display it.
    I think to have find a solution using Java Print Service API (JDK 1.4) but when i run the example the system display this error refered to this instruction
    "PrintService[] pservices = PrintServiceLookup.lookupPrintServices(flavor, aset);":
    java.lang.UnsatisfiedLinkError: getDefaultPrinterName
    at sun.print.Win32PrintServiceLookup.getDefaultPrinterName(Native Method)
    at sun.print.Win32PrintServiceLookup.getDefaultPrintService(Unknown Source)
    at sun.print.Win32PrintServiceLookup.getPrintServices(Unknown Source)
    at sun.print.Win32PrintServiceLookup.getPrintServices(Unknown Source)
    at javax.print.PrintServiceLookup.getServices(Unknown Source)
    at javax.print.PrintServiceLookup.lookupPrintServices(Unknown Source)
    at untitled4.applet1.main(Applet1.java:32)

  • Open a html page from an applet

    Hi,
    I would like to open, from an applet, an HTML page in a new window with a specific width an eight.
    Who can help me ?

    Here is an example of applet to javascript with liveconnect:
    http://www.narhari.com/java/applet2javascript/
    You can use the send(String) method from the sample applet to send something like:
    window.open('xyz.html','myPopup','width=200,height=200');in order to open a window with specific dimensions
    of course you can also build HTML in your applet and use send() + some javascript to render it.

  • Open web page from applet

    Hi guys,
    I am new to Java applet and I need your help. I want to open a web page (or a servlet) with known URL from an applet when I press a button. I know how to set up HttpURLConnection for the applet. But I don't how to open this web page. Could you please help me? What method I should use?
    Many thanks in advance.
    jh

    getAppletContext().showDocument(URL url)
    You should search the forum and then post over here. Also go through the api.

  • Help! How to Open a Frame from applet with

    Hey all. I need help =).
    I want:
    1. Have 1 class extends applet with running thread (this far no prob)
    2. Open a new frame from the applet (no prob)
    3. Start a new thread which is operating "inside" the new Frame/class
    4. Draw a simple Rect in the new Frame with the new thread to test that the graphics work.
    Plz help,
    ~Trobsky

    �rr..... i cant draw on the Frame =(.
    Heres the code:

    public class Fonster extends java.applet.Applet {
         Frame myFrame;
         Fri friFonster=new Fri();
         public void init() {
              myFrame=new Frame();
              myFrame.resize(300,300);
              myFrame.show();
              myFrame.add(friFonster);
              friFonster.init();
              friFonster.start();
         public void paint(Graphics g)
              g.drawRect(10,10,100,100);
    public class Fri extends java.applet.Applet {
         public void init(){
              repaint();
         public void paint(Graphics g)
              g.drawRect(10,10,200,200);

Maybe you are looking for

  • IPad Notepad / iCloud Notes

    In Notepad / iCloud Notes, I have three accounts:  All Notes, my personal notes and iCloud.  How do I get ALL three of these accounts to sync OR how do I move notes from one account to another?  Right now, only notes that I place on iCloud or sync'd.

  • HT1212 how to reset my ipod touch

    my ipod don't start

  • Tables behind FF7B

    Can someone confirm that behind transaction FF7B when used for liquidity forecast that all of the "drilled down" (most granular) data is contained in tables beginning with FDxxx? I specifically want to know if there are any data contained in structur

  • Summing up subgroup totals

    In below table, the light blue rows, represents the subgroup I am trying to sum up. The value in the "Inventory Value" contains the latest inventory value for said inventory. Light green row is grouped by Store name, Light blue is grouped by inventor

  • Service number creation

    Hi experts, While creating service po it is asking service master na,in that we have to give service number. That service number creation how to do? plz help me guys. Naren