Applet without GUI

Hello experts,

i have a task to code an applet,
which shall run in a browser and as an java-application

in case of java-application it may run on machines without a configured DISPLAY -> no GUI

is it possible to disable the GUI in case of such configured machines?

meikl ;-)
LVL 27
kretzschmarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
Just don't show the applet (dimensions of 0)
0
CEHJCommented:
Sorry misinterpreted. Try

java -Djava.awt.headless=true
0
CEHJCommented:
(where you're running as an application on a display-free box)
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Kelvin_KingCommented:
The problem is, if you intend to use your applet in a browser, then you won't be able to use it as an application because there is no main().

However, if you're talking about having the same application with GUI mode and Console mode, then yes definately can be done.
0
CEHJCommented:
>>then you won't be able to use it as an application because there is no main().

I'm assuming kretzschmar knows this and has made a main() ;-)
0
kretzschmarAuthor Commented:
>I'm assuming kretzschmar knows this and has made a main() ;-)
yes, i have a main()

>(where you're running as an application on a display-free box)
i tried it on a linux-box, got an error there because of no display,
the applet aborts in this case

a collegue configured then an xwindows and it works fine then,
but it should also work without any gui

>However, if you're talking about having the same application
>with GUI mode and Console mode, then yes definately can be done.

how?

usual i guess i got this error during some kind of awt-initialization
i get this error also, if i do not create any control

any suggestion are welcome

meikl ;-)
0
CEHJCommented:
Perhaps you'd better post some code ...
0
kretzschmarAuthor Commented:
well okay,

my main

  public static void main(String[] args) {
      TransferApplet applet = new TransferApplet();
    applet.init();
    if (applet.useGUI) {
      Frame frame = new Frame();
      frame.setTitle("TransferApplet");
      frame.add(applet);
      frame.setSize(400, 420);
      Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
      frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
      frame.setVisible(true);
      frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } });
    }
    applet.start();
  }

my init()

  public void init() {
    try  {
      try {
        ConfigFile = this.getDocumentBase().getRef();
      }
      catch (Exception e) {
        ConfigFile = null;
      }
      if (ConfigFile == null) {
        ConfigFile = getParameter("ConfigFile",null);
      }
      if (ConfigFile == null) {
         throw new Exception("Konfigurationsdatei nicht angegeben!");
      }
      props.load(new FileInputStream(ConfigFile));
      if (props.getProperty("GUI").compareTo("1") == 0) {
        useGUI = true;  //this global var is defaulted to false
        ctlInit();  
      }
    }
    catch (Exception e) {
      handleException(e);
    }

so nothing special, i guess (i'm just a beginner :-))

meikl ;-)
0
CEHJCommented:
You may need to call http://java.sun.com/j2se/1.5.0/docs/api/java/applet/Applet.html#setStub(java.applet.AppletStub)

as you are trying to use resources that are normally handled in an applet, GUI, context
0
CEHJCommented:
>>You may need to call

(and implement)
0
kretzschmarAuthor Commented:
>as you are trying to use resources that are normally handled in an applet, GUI, context
which?

>(and implement)
how?
0
CEHJCommented:
>>this.getDocumentBase()

for one. getParameter for the other. You have two alternatives:

a. bypass those calls and their ilk when using as an application
b. implement and set the AppletStub

>>how?

By instantiating a class that implements the methods of AppletStub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kretzschmarAuthor Commented:
well, guess i go for a.

just wondering what this will have to do with the DISPLAY error i got

testing now

meikl ;-)
0
CEHJCommented:
I assume of course, you have passed the correct command line parameter per my original comment
0
Kelvin_KingCommented:
What I ment initially when I said a GUI mode and console mode was basically 2 classes. One which extends JApplet, another which is just a console mode application with your regular BufferedReader.

So when you start your program you have to specify

java myProgram -mode 1

something like that.

0
objectsCommented:
just use the following:

  public static void main(String[] args) {
    TransferApplet applet = new TransferApplet();
    applet.init();
    applet.start();
  }

0
kretzschmarAuthor Commented:
hi experts,

just a small status:

the linuxbox is currently not available,
but will get it today -> be patient

meikl ;-)
0
kretzschmarAuthor Commented:
ok, get it work now

usual is was only this line

this.getDocumentBase();

i chanced the init and main as follows

(init)
...
      if (!isApplication) {
        try {
          ConfigFile = this.getDocumentBase().getRef();
        }
        catch (Exception e) {
          ConfigFile = null;
        }
      }
...

(main)
    ...
    applet.isApplication = true;  //isApplication is defaulted to false
    applet.init();
    ...

so points gets CEHJ

thanks for your help and time

meikl ;-)
0
CEHJCommented:
:-)
0
objectsCommented:
thats still got a gui, if you just want to run it as an app or an  applet you can acheive a lot better than that :)
0
kretzschmarAuthor Commented:
>thats still got a gui, if you just want to run it as an app or an  applet you can acheive a lot better than that :)

explain more, i'm still learning :-))
0
objectsCommented:
you asked how to run your applet without a gui, the comment you accepted does *not* do that
0
kretzschmarAuthor Commented:
usual the graded solved my problem i had

but anyway i will provide some points,
if you give me a small sample
with following conditions

applet runs in a browser -> create a gui (maybe simple a button)
applet runs as application, with an parameter-option switch maybe gui=<0|1>
in case of 0, create no gui
in case of 1, create a gui

meikl ;-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.