Link to home
Start Free TrialLog in
Avatar of trance12
trance12

asked on

java web start problem

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);



    }


}


Avatar of Mick Barry
Mick Barry
Flag of Australia image

you need to:

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

ASKER

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?
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()
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"));




       
       


       
       
i've included the images in the jar
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);
   }
}
should be:

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

and make sure to import javax.swing.*
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 :)
I'd also suggest using Swing, it gives you a far richer gui.
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?
Delete your ImageIcon class, you don't need it.
i did ..i just deleted it..it still gives me the error though??

did u also delete the class file?
yep
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"));
       
       
    }
   

that should be fine, check you don't still have a copy of ImageIcon.class somewhere on your classpath.
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")
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));



   
>  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
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
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)
same directory as the class files..no console errors thats the weird thing
> same directory as the class files

in the jar?

> no console errors thats the weird thing

you sure you're not ignoring any exceptions?
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?
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks..
no worries :)