Simple dialog in an applet

what is the easiest way to make a popup window in a java applet? (1.1 compat)
I haven't done Java for like 5 years so be gentle! :-)
Thanks

JDialog is fairly simple to use.
Here's a simple example of one I used as an about-dialog. As you can see, the imports take nearly as many lines as the code...
import javax.swing.JDialog;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.Frame;
import java.awt.Container;
import java.awt.BorderLayout;
import java.awt.Point;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class AboutDialog extends JDialog implements ActionListener
    public AboutDialog(Frame parent)
        super(parent, "AboutDialog...", true);
        setSize(450,350);
        Point p = parent.getLocationOnScreen();
        setLocation(p.x+50, p.y+50);
        Container pane = getContentPane();
        pane.setLayout(new BorderLayout());
        JPanel jps = new JPanel();
        JButton okButton = new JButton("Ok");
        okButton.addActionListener(this);
        jps.add(okButton);
        String about = "Write anything you want here";       
        pane.add(jps, "South");
        JTextArea ta = new JTextArea(about);
        ta.setFont(new Font("Courier", Font.PLAIN, 12));
        pane.add(new JScrollPane(ta), "Center");
    public void actionPerformed(ActionEvent e)
        setVisible(false);
}The most useful feature of Dialogs is modality. A modal dialog is always the focus (at least within java, you can focus other windows). So you must finish whatever the dialog wants before going back to java frames.
I made this one modal, you can't do anything until you close it, or click the ok button.
HTH,
Radish21

Similar Messages

  • Simple dialog - panel and checkboxes

    I have very simple dialog - just one panel and few checkboxes. When I set panel as "undefined" everything works right, but when i set a size of the panel checkboxes disappear.
    Works
    var win = new Window ("dialog", "test");
    var panelOpcje = win.add("panel", undefined, "Options");
    var check1 = panelOpcje.add("checkbox", undefined, "check1");
    var check2 = panelOpcje.add("checkbox", undefined, "check1");
    win.show();
    This doesn't work
    var win = new Window ("dialog", "test");
    var panelOpcje = win.add("panel", [0,0,400,300], "Options");
    var check1 = panelOpcje.add("checkbox", undefined, "check1");
    var check2 = panelOpcje.add("checkbox", undefined, "check1");
    win.show();
    What am I doing wrong, where are my checkboxes?

    I'm not sure if it is requirement, I think once you start adding your own measurements, add them to all your element, I could be wrong though.
    var win = new Window ("dialog", "test");
    var panelOpcje = win.add("panel", [0,0,400,300], "Options");
    var check1 = panelOpcje.add("checkbox", [10, 15, 125, 35], "check1");
    var check2 = panelOpcje.add("checkbox", [10, 45, 125, 65], "check1");
    win.show();

  • Dialog box in Applet

    how can I open a Dialog in an Applet,
    all Dialog constructors requires a JFrame or Dialog owner,
    is there a constructor for Applet?

    U can get a parent frame "handle" like this:
    Component frame = this;
    while(!(frame instanceof Frame))
       frame = frame.getParent();

  • Just a simple dialog

    Hi all.
    I'm trying to do a simple stupid dialog that works so:
    There are some options and a "Ok" and "Cancel" buttons.
    Ok?
    I'd love not to write millions of lines of code to make press OK and let the window close returning the results to the parent.
    Any help?
    Please, take in mind that I hate Java with my strongest will, so please explain clearly :D Thanks

    Java haters are not welcome here! :D
    Anyway, for simple dialogs, Swing has a formidable class. It's called "JOptionPane".
    // copied from the API
    Object[] options = { "OK", "CANCEL" };
    JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning",
    JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
    null, options, options[0]);This will create a window with the buttons OK and Cancel, the Title "Warning", the Text "Click OK to continue" and a Warning symbol.
    The return value of this method is an int, which indicates which button was pressed (0 for OK, 1 for cancel), so you can easily implement custom behavior after these two lines.

  • [JS][CS3] Simple dialog box problem

    Hi
    I am wanting to make my script do 1 of 2 things depending on the result of a dialog box.  I cannot seem to register the users response.  Here is the code:
    var myDialog = new Window('dialog', 'Confirm Changes');
    myDialog.frameLocation = [600,400];
    myDialog.size = [590, 250];
    myImage = myDialog.add('image',[480,41,572,127],'/Macintosh HD/Applications/Adobe InDesign CS3/Scripts/Scripts Panel/Images/xxxx.png');
    myPanel= myDialog.add('panel', [10,10,580,240], 'Select the action you wish to use');
    //Adding Buttons
    myUseExistingTextButton = myPanel.add('button', [48,190,75,25], 'Use Existing Text',{name:'select'});
    myUseNewButton = myPanel.add('button', [260,190,75,25], 'Use New text as shown',{name:'select'});
    myCancelButton = myPanel.add('button', [480,190,75,25], 'Cancel',{name:'select'});
    myExistingTextWindow = myDialog.add('edittext',[20,40,230,200],'Existing Text');
    myNewTextWindow = myDialog.add("edittext",[250,40,460,200],"New Text");
    myResult = myDialog.show();
    if(myResult == true)
         if (myResult == 0)
                        alert("Old was selected");
         if (myResult == 1)
                        alert("New was selected");
    which gives the following result:
    All I want to do is use the selected button do do the next part of my script depending on the text selected.
    I will keep on looking, and di-secting other scripts, but any help here would be nice.
    Thanks as always
    Roy

    Here is code created with RapidScriptUI in about 2 minutes. It includes multiline editbox, dimensions without using co-ordinates  that display accurately cross platform and simple to edit code for beginners like you to learn and understand (This is a free advertisement).
    var rapidDlg = new Window('dialog',"Confirm Changes",undefined);
    buildWindow();
    rapidDlg.show();
    function buildWindow(){
    // Properties for rapidDlg.Panel1
         rapidDlg.Panel1 = rapidDlg.add('panel',undefined,"Select the action you wish to choose");
         rapidDlg.Panel1.margins= [20,20,20,20];
         rapidDlg.Panel1.orientation = "row";
    // Properties for rapidDlg.Panel1.Group1
         rapidDlg.Panel1.Group1 = rapidDlg.Panel1.add('group',undefined);
         rapidDlg.Panel1.Group1.orientation = "column";
    // Properties for rapidDlg.Panel1.Group1.EditText1
         rapidDlg.Panel1.Group1.EditText1 = rapidDlg.Panel1.Group1.add('edittext',undefined,"Existing Text", {multiline:true});
         rapidDlg.Panel1.Group1.EditText1.preferredSize.width = 200;
         rapidDlg.Panel1.Group1.EditText1.preferredSize.height = 100;
    // Properties for rapidDlg.Panel1.Group1.ExistingText
         rapidDlg.Panel1.Group1.ExistingText = rapidDlg.Panel1.Group1.add('button',undefined,"Use Existing Text");
    rapidDlg.Panel1.Group1.ExistingText.onClick = ExistingText_Clicked;
    // Properties for rapidDlg.Panel1.Panel2
         rapidDlg.Panel1.Panel2 = rapidDlg.Panel1.add('panel',undefined,undefined);
         rapidDlg.Panel1.Panel2.alignment = [' ','fill'];
    // Properties for rapidDlg.Panel1.Group2
         rapidDlg.Panel1.Group2 = rapidDlg.Panel1.add('group',undefined);
         rapidDlg.Panel1.Group2.orientation = "column";
    // Properties for rapidDlg.Panel1.Group2.EditText2
         rapidDlg.Panel1.Group2.EditText2 = rapidDlg.Panel1.Group2.add('edittext',undefined,"New Text", {multiline:true});
         rapidDlg.Panel1.Group2.EditText2.preferredSize.width = 200;
         rapidDlg.Panel1.Group2.EditText2.preferredSize.height = 100;
    // Properties for rapidDlg.Panel1.Group2.NewText
         rapidDlg.Panel1.Group2.NewText = rapidDlg.Panel1.Group2.add('button',undefined,"Use New text as shown");
    rapidDlg.Panel1.Group2.NewText.onClick = NewText_Clicked;
    // Properties for rapidDlg.Button3
         rapidDlg.Button3 = rapidDlg.add('button',undefined,"Cancel", {name:"cancel"});
         rapidDlg.Button3.alignment = ['right',' '];
    function ExistingText_Clicked(){
         alert(this.text +  ' was clicked!');
    function NewText_Clicked(){
         alert(this.text +  ' was clicked!');
    Steven
    http://scriptui.com

  • Simple Date and Time Applet....

    Obviously I am a java newbie... I just need to know how to write a simple java applet that displays the current date and time... refreshing every second... in a small sans-serif font. Does anyone know where I can find an applet like this with the code so I can learn this? I have tried some websites but I get things much more complex then what I am trying to accomplish. Thanks.
    Donnie

    Sometimes the site you are on can help out :)
    Here is a clock applet courtesy of Sun:
    import java.awt.Graphics;
    import java.util.*;
    import java.text.DateFormat;
    import java.applet.Applet;
    public class Clock extends Applet implements Runnable {
    private Thread clockThread = null;
    public void start() {
    if (clockThread == null) {
    clockThread = new Thread(this, "Clock");
    clockThread.start();
    public void run() {
    Thread myThread = Thread.currentThread();
    while (clockThread == myThread) {
    repaint();
    try {
    Thread.sleep(1000);
    } catch (InterruptedException e){
    // the VM doesn't want us to sleep anymore,
    // so get back to work
    public void paint(Graphics g) {
    // get the time and convert it to a date
    Calendar cal = Calendar.getInstance();
    Date date = cal.getTime();
    // format it and display it
    DateFormat dateFormatter = DateFormat.getTimeInstance();
    g.drawString(dateFormatter.format(date), 5, 10);
    // overrides Applet's stop method, not Thread's
    public void stop() {
    clockThread = null;
    Just use the setFont() method in the init() method of the applet to set the sans serif font as such:
    setFont(new Font("SansSerif",Font.PLAIN,12);
    Hope that helps.
    -hankhill

  • Associating a dialog to an applet

    Hello,
    Is it possible to associte a JDialog with the applet window? (which happens to be the browser itself)
    thanks,
    Fadi

    Yes. You can find the Applet's parent, which is the browser.
    Object anchorpoint = hmain.getParent();
    while ( !(anchorpoint instanceof Frame))
    anchorpoint = ((Component)anchorpoint).getParent();
    After the while loop, you will the browser's handle in anchorpoint. When you pass it to the JDialog, you'll have to cast it to Frame though.
    JDialog myDialog = new JDialog((Frame)anchorpoint, "title of my dialog");

  • Help me out with a simple dialog box task

    i have used a single dialog box connected to a case structure..but the problem is it only executes true case after pressing "OK" button.
    i need the false case to keep on executing untill "OK" button is pressed.. please heelp me out..

    I agree that the spamming of the same question over and over is annoying and makes me LESS likely to help you. However, I will try to answer you.
    I believe that you are probably fairly new to LabVIEW. LabVIEW is a dataflow language. As such, each node operates as soon as all of its nodes have data. Your One Button Dialog Box does not produce data until the button is pressed. Therefore, there is no way for the Case structure to execute either the True or the False case until the One Button Dialog Box produces its data.
    So, there are several ways to work with this. Several have already been suggest in this or one of the other 3 queries.
    You could place the button on the front panel. If it is on the front panel, it will be read immediately and the value of the button will be available. If it is inside of the loop, the value will be available each time the loop is run. So the suggestion to use a button on the front panel would be a good one.
    If you need to use the dialog box, you could use a producer-consumer architecture. The dialog would be in the producer and the case code would be in the consumer. I think that this is not as good of a solution, but if this is part of a larger application it may be desirable to you for other reasons. There is an example producer-consumer that you can find in the example finder and I think that there is a template for one as well.
    There are other ways to do this as well, but they get more and more complicated and I don't think you have the experience necessary to accomplish them. I also don't think you need to make things that complicated for such a simple task.
    Good luck and try not to duplicate questions again.
    Bob Young - Test Engineer - Lapsed Certified LabVIEW Developer
    DISTek Integration, Inc. - NI Alliance Member
    mailto:[email protected]

  • JS CS3 Simple Dialog to change doc starting page.

    This example presents the user a dialog telling them the what their current document starting page is. The user can then change the value and update the starting page number. For some reason I'm getting a error Cannot handle the request because a modal dialog or alert is active. I have set myDialog.close(); before the if statement so should this not stop this error?
    I have not added any checks to ensure a doc is open in ID yet.
    var myDialog = new Window('dialog', ' Starting Pg No');
        myDialog.dPgNo = myDialog.add('panel',undefined,'File details');
        myDialog.dPgNo.alignChildren = 'left';
        myDialog.dPgNo.myPgNo = myDialog.dPgNo.add('group');
        myDialog.dPgNo.myPgNo.group = myDialog.dPgNo.myPgNo.add('group');
        myDialog.dPgNo.btnGroup = myDialog.dPgNo.add('group');
        with (myDialog.dPgNo){
        myPgNo.group.orientation = 'column';
        myPgNo.group.alignChildren = 'right';
        myPgNo.group.preferredSize = [90,15];
        myPgNo.group.st  = myPgNo.group.add('statictext',undefined,'Your Doc starting page is:');
        myPgNo.et = myPgNo.add('edittext', undefined, app.activeDocument.pages[0].name)
        btnGroup.btn = btnGroup.add('button', undefined, 'Update');
        btnGroup.alignment = 'right';
    myDialog.dPgNo.btnGroup.btn.onClick = function() {
    myDialog.close();
    var myPagestart = myDialog.dPgNo.myPgNo.et.text;
    if (app.activeDocument.pages[0].name != myPagestart){
    app.activeDocument.pages[0].appliedSection.continueNumbering = false; //<-----------ESTK stops here with the error mentioned before.
    app.activeDocument.pages[0].appliedSection.pageNumberStart = parseInt(myPagestart);
    app.activeDocument.pages[0].appliedSection.sectionPrefix = "";
    alert("Your document start page has been changed to "+myPagestart+".");
    myDialog.show();
    myDialog.show();

    Hi John,
    You don't need to close and reopen the window. Instead of dialog use 'palette' type of the window and run the script in a persistent engine, e.g. #targetengine "session".
    Kasyan
    #targetengine "session"
    var myDialog = new Window('palette','Starting Pg No');
        myDialog.dPgNo = myDialog.add('panel',undefined,'File details');
        myDialog.dPgNo.alignChildren = 'left';
        myDialog.dPgNo.myPgNo = myDialog.dPgNo.add('group');
        myDialog.dPgNo.myPgNo.myGroup = myDialog.dPgNo.myPgNo.add('group');
        myDialog.dPgNo.btnGroup = myDialog.dPgNo.add('group');
        with (myDialog.dPgNo){
            myPgNo.myGroup.orientation = 'column';
            myPgNo.myGroup.alignChildren = 'right';
            myPgNo.myGroup.preferredSize = [90,15];
            myPgNo.myGroup.st  = myPgNo.myGroup.add('statictext',undefined,'Your Doc starting page is:');
            myPgNo.et = myPgNo.add('edittext', undefined, app.activeDocument.pages[0].name)
            btnGroup.btn = btnGroup.add('button', undefined, 'Update');
            btnGroup.alignment = 'right';
    myDialog.show();
    myDialog.dPgNo.btnGroup.btn.onClick = function() {
        var myPagestart = myDialog.dPgNo.myPgNo.et.text;
        if (app.activeDocument.pages[0].name != myPagestart){
            app.activeDocument.pages[0].appliedSection.continueNumbering = false;
            app.activeDocument.pages[0].appliedSection.pageNumberStart = parseInt(myPagestart);
            app.activeDocument.pages[0].appliedSection.sectionPrefix = "";
            alert("Your document start page has been changed to "+myPagestart+".");

  • A simple dialog with semi-transparent border (MFC)

    Hi,
    I have to make a image dialog with semi-transparency border in MFC.
    I had web surfing all the day and found this solution in the codeproject.
    http://www.codeproject.com/Articles/42032/Perfect-Semi-transparent-Shaped-Dialogs-with-Stand
    But it creates two dialogs to make a semi-transparent dialog and the mechanism was so complex.
    And the release of the dialog object is difficult so that it may have memory leaks.
    I want a dialog (background is an image) with a semi-transparent border (corner - rounded).
    And I have to make it with only one dialog. If it's possible, how can I do it?
    Please help me, Thank you.

    The child control will become semi-transparency as your dialog.
    Do you want to show some child control on your dialog? If yes, you need the second dialog to host your child control. 
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Applet - error in simple Ping program using Applet.Pls correct my error.

    Can anyone pls correct the error in the below code.
    Program : TestExec1
    Using : Applet
    Logic : Trying to display the continous pinging status in the textarea in applet, but it returns error...!
    CODING
    import java.awt.*;
    import java.lang.*;
    import java.io.*;
    import java.net.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.*;
    /*<applet code="TestExec1" width=380 height=150>
    </applet>
    public class TestExec1 extends Applet
    String line = null;
    TextArea outputArea;
    Process p;
    public void init()
    outputArea = new TextArea(20,20);
    public void start()
    try
    Process p= Runtime.getRuntime().exec("ping 192.168.100.192 -t");BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
    while ((line = in.readLine()) != null)
    outputArea.append("\n" + line);
    System.out.println(line);
    catch (IOException e)
    e.printStackTrace();
    Error : C:\Program Files\Java\jdk1.6.0_02\bin>appletviewer TestExec1.java
    java.security.AccessControlException: access denied (java.io.FilePermission <<AL
    L FILES>> execute)
    at java.security.AccessControlContext.checkPermission(AccessControlConte
    xt.java:323)
    at java.security.AccessController.checkPermission(AccessController.java:
    546)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
    at java.lang.SecurityManager.checkExec(SecurityManager.java:782)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:447)
    at java.lang.Runtime.exec(Runtime.java:593)
    at java.lang.Runtime.exec(Runtime.java:431)
    at java.lang.Runtime.exec(Runtime.java:328)
    at TestExec1.start(TestExec1.java:31)
    at sun.applet.AppletPanel.run(AppletPanel.java:458)
    at java.lang.Thread.run(Thread.java:619)
    Regards
    ESM

    Will you please tell the procedure of how to use jarsigner and make a sign in for my program.
    class Name : SamplePing.java
    Using : Applet
    Manifest file : manifest.txt
    Main Class : SamplePing
    I have created jar file using the following command -
    "jar cvfm Ping.jar manifest.txt Sa*.class "
    Let me know how can i proceed further to run exec command in applet.Pls give me series of steps.
    Thanks in advance.

  • I am not able to login to my applet as the login dialog does not take the focu

    In the login dialog of the applet it does allow the user to enter the password in to the field. Password field does not takes the focus. I tried with JTextfield and it is also having the same problem.
    == This happened ==
    Every time Firefox opened
    == When in installed 3.5.9 version. It is ok with 3.0 version

    Can you use the Tab key?
    See also [[Pressing Tab key does not select menus or buttons]]
    http://kb.mozillazine.org/accessibility.tabfocus

  • Hidden dialog renders applet unusable

    i have a problem with dialogs in my applet.
    if an applet dialog is open, and the user minimizes the browser or switches to another application, the dialog gets pemanently hidden (at least in firefox). there's no way to locate the applet again, and hence, no way for the applet to regain focus.
    clicking around on the applet generates a system beep but does not cause the dialog to reappear.
    one obvious approach is to eliminate dialogs. i need the dialogs, though, and want to ask the community if better alternatives exist.
    any ideas? does anyone else have this problem?
    thanks!

    i figured how to make the applet modal with both the Microsoft JVM and the SUN JVM. from reading posts elsewhere on the web, it seems like people have also had trouble with making dialogs modal with the Microsoft JVM. this solution also makes it possible for someone to switch applications while a modal dialog is open without causing the applet to be unusable. when the user switches back to the browser/applet, the blocking dialog is on top of all windows versus being hidden as it would normally.
    ==================
    BEGIN CODE
    ==================
    public NonblockingDialog (Frame parent, String title) {
              super(parent, title, true);
    addWindowListener(new WindowAdapter() {
                   public void windowDeactivated (WindowEvent we) {
                        requestFocus();
                        toFront();
    ==================
    END CODE
    ==================

  • How to center Dialog over Applet?

    A quick question.... When I create a Dialog in an Applet, I have to create a "dummy" frame to be the parent/owner of the Dialog. As a result, when I display the Dialog, it shows up in the upper-left corner of the screen. How do I use a Dialog in an Applet so that it displays centered over the Applet?
    Thanks,
    Nordman

    I have to create a "dummy" frame to be the
    parent/owner of the Dialog.No. you do not. You can use the browser frame.
    In the applet you can get it like this:
    Frame browserFrame;
    Component comp= this;
    while (! (comp instanceof Frame))
       comp = comp.getParent();
    browserFrame = (Frame)comp;you can also use setLocationOnScreen() to set the dialogs position. To set it relative to the applet or the browserFrame, you call getLocationOnScreen on those, and calculate whatever position you want.
    Ragnvald Barth
    Software engineer

  • Please help!! How to communicate between applet and pop up dialog box

    Hi friend,
    I have done a AWT pop up dialog box from Applet. In this pop up dialog box, I want get user name, and display on an Applet, anyone can tell me how to do? Thanks a lot!!!!
    Alva

    You need to create two methods in your applet, getName and setName as well as a name field.
    private name = "";
    public void setName(String n)
        name = n;
    public void getName()
        return name;
    }The various constructor methods for Dialog already take the owner of the Dialog (your applet) as a parameter, so in your applet's ActionEvent handler, all you have to do is call
        name = textName.getText().trim();
        owner.setName(name);Yes, it's that easy.

Maybe you are looking for