Page 1 of 2 12 LastLast
Results 1 to 20 of 28
  1. #1
    Jet
    Jet is offline Member
    Join Date
    Jan 2014
    Posts
    14
    Rep Power
    0

    Default Applet for web browser

    Hello,
    I'm trying to run my applet about 5 days on web browser and i can't...

    1.
    I created Main class like: public class Main extends JApplet implements ActionListener,MouseListener{
    and after that class, is functions like public void init()
    Java Code:
    public void init(){
    	setSize(Width,Height);
    	setName("Game");
        cr.change_cursor("Pictures/mouse.png",this);
    	try {
            javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    createGUI();
                }
            });
        } catch (Exception e) {
            System.err.println("create GUI didn't successfully complete");
        }
    }
    cr is class...
    change_cursor is function in cr class....
    CreateGUI(); is function who running my code...
    2.
    I created about 5 class, and in class I'm doing like that: public class Sounds{....
    3.
    i grant all permisions to my applet
    grant {
    permission java.security.AllPermission;
    };
    4.
    My html code:
    <HTML>
    <BODY>
    <div align = "center">
    <APPLET CODE = "Main.class" archive="SSSignedApplet.jar" WIDTH = "500" HEIGHT = "600">
    </APPLET>
    </div>
    </BODY>
    </HTML>
    5.
    In cmd I do like:
    jar cvf SignedApplet.jar Main.class
    keytool -genkey -alias registr -keystore jetforewer -keypass k124565 -dname "cn=jonas" -storepass ab987c
    jarsigner -keystore jetforewer -storepass ab987c -keypass k124565 -signedjar SSignedApplet.jar SignedApplet.jar registr
    keytool -export -keystore jetforewer -storepass ab987c -alias registr -file Jet.cer
    keytool -import -alias jetf -file Jet.cer -keystore rayst -storepass abcdefgh

    P.S I don't know if I need use keys or not... I'm dont know what to make, to run my applet on web Browser...
    I read many informacion on websites....
    and problem is that i cann't open my applet in web... On Eclipse is running good...
    Applet for web browser-untitledsss.png
    hot to run java applet on web browser? please explain me in detail if you can :)
    Sorry for my bad english language...
    I'm newbie in java programming language
    here is some pictures:
    Applet for web browser-untitledsss.png
    Applet for web browser-untitledssss.png
    Last edited by Jet; 01-31-2014 at 11:12 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: Applet for web browser

    Can you copy the full contents of the Java Console window and paste it here. See the Copy button at the bottom of the window.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Jet
    Jet is offline Member
    Join Date
    Jan 2014
    Posts
    14
    Rep Power
    0

    Default Re: Applet for web browser

    Java Plug-in 10.51.2.13
    Using JRE version 1.7.0_51-b13 Java HotSpot(TM) Client VM
    User home directory = C:\Users\Jet
    ----------------------------------------------------
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------
    CacheEntry[file:/C:/Users/Jet/workspace/Zaidimas/bin/SSignedApplet.jar]: updateAvailable=true,lastModified=Fri Jan 31 13:05:49 EET 2014,length=6162
    Missing Application-Name manifest attribute for: file:/C:/Users/Jet/workspace/Zaidimas/bin/SSignedApplet.jar
    Missing Permissions manifest attribute in main jar: file:/C:/Users/Jet/workspace/Zaidimas/bin/SSignedApplet.jar


    Maybe I need somehow run java.policy.applet in eclipse when applet started without any keys...?
    but when i use html code like:
    <HTML>
    <BODY>

    <div align = "center">

    <APPLET CODE = "Main"WIDTH = "500" HEIGHT = "600">
    </APPLET>


    </div>
    </BODY>
    </HTML>
    and when I open website it shows me that cannot read pictures, but I grant all permisions...
    P.S IN APPLETVIEWER it run perfect...
    Last edited by Jet; 01-31-2014 at 11:12 PM.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: Applet for web browser

    Try adding the path to the folder holding the jar file to the Exception Site List in the Security tab of the Java Control Panel.
    See: https://blogs.oracle.com/java-platfo...n_site_list_in
    Last edited by Norm; 01-31-2014 at 08:53 PM.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Jet
    Jet is offline Member
    Join Date
    Jan 2014
    Posts
    14
    Rep Power
    0

    Default Re: Applet for web browser

    Its not solved my problem...
    Ok i will show all my code... I know I'm just newbie in java, and just two weeks learning it so code not
    optimized.
    I don't know maybe my code bad :( I don't know what to use, now if will need others fings use,replace, here will need change many fings...
    Main class:
    Java Code:
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.RenderingHints;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.image.BufferedImage;
    import java.util.Random;
    
    import javax.swing.BorderFactory;
    import javax.swing.ButtonGroup;
    import javax.swing.ImageIcon;
    import javax.swing.JApplet;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JRadioButton;
    import javax.swing.Timer;
    
    
    public class Main extends JApplet implements ActionListener,MouseListener{
    
    private static final long serialVersionUID = -6413020972658315765L;
    Timer tm=new Timer(80,(ActionListener) this);//100
    int x=0;
    int Width=500;
    int Height=600;
    JButton bt=new JButton();//Mygtuko kurimas
    JPanel panelis=new JPanel();//Panelio kurimas(Pagrindinio lango)
    JLabel label2=new JLabel();
    JButton  bt_imag=new JButton();
    JLabel labelis=new JLabel();
    JPanel panel=new JPanel();//Panelio kurimas(Zaidimo)
    Cursorius cr=new Cursorius();
    JButton taisykles=new JButton();
    Taisykles ts=new Taisykles();
    JLabel fm=new JLabel();
    JLabel nickname=new JLabel();
    Garsai sound=new Garsai();
    JRadioButton[] statymas = new JRadioButton[4];
    JLabel stat=new JLabel();
    String statymo_dydis="";
    public void paint(Graphics page)
     {
             super.paintComponents(page);
     }
    public void start()
    /*    try
        {
    createGUI();
        }
        catch(Exception ex)
        {
            
        }*/
    }
    
    public void init(){
        setSize(Width,Height);
        setName("Game");
        cr.change_cursor("Paveiksleliai/pele.png",this);
        try {
            javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    createGUI();
                }
            });
        } catch (Exception e) {
            System.err.println("create GUI didn't successfully complete");
        }
    }
    public void destroy(){
    }
    public void stop(){
    }
    
    public BufferedImage scaleImage(int WIDTH, int HEIGHT, String filename) {
        BufferedImage bi = null;
        try {
            ImageIcon ii = new ImageIcon(filename);//path to image
            bi = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
            Graphics2D g2d = (Graphics2D) bi.createGraphics();
            g2d.addRenderingHints(new RenderingHints(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY));
            g2d.drawImage(ii.getImage(), 0, 0, WIDTH, HEIGHT, null);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        return bi;
    }
    private void createGUI() {
        //Policy.setPolicy(new Permisions());
        fm=new JLabel(new ImageIcon("Paveiksleliai/fm.png"));
        fm.setBounds(390, 570, 40, 20);
        nickname=new JLabel("By      JetForewer");
        nickname.setBounds(380, 570, 150, 20);
        nickname.setFont(new Font("Serif", Font.BOLD, 14));
        nickname.setForeground(Color.red);
        panelis=new JPanel();
        panelis.setBounds(1, 1, Width-1, Height-1);
        panelis.setBorder(BorderFactory.createLineBorder(Color.yellow));
        panelis.setVisible(true);
        panelis.setLayout(null);
        add(panelis);
        statymo_dydis="500MB";
        //BufferedImage im=scaleImage(Width,Height,"Paveiksleliai/trl.png");
        label2 = new JLabel(new ImageIcon("Paveiksleliai/trl.png"));
        label2.setLocation(0,0);
        label2.setSize(Width, Height);
        label2.setVisible(true);
        panelis.add(label2);
    
         BufferedImage ims=scaleImage(180,255,"Paveiksleliai/Animacion/"+x+".png");
         ImageIcon imageIcon = new ImageIcon(ims);
         bt_imag=new JButton();
         bt_imag.setIcon(imageIcon);
         bt_imag.setBounds(170, 130, 180, 255);
         bt_imag.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
         bt_imag.setLayout(null);
         cr.change_cursor("Paveiksleliai/pele_hover.png",bt_imag);
         bt_imag.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e)
                {
                Garsai.play("Garsai/button_kortos.wav");
                x=53;
                cr.change_cursor("Paveiksleliai/pele.png",bt_imag);
                bt.setVisible(true);
                taisykles.setVisible(true);
                int i=0;
                String[] tekstai={"500MB","1GB","5GB","10GB"};
                ButtonGroup group = new ButtonGroup();
                int locationx=10;
                int[] dydziai={65,50,50,60};
                while (i<4)
                {
                    statymas[i]=new JRadioButton();
                    statymas[i].setText(tekstai[i]);
                    statymas[i].setSize(dydziai[i],20);
                    statymas[i].setBackground(new Color(0,0,0,0));
                    statymas[i].setLocation(locationx,490);
                    statymas[i].setSelected(false);
                    statymas[i].setForeground(Color.BLUE);
                    statymas[i].setOpaque(false);
                    statymas[i].addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e)
                        {
    
                            int index = -1;
                            for (int i = 0; i < statymas.length; i++) {
                                if (e.getSource() ==statymas[i]) {
                                    index = i;
                                    break;
                                }
                            }
                            if (index == -1) {
                                
                            } else {
                                //statymas[index].setBackground(new Color(0,0,0,0));
                                statymo_dydis=statymas[index].getText();
                            }
                        }
                        });
                    group.add(statymas[i]);
                    label2.add(statymas[i]);
                    locationx=locationx+dydziai[i];
                i++;
                }
                stat=new JLabel("Pasirinkite statymo dydį:");
                stat.setForeground(Color.black);
                stat.setLocation(10,470);
                stat.setSize(150,20);
                label2.add(stat);
                statymas[0].setSelected(true);
                }
         });
         label2.add(bt_imag);
         label2.add(fm);
         label2.add(nickname);
         tm.start();
            taisykles.setText("Taisyklės");//tekstas
            taisykles.setBackground(Color.blue);//fono spalva
            taisykles.setForeground(Color.white);//teksto spalva
            taisykles.setName("Button_start_game");//Vardo suteikimas
            taisykles.setVisible(false);//Padaromas nematomu
            taisykles.setBounds(10,60,155, 40);
            cr.change_cursor("Paveiksleliai/pele_hover.png",taisykles);
            taisykles.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e)
                {
                    Garsai.play("Garsai/button_click.wav");
                    panelis.setVisible(false);
                    panel=new JPanel();
                    panel.setSize(20, 20);
                    panel.setBackground(Color.black);
                    panel.setBounds(1, 1, Width-1, Height-1);
                    panel.setBorder(BorderFactory.createLineBorder(Color.black));
                    panel.setVisible(true);
                    panel.setLayout(null);
                    add(panel);
                    panel.add(ts.button(panelis,panel));
                    panel.add(ts.textArea());
                }     
            });  
            bt_imag.add(taisykles);
        
        bt.setText("Pradėti žaidimą");//tekstas
        bt.setBackground(Color.blue);//fono spalva
        bt.setForeground(Color.white);//teksto spalva
        bt.setName("Button_start_game");//Vardo suteikimas
        bt.setVisible(false);//Padaromas nematomu
        bt.setBounds(10,10,155, 40);
        cr.change_cursor("Paveiksleliai/pele_hover.png",bt);
        bt.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e)
            {
                Garsai.play("Garsai/button_click.wav");
                
             Object[] options = {"Taip","Ne, Ačiū"};
             int choice=JOptionPane.showOptionDialog(null,
                                                     "Ar jūs tikrai norite statyti: "+statymo_dydis+" ?",
                                                     " ",
                                                    JOptionPane.YES_NO_OPTION,
                                                    JOptionPane.QUESTION_MESSAGE,
                                                    null,
                                                    options,
                                                    options[1]);
             Garsai.play("Garsai/button_click.wav");
            if(choice == 0 ){
               panelis.setVisible(false);
               panel=new JPanel();
               panel.setSize(20, 20);
               panel.setBackground(Color.black);
               panel.setBounds(1, 1, Width-1, Height-1);
               panel.setBorder(BorderFactory.createLineBorder(Color.black));
               panel.setVisible(true);
               panel.setLayout(null);
               add(panel);
               Zaidimas_BlackJack d=new Zaidimas_BlackJack();
               panel.add(d.BlackJack(panelis,panel));
             }else{
                  }
    
    
           }     
        });  
        bt_imag.add(bt);
    }
    
    @Override
    public void actionPerformed(ActionEvent arg0) {
        BufferedImage image=scaleImage(180,250,"Paveiksleliai/Animacion/"+x+".png");
        ImageIcon Icon = new ImageIcon(image);
        bt_imag.setIcon(Icon);
        Random rand= new Random();
        float r = rand.nextFloat();
        float g = rand.nextFloat();
        float b = rand.nextFloat();
        Color randomColor = new Color(r, g, b);
        bt_imag.setBorder(BorderFactory.createLineBorder(randomColor));
        if (x!=53)
        x=x+1;    
        if (x==52)
        {
            int i=0;
            String[] tekstai={"500MB","1GB","5GB","10GB"};
            ButtonGroup group = new ButtonGroup();
            int locationx=10;
            int[] dydziai={65,50,50,60};
            while (i<4)
            {
                statymas[i]=new JRadioButton();
                statymas[i].setText(tekstai[i]);
                statymas[i].setSize(dydziai[i],20);
                statymas[i].setBackground(new Color(0,0,0,0));
                statymas[i].setLocation(locationx,490);
                statymas[i].setSelected(false);
                statymas[i].setForeground(Color.BLUE);
                statymas[i].setOpaque(false);
                statymas[i].addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e)
                    {
    
                        int index = -1;
                        for (int i = 0; i < statymas.length; i++) {
                            if (e.getSource() ==statymas[i]) {
                                index = i;
                                break;
                            }
                        }
                        if (index == -1) {
                            
                        } else {
                            //statymas[index].setBackground(new Color(0,0,0,0));
                            statymo_dydis=statymas[index].getText();
                        }
                    }
                    });
                group.add(statymas[i]);
                label2.add(statymas[i]);
                locationx=locationx+dydziai[i];
            i++;
            }
            stat=new JLabel("Pasirinkite statymo dydį:");
            stat.setForeground(Color.black);
            stat.setLocation(10,470);
            stat.setSize(150,20);
            label2.add(stat);
            statymas[0].setSelected(true);
            
        x=53;
        cr.change_cursor("Paveiksleliai/pele.png",bt_imag);
        //bt_imag.setBackground(Color.BLACK);
        bt.setVisible(true);//Padaromas nematomu;
        taisykles.setVisible(true);//Padaromas matomu
        }
        repaint();
      }
    public void panel_matomas()
    {
    panelis.setVisible(true);
    }
    public void mouseClicked(MouseEvent arg0) {
        // TODO Auto-generated method stub
        
    }
    @Override
    public void mouseEntered(MouseEvent arg0) {
        if (x!=53)
            cr.change_cursor("Paveiksleliai/pele_hover.png",bt_imag);
        
    }
    @Override
    public void mouseExited(MouseEvent arg0) {
        cr.change_cursor("Paveiksleliai/pele.png",bt_imag);
        
    }
    @Override
    public void mousePressed(MouseEvent arg0) {
        // TODO Auto-generated method stub
        
    }
    @Override
    public void mouseReleased(MouseEvent arg0) {
        // TODO Auto-generated method stub
        
    }
    }
    Cursorius class:
    Java Code:
    import java.awt.Component;
    import java.awt.Cursor;
    import java.awt.Image;
    import java.awt.Point;
    import java.awt.Toolkit;
    
    
    public class Cursorius{
    
        //private Main mMain;
        public void change_cursor(String picture,Component cr)
        {
             Toolkit toolkit = Toolkit.getDefaultToolkit();
                Image pele = toolkit.getImage(picture);
              //  BufferedImage blankCursorImg =
                          // new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
                           Cursor blankCursor = Toolkit.getDefaultToolkit().
                           createCustomCursor(pele, new Point(0, 0), null);
                           cr.setCursor(blankCursor);
        }
    }
    Garsai class:
    Java Code:
    import java.io.File;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.Clip;
    public class Garsai {
        static void play(String filename)
        {
            try
            {
                Clip clip = AudioSystem.getClip();
                clip.open(AudioSystem.getAudioInputStream(new File(filename)));
                clip.start();
            }
            catch (Exception exc)
            {
                exc.printStackTrace(System.out);
            }
        }
    }
    and is more 3 classes...
    Last edited by Jet; 01-31-2014 at 11:10 PM.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: Applet for web browser

    That is too much code for testing a problem with an applet. I still am not sure what and where the error is. One of the images says: InvocationTargetError? What code causes that? Make sure ALL the catch blocks call the printStackTrace() method so the full text of the error message is displayed.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    Jet
    Jet is offline Member
    Join Date
    Jan 2014
    Posts
    14
    Rep Power
    0

    Default Re: Applet for web browser

    I don't understand one thing. Why in eclipse applet runs successfully? where has be some error, but now I dont see them... Maybe my try bad?

    Java Code:
    public void init(){
    setSize(Width,Height);
    setName("Game");
    cr.change_cursor("Paveiksleliai/pele.png",this);
    try {
    javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
    public void run() {
    createGUI();
    }
    });
    } catch (Exception e) {
    System.err.println("create GUI didn't successfully complete");
    }
    }
    I think, that when where is Exception e, at startup program in console will print that "create GUI didn't successfully complete", but I dont get that message...
    and my all code is in createGUI(); function... just cr.change_cursor("Paveiksleliai/pele.png",this); not in try.
    How you find that "One of the images says: InvocationTargetError?"
    Last edited by Jet; 01-31-2014 at 11:05 PM.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: Applet for web browser

    Did you add the call to printStackTrace() to all the catch blocks, create a jar file, load the html file into the browser and copy what is displayed in the java console?

    The InvocationTargetError is shown in the last image in post#1.

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    Jet
    Jet is offline Member
    Join Date
    Jan 2014
    Posts
    14
    Rep Power
    0

    Default Re: Applet for web browser

    I cannot find anything in java console, but I think becouse i clear console before... (Maybe you know how to fix it?)
    So I host my java applet here is link, I think you will see errors TRL zaidimas
    of this link html code is:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>TRL zaidimas</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    </head>
    <body>
    <div align = "center">

    <applet code = "Main.class" width = "500" height = "600">
    </applet>

    </div>
    </body>
    </html>
    for this link:http://87.247.107.23/Zaidimas/bin/ssss.html

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>TRL zaidimas</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    </head>
    <body>
    <div align = "center">

    <applet code = "Main.class" archive = "game.jar" width = "500" height = "600">
    </applet>

    </div></body>
    </html>

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: Applet for web browser

    What is shown in the java console now with the new code?

    I get this error:
    Unable to connect to: http://87.247.107.23/Zaidimas/bin/ Connection timed out: connect
    Last edited by Norm; 02-01-2014 at 01:40 AM.
    If you don't understand my response, don't ignore it, ask a question.

  11. #11
    Jet
    Jet is offline Member
    Join Date
    Jan 2014
    Posts
    14
    Rep Power
    0

    Default Re: Applet for web browser

    Can you try now... Now working.. I needed turn off..becouse on pc I host that applet...
    P.S try to open what link TRL zaidimas and open java console
    and this link http://87.247.107.23/Zaidimas/bin/ddd.html


    in java console i got:
    Java Plug-in 10.51.2.13
    Using JRE version 1.7.0_51-b13 Java HotSpot(TM) Client VM
    User home directory = C:\Users\Jet
    ----------------------------------------------------
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------
    CacheEntry[file:/C:/Users/Jet/workspace/Zaidimas/bin/sMain.jar]: updateAvailable=false,lastModified=Fri Jan 31 19:19:47 EET 2014,length=6392
    Missing Application-Name manifest attribute for: file:/C:/Users/Jet/workspace/Zaidimas/bin/sMain.jar
    Missing Permissions manifest attribute in main jar: file:/C:/Users/Jet/workspace/Zaidimas/bin/sMain.jar
    Last edited by Jet; 02-01-2014 at 01:22 PM.

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: Applet for web browser

    When I look in the ddd.html file I don't see any reference to the sMain.jar file? I don't understand how the link you posted is connected to the contents of the java console that was posted.

    You need to make a small, simple java program that compiles, executes and shows the problem and post that. The code you have shown is too complicated.
    If you don't understand my response, don't ignore it, ask a question.

  13. #13
    Jet
    Jet is offline Member
    Join Date
    Jan 2014
    Posts
    14
    Rep Power
    0

    Default Re: Applet for web browser

    ok, here i found one example in internet.
    Java Code:
    import java.awt.*;
    import java.io.*;
    import java.applet.*;
    
    public class Count extends Applet {
    
    	private static final long serialVersionUID = -3368813097822225180L;
    	String myFile = "dd.txt";
        File f = new File(myFile);
        DataOutputStream dos;
    
      public void init() {
    
        String osname = System.getProperty("os.name");
        if (osname.indexOf("Windows") != -1) {
          myFile="dd.txt";
        }
      }
      public void paint(Graphics g) {
    
       try {
           dos = new DataOutputStream(new BufferedOutputStream
                             (new FileOutputStream(myFile),128));
            dos.writeChars("This is an Applet generated file\n");
            dos.flush();
            g.drawString("Success: Writing file"
                                            + myFile, 10, 10);
          }
          catch (SecurityException se) {
            g.drawString("Write Failed: Security exception:" + se, 10, 10);
            }
          catch (IOException ioe) {
        g.drawString("Write Failed:I/O exception" + ioe, 10, 10);
            }
       }
    }
    Is simple program who writes to file.
    So in mozilla firefox its writes that: " g.drawString("Write Failed:I/O exception" + ioe, 10, 10);"
    in Chrome its writes that: g.drawString("Success: Writing file"+ myFile, 10, 10);
    but no in text file...but in text file should write this: dos.writeChars("This is an Applet generated file\n");
    and better use Applet or Japplet? becouse i'm using Japplet... And if change to Applet when i need change all my code :/
    So i host this applet:
    you can see it here: http://87.247.107.23/Trying/bin/run.html
    Last edited by Jet; 02-01-2014 at 02:37 PM.

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: Applet for web browser

    Please copy the full contents of the java console and paste it here from when you executed the applet shown in post#13 so we can see the full text of the error messages.
    Be sure that the code calls the printStackTrace() method in the catch blocks so the full error message is shown.
    If you don't understand my response, don't ignore it, ask a question.

  15. #15
    Jet
    Jet is offline Member
    Join Date
    Jan 2014
    Posts
    14
    Rep Power
    0

    Default Re: Applet for web browser

    Here is full java console for this applet of post 13:

    Java Plug-in 10.51.2.13
    Using JRE version 1.7.0_51-b13 Java HotSpot(TM) Client VM
    User home directory = C:\Users\Jet
    ----------------------------------------------------
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------
    Missing Application-Name manifest attribute for: http://87.247.107.23/Trying/bin/sCount.jar
    Missing Permissions manifest attribute in main jar: http://87.247.107.23/Trying/bin/sCount.jar

    I dont get it... Why I don't see errors in java console...
    when i was runned my applet about two days ago I got many errors and errors was like cannot read pictures, I read what I need sign jar, in html code use jar and then when I done that i got others errors who shown in first post in pictures.

  16. #16
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: Applet for web browser

    Missing Application-Name manifest attribute for: http://87.247.107.23/Trying/bin/sCount.jar
    Missing Permissions manifest attribute in main jar:
    Have you tried adding those attributes to the manifest file?

    I don't understand what errors you are getting if there aren't any error messages.

    A suggestion for testing: Copy all the files needed for testing out of the bin folder to a special folder for testing. That is to isolate the production code from any files in the bin folder so that you know exactly what the program needs to execute.
    If you don't understand my response, don't ignore it, ask a question.

  17. #17
    Jet
    Jet is offline Member
    Join Date
    Jan 2014
    Posts
    14
    Rep Power
    0

    Default Re: Applet for web browser

    Where is manifest file? i don't find it in my program folder....
    I copy out all files from bin folder and i got the same message:
    In mozilla:Applet for web browser-untitleddd.png
    In Chrome:Applet for web browser-untitledddd.png
    I dont understand why in mozilla not same message as in google chrome...

  18. #18
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: Applet for web browser

    For debugging with the forum, the code needs to print lots of messages on the java console so that the messages can be copied and pasted here. The images are hard to read. Add more calls to the println() method to the code so messages are printed on the java console so they can be copied and pasted here.
    If you don't understand my response, don't ignore it, ask a question.

  19. #19
    Jet
    Jet is offline Member
    Join Date
    Jan 2014
    Posts
    14
    Rep Power
    0

    Default Re: Applet for web browser

    Java Plug-in 10.51.2.13
    Using JRE version 1.7.0_51-b13 Java HotSpot(TM) Client VM
    User home directory = C:\Users\Jet
    ----------------------------------------------------
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------
    CacheEntry[file:/C:/Users/Jet/workspace/Trying/bin/game.jar]: updateAvailable=true,lastModified=Sat Feb 01 18:01:02 EET 2014,length=1205
    0
    java.security.AccessControlException: access denied ("java.io.FilePermission" "dd.txt" "write")



    Here what I got. It says what applet is not signed or something like that, but yesterday i signed and got the same message...
    I did like in post#1

  20. #20
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: Applet for web browser

    java.security.AccessControlException: access denied ("java.io.FilePermission" "dd.txt" "write")
    The only solution I have found for that error is to grant permission in the .java.policy file:

    permission java.io.FilePermission "<<ALL FILES>>", "read, write";

    All the browsers I tested wrote the file to a different place.
    If you don't understand my response, don't ignore it, ask a question.

Page 1 of 2 12 LastLast

Similar Threads

  1. Can't get this to run in browser as applet - Help
    By confusedgirl in forum New To Java
    Replies: 1
    Last Post: 02-02-2013, 03:53 AM
  2. How to run applet in a web Browser?
    By elururajesh3 in forum Java Applets
    Replies: 4
    Last Post: 11-06-2011, 09:34 AM
  3. applet working in applet viewer, not browser
    By plasticfood in forum Java Applets
    Replies: 4
    Last Post: 06-24-2011, 06:47 PM
  4. Applet not working in browser
    By gkr1989 in forum Java Applets
    Replies: 3
    Last Post: 07-03-2009, 09:43 AM
  5. applet won't run in browser...
    By shwein in forum Java Applets
    Replies: 6
    Last Post: 10-17-2008, 06:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •