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

x
?
Solved

java web start problem

Posted on 2005-05-10
27
Medium Priority
?
222 Views
Last Modified: 2013-11-23
hi
  can someone point to me what i'm doing wrong here..i'm trying to launch a simple applet as an application through web start using a jnlp file locally on my pc..it launches web start and then just dies..i know web start works cause i've launched test applications from the web..all the files are in the C:/java_source directory..i thouhgt i had it working earlier but was mistaken..crmloginapplet has a main class thats the entry point..that calls crmlogin where the applet is painted..if there is a better way to do this please let me know..thank you

<?xml version="1.0" encoding="utf-8"?>
<!-- JNLP File for CRM -->
<jnlp
  spec="1.0+"
  codebase="file:///C:/java_source/"
  href="crmmodule.jnlp">
  <information>
    <title>CRM Login</title>
    <vendor>Sun Microsystems, Inc.</vendor>
    <homepage href="http://www.telk.com.au"/>
    <description>CRM Login Application</description>
    <description kind="short">CRM login screen.</description>
    <icon href="intro.jpg"/>
    <icon href="ok.jpg"/>
    <icon href="nothanks.jpg"/>
    <offline-allowed/>       
  </information>
  <security>
      <all-permissions/>
  </security>
  <resources>
    <j2se version="1.4"/>
    <jar href="crmmodule.jar"/>
 </resources>
  <application-desc main-class="CRMLoginApplet"/>
  </application-desc>
</jnlp>





import java.applet.*;
import java.awt.*;
import java.io.*;
import java.net.*;
import java.util.Vector;
import java.io.*;
import java.net.*;


public class CRMLoginApplet  extends Applet {
   
    public void init() {
   
        String customerCareEmail = "at@telk.com.au";
       
        setSize(278, 175);
       
        Image introImage = getImage(getCodeBase(), "intro.jpg");
        Image okImage = getImage(getCodeBase(), "ok.jpg");
        Image nothanksImage = getImage(getCodeBase(), "nothanks.jpg");
       
       
        setLayout( new BorderLayout() );
       
        try {
           
            add( "Center",new CRMLogin(this,customerCareEmail,introImage,okImage,nothanksImage));
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
       
       
    }
   
    public void destroy() {
    }
   
    static public void main( String args[] )  {
       
        new CRMLoginApplet();
    }
}




import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.StringTokenizer;
import java.io.*;
import java.net.*;
import java.util.Vector;


public class CRMLogin extends Applet implements Serializable, ActionListener,MouseListener {

    private TextArea ta = new TextArea();
    private TextField tf = new TextField();
    private Panel PN1;
    private final static boolean DEBUG = false;


    private java.awt.Button button1;
    private java.awt.Button button2;
    private java.awt.Button button3;
    private java.awt.Label label1;
    private java.awt.Panel panel1;
    private java.awt.Panel panel3;
    private java.awt.Panel panel4;
    private java.awt.Panel panel5;
    private java.awt.Panel panel2;
    private java.awt.TextField textField1;

    String t;
    private Applet applet;
    // Constructor
    public CRMLogin(final Applet a,  final String customerCareEmail,Image introImage, Image okimage, Image nothanks) {
        this.applet = a;

        button1 = new java.awt.Button();
        panel1 = new java.awt.Panel();
        panel2 = new java.awt.Panel();
        label1 = new java.awt.Label();
        textField1 = new java.awt.TextField();
        panel3 = new java.awt.Panel();
        panel5 = new java.awt.Panel();
        panel4 = new java.awt.Panel();

        button1.setLabel("button1");

        setLayout(new java.awt.BorderLayout());

        panel1.setLayout(null);

        panel1.setBackground(new java.awt.Color(255, 255, 255));
        panel1.setForeground(new java.awt.Color(0, 0, 0));

        panel2 = new ImagePanel(introImage);
        panel2.setBackground(new java.awt.Color(255, 255, 255));
        panel1.add(panel2);
        panel2.setBounds(10, 10, 510, 160);




        label1.setAlignment(java.awt.Label.CENTER);
        label1.setBackground(new java.awt.Color(255, 255, 255));
        label1.setFont(new java.awt.Font("Arial", 1, 14));
        label1.setForeground(new java.awt.Color(150, 150, 150));
        label1.setText("your name");
        panel1.add(label1);
        label1.setBounds(10, 180, 80, 21);

        textField1.setFont(new java.awt.Font("Arial", 1, 14));
        panel1.add(textField1);
        textField1.setBounds(100, 180, 400, 21);
        panel3 = new ImagePanel(okimage );
        panel1.add(panel3);
        panel3.setBounds(10, 210, 240, 90);
        textField1.setText(customerCareEmail);
        textField1.setForeground(new java.awt.Color(247, 68, 111));
        panel1.add(panel4);


        panel4 = new ImagePanel(nothanks );
        panel1.add(panel4);
        panel4.setBounds(300, 210, 220, 90);

        panel4.addMouseListener(this);

        add(panel1, java.awt.BorderLayout.CENTER);



    }


}


0
Comment
Question by:trance12
  • 13
  • 13
27 Comments
 
LVL 92

Expert Comment

by:objects
ID: 13975311
you need to:

- create frame and add your applet to that frame
- call init()
- replace the use of getCodeBase() with something else
0
 

Author Comment

by:trance12
ID: 13975388
ok..i've changed the main entry class to be

public void start() {
    }
   
    public void destroy() {
    }
   
    static public void main( String args[] )  {
       
       
        CRMLoginApplet a = new CRMLoginApplet();
        a.init();
        a.start();
 
       Frame appletFrame = new Frame("Applet Window");
       appletFrame.add("Center", a);
       appletFrame.setSize(150,150);
       appletFrame.setLocation(100,100);
       appletFrame.show();

    }


i've added it to a frame..what do i replace getCodeBase with?
0
 
LVL 92

Expert Comment

by:objects
ID: 13975411
The URL of the directory on the server to find the images.
Might be better though to include the images in your jar and load them using getResource()
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.

 

Author Comment

by:trance12
ID: 13975467
i've tried this

      Image introImage = new ImageIcon(this.getClass().getResource("intro.jpg"));


it gives me this erro..what am i missing?

CRMLoginApplet.java [23:1] cannot resolve symbol
symbol  : constructor ImageIcon (java.net.URL)
location: class ImageIcon
        Image introImage = new ImageIcon(this.getClass().getResource("intro.jpg"));




       
       


       
       
0
 

Author Comment

by:trance12
ID: 13975471
i've included the images in the jar
0
 

Author Comment

by:trance12
ID: 13975484
and this is the imageicon class

import java.awt.*;
import java.awt.image.ImageObserver;
import java.applet.Applet;
public class ImageIcon extends Applet
{
   private Image img;

   public ImageIcon(Image i)
   {
      this.img = i;
   }
   public void paint(Graphics g)
   {
       //super.paint(g);
       g.drawImage(img, 10, 10, this);
   }
}
0
 
LVL 92

Expert Comment

by:objects
ID: 13975485
should be:

 ImageIcon introImage = new ImageIcon(this.getClass().getResource("intro.jpg"));

and make sure to import javax.swing.*
0
 
LVL 92

Expert Comment

by:objects
ID: 13975494
Sorry I thought you were using javax.swing.ImageIcon.

> public class ImageIcon extends Applet

Everything does not need to extend Applet, in fact none of them need to :)
0
 
LVL 92

Expert Comment

by:objects
ID: 13975498
I'd also suggest using Swing, it gives you a far richer gui.
0
 

Author Comment

by:trance12
ID: 13975517
i tried that too...actually i want to use javax.swing..

import javax.swing.*;

ImageIcon introImage = new ImageIcon(this.getClass().getResource("intro.jpg"));

it still give me the same error?
0
 
LVL 92

Expert Comment

by:objects
ID: 13975533
Delete your ImageIcon class, you don't need it.
0
 

Author Comment

by:trance12
ID: 13975540
i did ..i just deleted it..it still gives me the error though??

0
 
LVL 92

Expert Comment

by:objects
ID: 13975606
did u also delete the class file?
0
 

Author Comment

by:trance12
ID: 13975626
yep
0
 

Author Comment

by:trance12
ID: 13975634
this is the init part


import java.applet.*;
import java.awt.*;
import java.io.*;
import java.net.*;
import java.util.Vector;
import java.io.*;
import javax.swing.*;


public class CRMLoginApplet  extends Applet {
   
    public void init() {
   
        String customerCareEmail = "akash.hegde@peopletelecom.com.au";
       
       
    ImageIcon introImage = new ImageIcon(this.getClass().getResource("intro.jpg"));
    ImageIcon okImage = new ImageIcon(this.getClass().getResource("ok.jpg"));
    ImageIcon nothanksImage = new ImageIcon(this.getClass().getResource("nothanks.jpg"));
       
       
    }
   

0
 
LVL 92

Expert Comment

by:objects
ID: 13975669
that should be fine, check you don't still have a copy of ImageIcon.class somewhere on your classpath.
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13977897
You an make it more explicit by doing:
javax.swing.ImageIcon introImage = new javax.swing.ImageIcon(this.getClass().getResource("intro.jpg"));
Note, that intro.jpg should be in the same place as this class (if that class is inside its packge and the image is in the root
of the jar then you can replace "intro.jpg" with "/intro.jpg")
0
 

Author Comment

by:trance12
ID: 13982729
not sure what i'm doing wrong here

ImageIcon introImage = new ImageIcon(this.getClass().getResource("intro.jpg"));
    ImageIcon okImage = new ImageIcon(this.getClass().getResource("ok.jpg"));
    ImageIcon nothanksImage = new ImageIcon(this.getClass().getResource("nothanks.jpg"));
       
       
        setLayout( new BorderLayout() );
       
        try {
           
            add( "Center",new CRMLogin(this,customerCareEmail,introImage,okImage,nothanksImage));

in crmlogin, its compiled fine..

public CRMLogin(final Applet a,  final String cust, final String custno,ImageIcon introImage, ImageIcon okimage, ImageIcon nothanks) {


i get this error:

CRMLoginApplet.java [27:1] cannot resolve symbol
symbol  : constructor CRMLogin (CRMLoginApplet,java.lang.String,javax.swing.ImageIcon,javax.swing.ImageIcon,javax.swing.ImageIcon)
location: class CRMLogin
            add( "Center",new CRMLogin(this,customerCareEmail,introImage,okImage,nothanksImage));



   
0
 
LVL 92

Expert Comment

by:objects
ID: 13982910
>  add( "Center",new CRMLogin(this,customerCareEmail,introImage,okImage,nothanksImage));

> CRMLogin(final Applet a,  final String cust, final String custno,ImageIcon introImage, ImageIcon okimage, ImageIcon nothanks)

It expects two strings, customer and customerNo
0
 

Author Comment

by:trance12
ID: 13983007
thanks..web start loads it fien without the images..when i include the iamge icons, it just launches and dissapears again..


  ImageIcon introImage = new ImageIcon(this.getClass().getResource("intro.jpg"));
    ImageIcon okImage = new ImageIcon(this.getClass().getResource("ok.jpg"));
    ImageIcon nothanksImage = new ImageIcon(this.getClass().getResource("nothanks.jpg"));
       
    add( "Center",new CRMLogin(this,customerCareEmail,introImage,okImage,nothanksImage));

i'm loading images onto jpanel in CRMLogin

        jPanel2 = new CRMImageJPanel(introImage.getImage());
        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanell.add(jPanel2);
        jPanel2.setBounds(10, 10, 510, 160);
   

anything wrong with the above or should i be loading images in a different way?

Thanks
0
 
LVL 92

Expert Comment

by:objects
ID: 13983026
thats fine, where are the images located?  They should be in the same directory as the class file.

(You can check the JWS console for any errors)
0
 

Author Comment

by:trance12
ID: 13983032
same directory as the class files..no console errors thats the weird thing
0
 
LVL 92

Expert Comment

by:objects
ID: 13983053
> same directory as the class files

in the jar?

> no console errors thats the weird thing

you sure you're not ignoring any exceptions?
0
 

Author Comment

by:trance12
ID: 13983060
sorry..dont worry..it worked fine..i forgot to include the iamges in my jnlp file..just one last think how to i control the size of the window that opens up when i lauch web start..currently it just opens it with the min and max buttosn and when i enlarge it, it goes to full screen..is there a away i can set the size of the opening screen?
0
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 13983067
Use the setSize() method of your frame


appletFrame.setSize(100, 100);
0
 

Author Comment

by:trance12
ID: 13983088
thanks..
0
 
LVL 92

Expert Comment

by:objects
ID: 13983139
no worries :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 …
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month11 days, 8 hours left to enroll

564 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