How does one show a message in a popup-window from an applet?

Paolo Rocca

Just popup a Frame from your applet. This is your applet:

//File hello.java
import java.awt.*;
import java.applet.*;

public class hello extends Applet {
  Frame f = new helloFrame ();
  public void init() {
    setLayout (new FlowLayout());
    add (new Button("Click me"));
    /* this button allows you to pop up a frame */
  }
  public boolean action (Event evt, Object arg) {
    if (arg.equals("Click me")) {
      f.show();		// Show the popup window
      f.resize (150, 100);	// and resize it
      return true;
    }
    else return false;
  }
}

And this is your frame:
// File helloFrame.java
import java.awt.*;
import java.applet.*;

public class helloFrame extends Frame {
  public helloFrame() {
    setLayout (new FlowLayout());
    setTitle ("Hello!");			    // The window title
    add (new Label ("This is the message"));    // Your message
    add (new Button ("Ok"));		    // The button to quit
  }
  public boolean action (Event evt, Object arg) {
    if (arg.equals("Ok")) {
      dispose();
      return true;
    }
    else return false;
  }
}

You have to compile helloFrame first, and then you can compile hello. When you click on the button "click me" a popup window will be showed, with your message in it.
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact