Solved

standalone programs

Posted on 1998-06-22
5
206 Views
Last Modified: 2010-03-30
I wrote this applet and ran it and it ran okay; but if I
compile it and put it in an html page it will not run
properly. It trys to start and then just flash on the screen
with the choice box and then that is all. I dont really
know how to use the project and parts of Jbuilder or
Java Cafe so I only wrote the code for the part of the
applet that does the desired function. When I looked at the
premade applet parts it seemed that they had put in isStandAlone and I thought maybe I needed this but I dont
know. When I tried to put what I did with what was in the
premade applet it did not work. I will upload the source
code in a minute of what I did to http://www.geocities.com/
ResearchTriangle/Lab/6810/Choosing.java; I have enter two questions already
about making this applet. The first two were about something
else. I figured out that part and put the method in the
system.out.println parentheses. I did not know I could do
this and it worked. I copied this from another applet someone did and it worked. I was trying to renameTo() and
it would not work until I put the renameTo() method into
the system.out.println.
0
Comment
Question by:johnh619
[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
  • 3
5 Comments
 

Author Comment

by:johnh619
ID: 1223516
Edited text of question
0
 
LVL 1

Expert Comment

by:ragnar
ID: 1223517
i don't fully understand the question, but i did find an error early in the code which reads:

  applet.isStanlalone ()= true;

i think you mean:

  applet.isStandalone = true;

however, i don't see the object applet being defined anywhere.  your event handling seems okay.  i'm publishing a column on file input/output for www.webresource.net in a few days.  it may help clarify some of what you are wanting to do with files.  let me know and i'll give you the URL to the article when it publishes this week.
0
 
LVL 2

Accepted Solution

by:
aziz061097 earned 50 total points
ID: 1223518
I don't know what for you are using IsStandAlone . Try the following as an applet program instead of Frame(application)

// Name of the program ChoosingApp.java
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.applet.Applet;

public class ChoosingApp extends Applet
            implements ActionListener, ItemListener {
        boolean isStandalone = false;
     //   applet.isStandalone ()= true;
      Choice choice;
      Button surfcache;
        Button savecache;
        File f1=new File("c:/netscape/cache");
        File f2=new File("c:/netscape/cache1");
        File f3=new File("c:/netscape/cache2");
        static final String SURFCACHE="surfcache";
        static final String SAVECACHE="savecache";
      public void paint(Graphics G) {
                //boolean isStandalone = false;
                //applet.isStandalone= true;
            //new Choosing();
            }
      public void init() {
            choice = new Choice();
            choice.addItemListener(this);
            choice.addItem("Surfcache");
            choice.addItem("Savecache");
            surfcache = new Button("Surfcache");
                savecache= new Button("Savecache");
            surfcache.addActionListener(this);
                savecache.addActionListener(this);
                surfcache.setActionCommand(SURFCACHE);
                savecache.setActionCommand(SAVECACHE);
                add("North",surfcache);
            add("South",savecache);
            //pack();
            show();}
      public void itemStateChanged(ItemEvent event) {
              System.out.println("Chosen: " +
                            choice.getSelectedItem());}
      public void actionPerformed(ActionEvent e) {
                String command=e.getActionCommand();
                choice.getSelectedItem();
if (command == SURFCACHE){
System.out.println(f1.getPath() +
(f1.renameTo(f3) ? " renamed to " : "was already renamed to")
+ f3.getPath());
System.out.println(f2.getPath() +
(f2.renameTo(f1) ? " renamed to " : " was already renamed to")
+ f1.getPath());
System.out.println("f1: " + f1.toString() + " " + f1.hashCode());
System.out.println("f2: " + f2.toString() + " " + f2.hashCode());}
if (command == SAVECACHE){
System.out.println(f1.getPath() +
(f1.renameTo(f2) ? " renamed to " : " was already renamed to ")
+ f2.getPath());
System.out.println(f3.getPath() +
(f3.renameTo(f1) ? " renamed to " : " was already renamed to ")
+ f1.getPath());
System.out.println("f1: " + f1.toString() + " " + f1.hashCode());
System.out.println("f3: " + f3.toString() + " " + f3.hashCode());
}}}





The HTML for running the above applet (ChangingApp.html)

<HTML>

<APPLET CODE=ChoosingApp WIDTH=200 HEIGHT=200 ></APPLET>

</HTML>


Run in the commandline the following command after compiling :

appletviewer ChoosingApp.html
0
 

Author Comment

by:johnh619
ID: 1223519
I had already tried it as applet instead of frame but then it
rejects the file declaration and variables. I will try signing
the one I had working but would not run from the browser because
of signing problems and file security. Perhaps though I might
still like to hear anything further. I am investigating the idea
of using an interface to get around the problem of it not accepting the java.io.file  and file declarations in the
extend applet version. The frame one is okay. Thanks
0
 

Author Comment

by:johnh619
ID: 1223520
I found out about signing the applet and the problem of getting
the certificate and that is the reason my applet would not run
in the browser. So now to make it a standalone application is
the problem.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jboss 7.1 start up error 1 83
Java: anonymous class 4 54
junit as external jar or library 7 58
junit example issue 2 54
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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:
Suggested Courses

734 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