Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Applet without GUI

Posted on 2006-03-20
23
Medium Priority
?
592 Views
Last Modified: 2013-11-23
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 ;-)
0
Comment
Question by:kretzschmar
  • 10
  • 8
  • 3
  • +1
23 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16234661
Just don't show the applet (dimensions of 0)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16234666
Sorry misinterpreted. Try

java -Djava.awt.headless=true
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16234675
(where you're running as an application on a display-free box)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 13

Expert Comment

by:Kelvin_King
ID: 16234681
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 16234686
>>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
 
LVL 27

Author Comment

by:kretzschmar
ID: 16234925
>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
 
LVL 86

Expert Comment

by:CEHJ
ID: 16234947
Perhaps you'd better post some code ...
0
 
LVL 27

Author Comment

by:kretzschmar
ID: 16235097
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 16235123
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 16235131
>>You may need to call

(and implement)
0
 
LVL 27

Author Comment

by:kretzschmar
ID: 16235153
>as you are trying to use resources that are normally handled in an applet, GUI, context
which?

>(and implement)
how?
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 1000 total points
ID: 16235175
>>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
 
LVL 27

Author Comment

by:kretzschmar
ID: 16235195
well, guess i go for a.

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

testing now

meikl ;-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16235212
I assume of course, you have passed the correct command line parameter per my original comment
0
 
LVL 13

Expert Comment

by:Kelvin_King
ID: 16235581
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
 
LVL 92

Expert Comment

by:objects
ID: 16240750
just use the following:

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

0
 
LVL 27

Author Comment

by:kretzschmar
ID: 16244656
hi experts,

just a small status:

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

meikl ;-)
0
 
LVL 27

Author Comment

by:kretzschmar
ID: 16256145
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 16256159
:-)
0
 
LVL 92

Expert Comment

by:objects
ID: 16257189
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
 
LVL 27

Author Comment

by:kretzschmar
ID: 16257486
>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
 
LVL 92

Expert Comment

by:objects
ID: 16262441
you asked how to run your applet without a gui, the comment you accepted does *not* do that
0
 
LVL 27

Author Comment

by:kretzschmar
ID: 16265928
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

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

571 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