[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to convert Application to Applet

Posted on 1997-10-02
1
Medium Priority
?
198 Views
Last Modified: 2013-11-23
I have an application which contains a number of different frames. I would like to modify the code so that I can also run it as an applet. I'm not sure what code needs to be changed or added. Also, my application makes use of dialog boxes, frame titles, etc...) Will these still work within an applet?

Thanks for your help!

Carey Boldenow
carey.boldenow@attws.com
0
Comment
Question by:boldec
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 3

Accepted Solution

by:
eugenem earned 200 total points
ID: 1227794
It depends on code. If your class extends Frame, move all widgets initialization from constructor to init(), your class should extend Applet, in main() create one Frame() and one instance of your class, run init() of your class, add your class to Frame. So when class is running as Applet, it uses init(), and when as application, it uses main(). There is an example. Just look at init/main functions.

// SpecTcl generated class test, version 1.1

package DFS;
import java.awt.*;

public class test extends java.applet.Applet {            

// a slot to hold an arbitrary object pointer that can
// be filled in by the app. and referenced in actions
public Object arg;

public Button button_1;

//methods to support form introspection
public static String names[] = {
      "button_1",
};
public String[] getNames() {
      return names;
}

//There should be an easier way to do this
public Object[] getWidgets() {
      Object[] list = new Object[1];
      list[0] = button_1;
      return list;
}

public void init() {

      // main panel
      GridBagLayout grid = new GridBagLayout();
      int rowHeights[] = {0,30,30};
      int columnWidths[] = {0,30,30};
      double rowWeights[] = {0.0,0.0,0.0};
      double columnWeights[] = {0.0,0.0,0.0};
      grid.rowHeights = rowHeights;
      grid.columnWidths = columnWidths;
      grid.rowWeights = rowWeights;
      grid.columnWeights = columnWeights;

      button_1 = new Button();
      button_1.setLabel("button");
      this.add(button_1);
      

      // Geometry management
      GridBagConstraints con = new GridBagConstraints();
      reset(con);
      con.gridx = 1;
      con.gridy = 1;
      con.anchor = GridBagConstraints.CENTER;
      con.fill = GridBagConstraints.NONE;
      grid.setConstraints(button_1, con);


      // Resize behavior management and parent heirarchy
      setLayout(grid);

      // Give the application a chance to do its initialization
      super.init();
}

public boolean handleEvent(Event event) {
      if (event.id==event.KEY_ACTION && event.key==event.F4 && event.modifiers==event.ALT_MASK) {  // Alt-F4 always exits
            System.exit(3);
      } else
            return super.handleEvent(event);
      return true;
}

public static void main(String[] args) {
    Frame f = new Frame("test Test");
    test win = new test();
    win.init();
    f.add("Center", win);
    f.pack();
    f.show();
}

private void reset(GridBagConstraints con) {
    con.gridx = GridBagConstraints.RELATIVE;
    con.gridy = GridBagConstraints.RELATIVE;
    con.gridwidth = 1;
    con.gridheight = 1;
 
    con.weightx = 0;
    con.weighty = 0;
    con.anchor = GridBagConstraints.CENTER;
    con.fill = GridBagConstraints.NONE;
 
    con.insets = new Insets(0, 0, 0, 0);
    con.ipadx = 0;
    con.ipady = 0;
}

}

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question