Instancer in JApplet

Hello I have this problem:
I made a swing application, I have 2 classes, one is the implementation of the class, the other the window (the interface) so I instance the 2, I pass as parameter the window to the implementor and works great.
The problem is that now I want to create this in a JApplet so I can't create the implementor, the interface (JApplet) and then pass as parameter the window to the implementor, how can I solve this? one option is to instance all in the JApplet, I want to know if there is other option.
Thanks

Cross-posted.

Similar Messages

  • Problem getting japplet static field

    Hi,
    i have a japplet where i have a static jlist field.
    i'm trying to implement chat using sockets.
    i have thread class. in this class, i want the selected index of jlist used in japplet.
    the basic logic is....i run the server, i open 3 instances of japplet. the list will populate with number of clients connected....in this case...3. i select particular value from list and i retrive particular socket object out of a vector (used to store socket object) using this index.
    so the problem is when i do ClietApplet.list.getSelectedIndex()...it gives -1
    can anyone pls suggest me what would be the problem or what would be other way round ?

    here is server and server thread
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.border.*;
    import java.net.*;
    import java.io.*;
    import java.util.*;
    public class NewServer
         public ServerSocket serverSocket = null;
         BufferedReader input;
         String txt = "";
         static int list_val = 0;
         OutputStreamWriter outputstream = null;
         public NewServer()
              super();
              System.out.println("     in constructor ");
              startSocketWait();
         public void startSocketWait()
              try
                   serverSocket = new ServerSocket(5090);
                   while (true)
                        Socket client = serverSocket.accept ();
                        System.out.println ("Accepted from " + client.getInetAddress ());
                        list_val = list_val + 1;
                        System.out.println("list_val is "+ list_val);
                        ServerThread st = new ServerThread(client);
                        st.start();
              catch ( java.io.InterruptedIOException e )
                   System.out.println("InterruptedIOException Occured");
                   e.printStackTrace();
              catch(Exception e)
              System.out.println("error " + e);
         public static void main(String args[])
              NewServer server = new NewServer();
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.net.Socket;
    import java.util.Vector;
    import java.io.*;
    import java.util.*;
    class ServerThread extends Thread {
         protected Socket client;
         protected static int key;
         OutputStreamWriter outputstream = null;
              BufferedReader br;
              static String[] message_split;
         ServerThread(Socket client) {
         this.client = client;
         try
              outputstream = new OutputStreamWriter(client.getOutputStream());
              br = new BufferedReader(new InputStreamReader(client.getInputStream()));
         catch(Exception e5)
         //protected static HashMap map = new HashMap();
         protected static Vector handlers = new Vector ();
         public void run() {
         try
              handlers.addElement (this);
              //map.put(key,this);
                   while (true)
                        String msg = br.readLine() + "\n";
                        broadcast (msg);
         catch (Exception e)
              e.printStackTrace();
         finally
              handlers.removeElement(this);
              try
              client.close();
              catch (Exception e2)
              System.out.println("Oh no! " +
              e2.toString());
         protected static void broadcast (String message)
         synchronized (handlers)
                   Enumeration e = handlers.elements ();
                   //while (e.hasMoreElements ())
                   //ServerThread st = (ServerThread) e.nextElement ();
                        ServerThread st = (ServerThread) handlers.get(AppletClient.list.getSelectedIndex());
                        try
                             System.out.println("in try");
                             synchronized (st.outputstream)
                                  System.out.println("in outputstream");
                                  st.outputstream.write("Client : " + message);
                             st.outputstream.flush ();
                        catch (IOException ex)
         }// method broadcast ends
    }// ServerThread ends
    pls run the server...NewServer.java and open 3 or 4 instances of AppletClient....whenever the client selects any particular index from list...the message should go to that client
    thanks in advance

  • Get datetime to a JFrame...

    i need to get the current system date & time to JFrame (to display)...also it should change dynamically according to the systems date&time
    (i.e it should change from second to second...)
    i tried it with a JApplet (call the JApplet in-side the JFrame...)
    Like this...
    //JApplet
    String lastTime = "";
    GregorianCalendar day = new GregorianCalendar();
    String time = day.getTime().toString();
    try {
    Thread.sleep(1000);
    } catch (InterruptedException e) {
    // do nothing
    lastTime = time;
    repaint();
    //JFrame
         BorderLayout bord=new BorderLayout();
         getContentPane().setLayout(bord);
         appletTest aT=new appletTest();     //instance from JApplet
         getContentPane().add("Center",aT);
    But, here it is not erase the previous value...It just overlap...
    (if seconds...2 is overlap with 1....then 3 is overlap with 2)
    How to avoid this...
    OR
    Is there other way of get the date&time to a JFrame.
    pls...tell
    thanks

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.lang.*;
    import java.util.*;
    import java.applet.*;
    <Applet code=AppletDate.class width=500 height=400>
    </Applet>
    public class AppletDate extends Applet implements Runnable
    GregorianCalendar cal;
    Thread thread=null;
    Date date;
    public void start()
           if(thread==null)
                thread=new Thread(this);
                thread.start();
         }//start
         public void run()
              while(thread!=null)
                   repaint();
                   try
                        thread.sleep(1000);
                   catch (Exception E)
                        System.out.println(E);
                   }//catch
              }//while
         }//run
         public void paint(Graphics g)
              String time;
            date=new Date();
              GregorianCalendar cal=new GregorianCalendar();
              cal.setTime(date);
              time=cal.get(cal.HOUR)+":"+cal.get(cal.MINUTE)+":"+cal.get(cal.SECOND);
              g.drawString(time,30,30);
    }

  • Error creating instance of class from same package

    When I try to create an instance of a class that is in the same package, my IDE indicates that the constructor can not be found. Can anyone tell me what is wrong? Thanks. Below are the codes for both classes:
    package com.practice;
    import java.applet.*;
    import java.awt.*;
    import javax.swing.*;
    public class WebProject extends Applet{
         public void init(){
                    // The following line is where the IDE indicates there is an error
              UserInterface gui = new UserInterface();
         } // end init()
         public void start(){
         } // end start()
         public void stop(){
         } // end stop()
         public void destroy(){
         } // end destory()
    } // end class
    package com.practice;
    import java.applet.*;
    import java.awt.*;
    import javax.swing.*;
    public class UserInterface extends Applet{
         JPanel menuPanel = new JPanel();
         JPanel contentPanel = new JPanel();
         JPanel savePanel = new JPanel();
         ImageIcon saveIcon = new ImageIcon("workspace/images/toolbarButtongraphics/general/Save24");
         JButton saveButton = new JButton("Save", saveIcon);
         public UserInterface(){
              savePanel.add(saveButton);
              setLayout(new BorderLayout());
              add(menuPanel, BorderLayout.NORTH);
              add(contentPanel, BorderLayout.CENTER);
              add(savePanel, BorderLayout.SOUTH);
    } // end UserInterface class

    Thanks for the explanation and example. At first, I didn't understand what you were getting at, but after reading "Using Top-Level Containers" and "How to Use Root Panes" java tutorials it made much more sense. Unfortunately, the books I've read up to this point, did not cover those topics at all. The books simply stated that the first step in creating a Swing gui was to extend the JFrame, or JApplet, or etc.
    Unfortunately, my original problem persists. I continue to get compile-time errors such as:
    TestUserInterface.java:5: cannot find symbol
    symbol: class UserInterface
    location: class projects.web.TestUserInterface
                          UserInterface ui = new UserInterface(); Anyone know why?
    Both the classes are in the same named packaged. Below is my code:
    package projects.web;
    import java.awt.*;
    import javax.swing.*;
    public class UserInterface extends JFrame{
         JPanel menuPanel = new JPanel();
         JPanel contentPanel = new JPanel();
         JPanel selectionPanel = new JPanel();
         JButton save = new JButton("Save");
         JButton addFiles = new JButton("Add");
         public UserInterface(){
         super("File Upload");
         setSize(500, 500);
         menuPanel.add(addFiles);
         selectionPanel.add(save);
         setLayout(new BorderLayout());
         add(menuPanel, BorderLayout.NORTH);
         add(contentPanel, BorderLayout.CENTER);
         add(selectionPanel, BorderLayout.SOUTH);
         } // end constructor
    } // end UserInterface class
    package projects.web;
    public class TestUserInterface{
         public static void main(String[] args){
              UserInterface ui = new UserInterface();
    } // end TestUserInterface class

  • Creation of an applet JApplet in a desktop JDesktopPane

    how its posible to load from a jar file an applet which come from package my.package.myclass of the jar file.
    next i want to put it in a JInternalFrame and put this desktop frame in a JDesktopPane.
    indeed i can move the applet around with other applets in a little window!
    here's the code of the desktop_panel.javapackage kevin_shell;
    import kevin_shell.Kdemos.*;
    import java.awt.*;
    import java.awt.event.*;
    import java2d.MemoryMonitor;
    //import java2d.demos.Lines.*;
    import javax.swing.*;
    import javax.swing.border.BevelBorder;
    import javax.swing.border.Border;
    import com.l2fprod.gui.plaf.skin.Skin;
    import com.l2fprod.gui.plaf.skin.SkinLookAndFeel;
    public class desktop_panel extends JPanel {
    JInternalFrame win_info = new JInternalFrame();
    public void killme(KDemo demo) {
    demo = null;
    public void view_image(String file) {
    thread_load_cube load = new thread_load_cube(file);
    load.start();
    JPanel jPanel2 = new JPanel();
    JDesktopPane pan_workspace = new JDesktopPane();
    public void paint(Graphics p) {
    p.setColor(Color.blue);
    p.fillRect(0, 0, 1000, 1000);
    p.setColor(Color.red);
    p.drawString("kevin OS", 10, 10);
    super.paint(p);
    BorderLayout borderLayout1 = new BorderLayout();
    JPanel jPanel3 = new JPanel();
    JButton jButton1 = new JButton();
    JInternalFrame win_memory = new JInternalFrame();
    JInternalFrame win_terminal = new JInternalFrame();
    MemoryMonitor win_mem = new MemoryMonitor();
    KClock win_perf = new KClock();
    JPanel jPanel4 = new JPanel();
    JLabel jLabel1 = new JLabel();
    JButton jButton2 = new JButton();
    JLabel jLabel6 = new JLabel();
    JLabel jLabel4 = new JLabel();
    JButton but_collect = new JButton();
    JButton but_refresh = new JButton();
    JTextField nb_free = new JTextField();
    Border border1;
    Border border2;
    JLabel jLabel2 = new JLabel();
    JTextField ed_jdk_path = new JTextField();
    JTextField nb_total = new JTextField();
    JLabel jLabel3 = new JLabel();
    JLabel jLabel5 = new JLabel();
    bean_clock bean_clock1 = new bean_clock();
    JPanel jPanel5 = new JPanel();
    JPanel jPanel1 = new JPanel();
    JTabbedPane tabber = new JTabbedPane();
    BorderLayout borderLayout2 = new BorderLayout();
    JList list1 = new JList();
    JList list_system = new JList();
    JList list3 = new JList();
    JButton jButton3 = new JButton();
    JButton jButton4 = new JButton();
    JButton jButton5 = new JButton();
    JButton jButton6 = new JButton();
    test_applet Itest_applet = new test_applet();
    JButton jButton7 = new JButton();
    public desktop_panel() {
    try {
    jbInit();
    System.out.println("initializing desk");
    bean_clock1.setLocation(0, 0);
    bean_clock1.setSize(win_info.getPreferredSize());
    //bean_clock1.start();
    pan_workspace.add(win_info);
    win_info.show();
    win_info.setLocation(0, 0);
    win_info.setSize(win_info.getPreferredSize());
    //Class bruno=java.lang.ClassLoader.getSystemClassLoader().loadClass("demo_cube");
    //Object b=bruno.newInstance();
    pan_workspace.add(win_memory);
    win_memory.show();
    win_memory.setSize(win_memory.getPreferredSize());
    pan_workspace.add(win_terminal);
    win_terminal.show();
    win_terminal.setSize(win_terminal.getPreferredSize());
    pan_workspace.add(win_mem);
    win_mem.setVisible(true);
    win_mem.setSize(win_mem.getPreferredSize());
    pan_workspace.add(win_perf);
    win_perf.setVisible(true);
    win_perf.setSize(100, 100);
    win_perf.setLocation(400, 400);
    win_perf.startClock();
    //list_system.add("welcome to kevin os");
    //tabber.add(list_system);
    tabber.add(list1);
    tabber.add(list3);
    win_terminal.getContentPane().add(tabber, BorderLayout.CENTER);
    win_terminal.setSize(300, 300);
    win_terminal.setResizable(true);
    win_terminal.setLocation(400, 400);
    System.out.println("ok");
    } catch (Exception e) {
    e.printStackTrace();
    class thread_load_cube extends Thread {
    String file;
    thread_load_cube() {
    file = "pics/babe1.jpg";
    thread_load_cube(String f) {
    file = f;
    //win_cube
    public void run() {
    try {
    System.out.println("cube loading");
    Class demo = java.lang.ClassLoader.getSystemClassLoader().
    loadClass("kevin_shell.Kdemos.demo_cube");
    KDemo win_cube = (KDemo) demo.newInstance();
    //list_system.add("win cube (loading....)");
    java.net.URL stoneURL = main_win.class.getResource(file);
    java.net.URL skyURL = main_win.class.getResource(
    "pics/babe2.jpg");
    //win_cube=new demo_cube();
    win_cube.set_parameters(stoneURL, skyURL);
    //pan_workspace.add(win_cube);
    win_cube.show();
    win_cube.setLocation(300, 300);
    win_cube.setSize(300, 300);
    win_cube.setResizable(true);
    win_cube.setTitle("java 3d cube");
    win_cube.setIconifiable(true);
    win_cube.init();
    win_cube.setClosable(true);
    System.out.println("ok");
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    System.out.println("problem with class");
    } catch (IllegalAccessException e) {
    e.printStackTrace();
    System.out.println("acces problem");
    } catch (InstantiationException e) {
    e.printStackTrace();
    System.out.println("instance");
    class thread_load_j3d extends Thread {
    public void run() {
    //list_system.add("j3d test loading...");
    //kev
    try {
    Class demo = java.lang.ClassLoader.getSystemClassLoader().
    loadClass("kevin_shell.Kdemos.demo_j3d");
    KDemo win = (KDemo) demo.newInstance();
    //pan_workspace.add(win);
    win.show();
    win.setLocation(300, 300);
    win.setSize(300, 300);
    win.setResizable(true);
    win.setTitle("j3d test");
    win.setIconifiable(true);
    win.init();
    win.setClosable(true);
    System.out.println("ok");
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    System.out.println("problem with class");
    } catch (IllegalAccessException e) {
    e.printStackTrace();
    System.out.println("acces problem");
    } catch (InstantiationException e) {
    e.printStackTrace();
    System.out.println("instance");
    private void jbInit() throws Exception {
    border1 = BorderFactory.createMatteBorder(4, 4, 4, 4,
    new Color(91, 91, 91));
    border2 = BorderFactory.createBevelBorder(BevelBorder.RAISED,
    Color.white, Color.white,
    new Color(153, 153, 204),
    new Color(153, 153, 204));
    jButton2.setBackground(Color.white);
    jButton2.setBorder(BorderFactory.createLineBorder(Color.black));
    jButton2.setPreferredSize(new Dimension(70, 70));
    //jButton2.setIcon(new ImageIcon(desktop_panel.class.getResource("icons/on_kevin.gif")));
    jButton2.setMargin(new Insets(0, 0, 0, 0));
    jButton2.setBounds(new Rectangle(9, 6, 52, 54));
    jLabel1.setFont(new java.awt.Font("Dialog", 1, 70));
    jLabel1.setForeground(SystemColor.desktop);
    jLabel1.setText("kevin os 1.0");
    jLabel1.setBounds(new Rectangle(66, 6, 255, 22));
    this.setLayout(borderLayout1);
    this.setBackground(UIManager.getColor("EditorPane.selectionBackground"));
    jPanel2.setLayout(null);
    jPanel2.setBackground(UIManager.getColor(
    "InternalFrame.activeTitleBackground"));
    jPanel2.setMaximumSize(new Dimension(100, 100));
    jPanel2.setMinimumSize(new Dimension(100, 100));
    jPanel2.setPreferredSize(new Dimension(100, 100));
    jPanel3.setBackground(new Color(255, 231, 0));
    jPanel3.setPreferredSize(new Dimension(60, 10));
    jButton1.setBackground(Color.white);
    jButton1.setBorder(BorderFactory.createLineBorder(Color.black));
    jButton1.setPreferredSize(new Dimension(50, 50));
    //jButton1.setIcon(new ImageIcon(desktop_panel.class.getResource("icons/info.gif")));
    jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    jButton1_mouseClicked(e);
    pan_workspace.setBackground(UIManager.getColor(
    "List.selectionBackground"));
    pan_workspace.setOpaque(false);
    pan_workspace.setAlignmentX((float) 0.0);
    pan_workspace.setAlignmentY((float) 0.0);
    pan_workspace.setLayout(null);
    win_memory.setToolTipText("");
    win_memory.getContentPane().setBackground(SystemColor.controlDkShadow);
    win_memory.setTitle("memory");
    win_memory.setBorder(border2);
    win_memory.setIconifiable(true);
    win_memory.setNormalBounds(new Rectangle(10, 10, 381, 254));
    win_memory.setPreferredSize(new Dimension(381, 254));
    win_memory.setMinimumSize(new Dimension(381, 254));
    win_info.setFrameIcon(null);
    win_info.setPreferredSize(new Dimension(269, 230));
    win_info.setMinimumSize(new Dimension(269, 230));
    win_info.setBorder(border2);
    win_info.getContentPane().setBackground(UIManager.getColor(
    "CheckBoxMenuItem.selectionBackground"));
    win_info.setMaximumSize(new Dimension(100, 100));
    win_info.setResizable(true);
    win_info.setIconifiable(true);
    win_info.setTitle("kevin OS info");
    but_collect.setBackground(Color.orange);
    but_collect.setText("garbage collector");
    but_collect.setBounds(new Rectangle(13, 114, 162, 31));
    but_collect.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    but_collect_mouseClicked(e);
    but_refresh.setText("refresh");
    but_refresh.setBounds(new Rectangle(11, 150, 162, 32));
    but_refresh.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    but_refresh_mouseClicked(e);
    nb_free.setBackground(Color.white);
    nb_free.setDisabledTextColor(Color.white);
    nb_free.setEditable(false);
    nb_free.setBounds(new Rectangle(107, 40, 108, 22));
    jPanel4.setBackground(UIManager.getColor(
    "InternalFrame.activeTitleBackground"));
    jLabel2.setBackground(Color.pink);
    jLabel2.setFont(new java.awt.Font("Dialog", 1, 50));
    jLabel2.setForeground(Color.red);
    jLabel2.setText("-OS-");
    jLabel2.setBounds(new Rectangle(98, 12, 139, 52));
    ed_jdk_path.setBackground(Color.white);
    ed_jdk_path.setDisabledTextColor(Color.white);
    ed_jdk_path.setEditable(false);
    ed_jdk_path.setBounds(new Rectangle(104, 14, 190, 22));
    nb_total.setBackground(Color.white);
    nb_total.setDisabledTextColor(Color.white);
    nb_total.setEditable(false);
    nb_total.setBounds(new Rectangle(228, 40, 108, 22));
    jLabel3.setToolTipText("");
    jLabel3.setText("free");
    jLabel3.setBounds(new Rectangle(106, 70, 112, 16));
    jLabel5.setBounds(new Rectangle(228, 70, 112, 16));
    jLabel5.setText("total");
    jLabel5.setToolTipText("");
    win_terminal.setTitle("terminal");
    jPanel5.setLayout(borderLayout2);
    jButton3.setPreferredSize(new Dimension(50, 27));
    jButton3.setText("cube");
    jButton3.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    jButton3_actionPerformed(e);
    jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    jButton3_mouseClicked(e);
    jButton4.setText("test");
    jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    jButton4_mouseClicked(e);
    jButton5.setText("skin cool");
    jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    jButton5_mouseClicked(e);
    jButton6.setText("skin xp");
    jButton6.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    jButton6_mouseClicked(e);
    jButton7.setText("test applet");
    jButton7.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    jButton7_actionPerformed(e);
    win_memory.getContentPane().add(jPanel4, BorderLayout.CENTER);
    jPanel4.setLayout(null);
    jPanel4.setMinimumSize(new Dimension(100, 100));
    jPanel4.setPreferredSize(new Dimension(100, 100));
    jLabel6.setText("java memory");
    jLabel6.setBounds(new Rectangle(16, 40, 78, 18));
    jLabel4.setText("jdk path");
    jLabel4.setBounds(new Rectangle(18, 16, 76, 18));
    this.add(jPanel3, BorderLayout.WEST);
    jPanel3.add(jButton7);
    jPanel3.add(jButton1, null);
    jPanel3.add(jButton3, null);
    jPanel3.add(jButton4, null);
    jPanel3.add(jButton5, null);
    jPanel3.add(jButton6, null);
    this.add(pan_workspace, java.awt.BorderLayout.CENTER);
    jPanel4.add(jLabel4, null);
    jPanel4.add(jLabel6, null);
    jPanel4.add(but_collect, null);
    jPanel4.add(ed_jdk_path, null);
    jPanel4.add(nb_free, null);
    jPanel4.add(nb_total, null);
    jPanel4.add(but_refresh, null);
    jPanel4.add(jLabel3, null);
    jPanel4.add(jLabel5, null);
    win_info.getContentPane().add(jPanel2, BorderLayout.CENTER);
    jPanel2.add(jButton2, null);
    jPanel2.add(jLabel1, null);
    jPanel2.add(jLabel2, null);
    tabber.add(list1, "list1");
    tabber.add(list_system, "list_system");
    tabber.add(list3, "list3");
    void but_refresh_mouseClicked(MouseEvent e) {
    nb_free.setText(String.valueOf(java.lang.Runtime.getRuntime().
    freeMemory()));
    nb_total.setText(String.valueOf(java.lang.Runtime.getRuntime().
    totalMemory()));
    void jButton1_mouseClicked(MouseEvent e) {
    win_info.show();
    win_info.setLocation(0, 0);
    //win_info.setSize(100,100);
    void but_collect_mouseClicked(MouseEvent e) {
    java.lang.Runtime.getRuntime().gc();
    but_refresh_mouseClicked(e);
    //list_system.add("collecting memory");
    void jButton3_mouseClicked(MouseEvent e) {
    //win_cube.begin_anim();
    void jButton4_mouseClicked(MouseEvent e) {
    thread_load_j3d load = new thread_load_j3d();
    load.start();
    void jButton6_mouseClicked(MouseEvent e) {
    try {
    Skin skin = null;
    //windows xp
    skin = SkinLookAndFeel.loadThemePack("skins/BeOS-theme.jar");
    // set the skin
    SkinLookAndFeel.setSkin(skin);
    // ask Swing to use Skin Look And Feel
    UIManager.setLookAndFeel(
    "com.l2fprod.gui.plaf.skin.SkinLookAndFeel");
    SwingUtilities.updateComponentTreeUI(this);
    this.validate();
    this.updateUI();
    } catch (Exception er) {
    System.out.println("Failed loading L&F: ");
    er.printStackTrace();
    void jButton5_mouseClicked(MouseEvent e) {
    try {
    Skin skin = null;
    skin = SkinLookAndFeel.loadThemePack("skins/themepack.zip");
    // set the skin
    SkinLookAndFeel.setSkin(skin);
    // ask Swing to use Skin Look And Feel
    UIManager.setLookAndFeel(
    "com.l2fprod.gui.plaf.skin.SkinLookAndFeel");
    } catch (Exception er) {
    er.printStackTrace();
    void jButton3_actionPerformed(ActionEvent e) {
    thread_load_cube load = new thread_load_cube();
    load.start();
    public void jButton7_actionPerformed(ActionEvent e) {
    JApplet applet=null;
    frame_applet frame=null;
    try{
    //ExtClassLoader ecl = new ExtClassLoader("/home/kevinet/CODE/JAVA/jlguiapplet2.3.1-selfsigned/lib/jlguiapplet2.3.jar");
    //Class demo = ecl.loadClass("javazoom.jlgui.player.amp.PlayerApplet");
    Class demo = java.lang.ClassLoader.getSystemClassLoader().loadClass("kevin_shell.Kdemos.test_applet");
    applet = (JApplet) demo.newInstance();
    frame=new frame_applet(applet);
    } catch (ClassNotFoundException cnfe) {
    cnfe.printStackTrace();
    System.out.println("problem with class");
    catch (IllegalAccessException iae) {
    iae.printStackTrace();
    System.out.println("acces problem");
    catch (InstantiationException ie) {
    ie.printStackTrace();
    System.out.println("instance");
    System.out.println("hello");
    pan_workspace.add(frame);
    applet.init();
    //applet.setLocation(0,0);
    applet.start();
    frame.setVisible(true);
    frame.show();
    frame.setLocation(300, 300);
    frame.setSize(300, 300);
    frame.setResizable(true);
    frame.setTitle("test applet");
    frame.setIconifiable(true);
    frame.setClosable(true);
    }

    What about calling getLocation on the applet itself?
    Otherwise, if you are using Swing, you can try (where "this" is the applet object):
    javax.swing.SwingUtilities.getWindowAncestor(this).getLocation();
    or
    javax.swing.SwingUtilities.convertPointToScreen(this.getLocation(), this);
    The latter should work, at least.

  • Images in JApplet

    Hi!
    I am trying to convert a game application, made using Java - Swing combination, to an JApplet.
    First I installed the newest JRE1.3.1 from the java.sun.com and used the HTMLConverter.
    Testing revealed that the JApplet runs quite Ok in the Appletviewer.
    When I try to run it in Netscape 6.1 the game works otherwice except that it doesn't have any
    of it's pictures which are either in gif - or jpg formats. The Java Console doesn't tell me anything that might indicate a problem.
    The interesting part comes when I try to run the same JApplet inside IE5.5. I get a message
    that states that the requested html-page (or one of its components) could not be found. At the
    same time thought an instance of the Netscape 6.1 is being launched and, to my surprise, the
    JApplet runs Ok in it.
    If I try to run the JApplet in Opera 5.12 I just get a message saying that a connection to the
    running virtual machine could not be established.
    At home I use Linux and KDE's browser Konqueror. That's the only one that gives a securityexception for the read operation of the images.
    At work, where I have Win 2000, I have tried to play with policytool in order to grant the required reading permissions, but I haven't succeeded yet.
    I would appreciate any help in solving this mystery.
    Jussi

    Image         map;
    URL url = null;
    try
             url = new URL(getCodeBase()+"usa.gif");
         catch(MalformedURLException e)
    map = getToolkit().createImage(url);
    MediaTracker tracker = new MediaTracker(this);
    tracker.addImage(map,0);
    try   {tracker.waitForID(0);}
    catch (InterruptedException e){} .
    //usa.gif is the name of the file
    Noah

  • Preserve aspect ratio of JPanel size within JApplet

    Hi, currently, I have a JPanel component, which will be placed at the center of JApplet (This JApplet is BorderLayout).
    I wish to preserve the aspect ratio of the JPanel to square (width equal to height) even when the JApplet size is changed.
    I overriden the getPreferredSize, getMinimumSize and getMaximumSize of JPanel as follow:
    import java.awt.*;
    * @author  yccheok
    public class NewJPanel extends javax.swing.JPanel {
        /** Creates new form NewJPanel */
        public NewJPanel() {
            initComponents();
            this.setBackground(Color.RED);
        public Dimension getMinimumSize() {
            Dimension dimension;
            dimension = super.getMinimumSize();
            Dimension newDimension;
            if(dimension.getWidth() < dimension.getHeight()) {
                newDimension = new Dimension((int)dimension.getWidth(), (int)dimension.getWidth());
            else {
                newDimension = new Dimension((int)dimension.getHeight(), (int)dimension.getHeight());
            System.out.println("newDimension="+newDimension);
            return newDimension;
        public Dimension getMaximumSize() {
            return getMinimumSize();
        public Dimension getPreferredSize() {
            return getMinimumSize();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                         
        private void initComponents() {
            setLayout(new java.awt.BorderLayout());
        // </editor-fold>                       
        // Variables declaration - do not modify                    
        // End of variables declaration                  
    }whereas my JApplet code is as follow:
    import java.awt.*;
    import javax.swing.*;
    * @author yccheok
    public class NewJApplet extends javax.swing.JApplet {
        /** Creates a new instance of NewJApplet */
        public NewJApplet() {
        public void init()
            this.getContentPane().setLayout(new BorderLayout());
            this.getContentPane().add(new NewJPanel(), BorderLayout.CENTER);
    }However, I realize none of the JPanel's getPreferredSize, getMinimumSize or getMaximumSize is called. Am I doing something wrong?
    Thank you very much!

    You probably should create your own layout manager

  • Can I add controls at runtime in JApplet

    Please also tell me what good is JApplet for. As I cannot interact with database and there are several other limitations. Should I go and use JApplet in my application or avoid using them.
    My basic question remains the same "Can I add controls at runtime in JApplet"

    Yes, you can add controls to an applet at runtime.
    Applets are run on remote computers, in browsers for instance.
    Since they are run remotely, connecting to a database can be difficult. In most cases you'll need a server that makes the connection with the database. The applet speaks with the server via a socket.
    If you're writing a standard desktop application, then you should use JFrame.

  • Rmi client and jApplet

    Hi,
    I am trying to use a jApplet as an rmi client. However, either creating a new instance of the class i created, that extends jApplet, in the rmi client class i created or creating a new instance of the rmi client in the class that extends jApplet results in error.
    What is the correct way to go about doing this? I developed the jApplet thinking it could be simply used with the rmi client.
    instanciating the rmi client in the jApplet class gives :
    java.lang.OutOfMemory Error
    instanciating the jApplet class in the rmi client class gives other errors I am unable to reproduce at the moment :(
    thanks for any help
    -Paulo Murphy de Freitas

    Hi,
    I am trying to use a jApplet as an rmi client. However, either creating a new instance of the class i created, that extends jApplet, in the rmi client class i created or creating a new instance of the rmi client in the class that extends jApplet results in error.
    What is the correct way to go about doing this? I developed the jApplet thinking it could be simply used with the rmi client.
    instanciating the rmi client in the jApplet class gives :
    java.lang.OutOfMemory Error
    instanciating the jApplet class in the rmi client class gives other errors I am unable to reproduce at the moment :(
    thanks for any help
    -Paulo Murphy de Freitas

  • Caching images in a JApplet

    I have a JApplet here:
    http://www.jujubees.org/java_photo_album/photoAlbum.html
    the code is coming along well but I have one major problem. The images seem to take for ever to download even with a high speed cable connection (so god only knows how long a dial up would take). What technique can I use to make sure the images are being cached in the web browser? Also is there a way to check and see if the browser has cached a certain image? If you want to see the code then I could post it.

    I have a JApplet here:
    http://www.jujubees.org/java_photo_album/photoAlbum.htm
    the code is coming along well but I have one major
    problem. The images seem to take for ever to download
    even with a high speed cable connection (so god only
    knows how long a dial up would take). What technique
    can I use to make sure the images are being cached in
    the web browser? Also is there a way to check and see
    if the browser has cached a certain image? If you want
    to see the code then I could post it.Well you could check to see if the images are being cached by printing out the details of your images, byte size and so on. If you want the browser to cache all the images what you could do is feed the location of the images into the applet, with a parameter for instance, then create a thread that iterates over the images in the directory and loads them into a hashtable of some kind. So the rendering would be faster. Or put them into a .jar/.zip, would be faster. You don't have to wait for all the images to load to display the first one.
    Unless you are manually coding the images in your code you can be fairly certain that the browser is not going to. Perhaps with advanced browsers like Opera, but even then, no.
    See ya
    Michael

  • Cant get image to load in JApplet - java.security.AccessControlException

    hi,
    I need to make a JApplet that loads and displays images. Before I worry about media tracker or anything else I need to get the image to load.
    My code is:
    package Applet;
    import java.awt.*; 
    import javax.swing.*;
    import java.applet.*;
    * @author Nick
    public class TestJApplet extends JApplet {
        /** Creates a new instance of TestJApplet */
        public TestJApplet() {
        public void init()
        public void paint(Graphics g)
            Image image;
            image = getImage(this.getDocumentBase(),"a.gif");
            g.drawRect(30,30,30,30);
    }where a.gif is located in the same folder as the .java file.
    I get the following message:
    Exception in thread "AWT-EventQueue-1" java.security.AccessControlException: access denied (java.io.FilePermission \C:\Documents and Settings\Nick\Math\build\a.gif read)
            at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
            at java.security.AccessController.checkPermission(AccessController.java:427)
            at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
            at java.lang.SecurityManager.checkRead(SecurityManager.java:871)
            at sun.awt.image.URLImageSource.<init>(URLImageSource.java:37)
            at sun.applet.AppletImageRef.reconstitute(AppletImageRef.java:33)
            at sun.misc.Ref.get(Ref.java:47)
            at sun.applet.AppletViewer.getCachedImage(AppletViewer.java:377)
            at sun.applet.AppletViewer.getImage(AppletViewer.java:372)
            at java.applet.Applet.getImage(Applet.java:236)
            at java.applet.Applet.getImage(Applet.java:258)
            at Applet.TestJApplet.paint(TestJApplet.java:27)
            at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
            at sun.awt.RepaintArea.paint(RepaintArea.java:224)
            at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:254)
            at java.awt.Component.dispatchEventImpl(Component.java:4031)
            at java.awt.Container.dispatchEventImpl(Container.java:2024)
            at java.awt.Component.dispatchEvent(Component.java:3803)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
            at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
    Exception in thread "AWT-EventQueue-1" java.security.AccessControlException: access denied (java.io.FilePermission \C:\Documents and Settings\Nick\Math\build\a.gif read)
            at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
            at java.security.AccessController.checkPermission(AccessController.java:427)
            at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
            at java.lang.SecurityManager.checkRead(SecurityManager.java:871)
            at sun.awt.image.URLImageSource.<init>(URLImageSource.java:37)
            at sun.applet.AppletImageRef.reconstitute(AppletImageRef.java:33)
            at sun.misc.Ref.get(Ref.java:47)
            at sun.applet.AppletViewer.getCachedImage(AppletViewer.java:377)
            at sun.applet.AppletViewer.getImage(AppletViewer.java:372)
            at java.applet.Applet.getImage(Applet.java:236)
            at java.applet.Applet.getImage(Applet.java:258)
            at Applet.TestJApplet.paint(TestJApplet.java:27)
            at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
            at sun.awt.RepaintArea.paint(RepaintArea.java:224)
            at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:254)
            at java.awt.Component.dispatchEventImpl(Component.java:4031)
            at java.awt.Container.dispatchEventImpl(Container.java:2024)
            at java.awt.Component.dispatchEvent(Component.java:3803)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
            at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)Could someone help me get an image to load in an Applet/JApplet.
    Cheers :)

    From looking at your code there are two problems... the first is that you have a security exception being thrown because you are attempting to load a file locally with insufficient privileges to do so. This is because Applets have additional security levied on them so they don't say, in this circumstance steal a file off the loaded machine and send it back to the server that delivered them.
    If you want to get your applet to load a local file (I don't think that is what you're asking here) then you have to digitally sign your applet and allow the user to decide if they want to be allow it to load a local file.
    Nutshell is that you need to understand that the URL returned from getDocumentBase() in an applet is going to be from the Jar file you send the applet with or the URL you served the applet from. This is a bit of debugging code to show you what you are looking at and hopefully explain anything ambiguous I may have stated.
    package testapplication;
    import java.awt.EventQueue;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    * Description : <p></p>
    * @author John Michael Resler<br/>
    * Class : DocBaseApplet<br/>
    * Creation Time : 8:31 AM<br/>
    * Creation Date : June 18, 2006<br/>
    * Compiler : Sun Java Community Edition (version 1.5.0_06)<br/>
    public class DocBaseApplet extends javax.swing.JApplet implements MouseListener {
         * Initializes the applet DocBaseApplet
        public void init() {
            try {
                EventQueue.invokeAndWait(new Runnable() {
                    public void run() {
                        initComponents();
            } catch (Exception ex) {
                ex.printStackTrace();
        private void initComponents() {
            documentBaseLabel = new javax.swing.JLabel();
            documentBaseLabel.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    documentBaseLabelMouseClicked(evt);
            org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .addContainerGap()
                    .add(documentBaseLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
                    .addContainerGap())
            layout.setVerticalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .addContainerGap()
                    .add(documentBaseLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE)
                    .addContainerGap())
        private void documentBaseLabelMouseClicked(java.awt.event.MouseEvent evt) {                                              
            // TODO add your handling code here:
            this.documentBaseLabel.setText(this.getDocumentBase().toString());
        public void mouseClicked(MouseEvent e) {
        public void mousePressed(MouseEvent e) {
        public void mouseReleased(MouseEvent e) {
        public void mouseEntered(MouseEvent e) {
        public void mouseExited(MouseEvent e) {
        private javax.swing.JLabel documentBaseLabel;
    }

  • Java Swing Canvas --- JApplet

    i tried to change canvas Class to JPanel but when i run program
    it just draw it and it disappear(just my board)[canvas instance]
    the button dont disappear(they stay).
    if i press my other button then board come up again
    but in the start it just load and after it load up completley it disappear
    Public class ChessGame {
    JFrame a = new JFrame
    Chess a =new Chess()
    a.init()
    a.start();
    Class Chess extends JApplet
    Board board;
    public init()
    board = new board (this);
    class BOard extends Canvas
    // constructor
    public Board ( JApplet Refrence)
    thank u in advance

    Hi,
    i am not sure , but may be u are adding a heavy weight component over a light weight component, try converting every thing to AWT or SWING
    Ashish

  • JApplet ,JScrollPane, JPanel

    Hi,
    I have a class JTestPanel2 which extends JPanel, I have added a button to this class and overriden the paint method to draw some lines,
    In my JApplet, i create instance of Test class and add to the JSCrollPane, I add this JScrollPane to my JApplet content pane, the problem is i dont see the JButton on the screen , but when i click on some where i have added the JButton , i get the action performed event triggered,
    My layout for Test class is BorderLayout and i add the button to north,
    So what is the problem ..how can i solve it,
    Answere ASAP
    here is the code
    for JPAnel
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class JPanelTest2 extends JPanel implements ActionListener
         JPanel jp2 ;
         JButton jb;
         String message = "test";
         JPanelTest2()
              super();
              setLayout(new BorderLayout());
              jp2 = new JPanel();
              jb = new JButton("Okay");
              jb.addActionListener(this);
              jp2.add(jb);     
         setPreferredSize(new Dimension(400,400));
         add("North", jp2);
         jp2.setVisible(true)     ;
         public void paint(Graphics g)
    super.paintComponent(g);
    g.drawString(message, 200, 200);
    public void actionPerformed(ActionEvent ev)
         message = "change";
         repaint();
    Code for Applet
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class JPanelTest1 extends JApplet
         Container c ;
         public void init()
         c = getContentPane();
         c.setLayout(new BorderLayout());
    JPanelTest2 jp1= new JPanelTest2();
         JScrollPane js = new JScrollPane(jp1, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
         js.getHorizontalScrollBar().setMaximum(500);
         js.getHorizontalScrollBar().setValue(0);
         setSize(400,400);
         c.add("North", js);
    Ashish

    Do not override the drawing for your main container JPanel. Instead place another JPanel instance into the layout of your containing JPanel and draw with that. That will contain the drawing of that panel to just the area contained in that sub panel, and then it won't mess up the drawing of the other items contained within the main panel.

  • Coldfusion create instance of class from data element when cosuming a webservice

    I am calling the following wsdl via cfobject https://services-staging.labcorpsolutions.com/webservice/services/LabcorpOTS/wsdl/LabcorpO TS.wsdl
    I am attempting to call the following method registerDonor(java.lang.String, java.lang.String, com.labcorp.ots.ws.data.CreateRegistrationRequest) which references the CreateRegistrationRequest data element.
    I haven't been successful in creating an instance of the CreateRegistrationRequest class and setting values of its members, as well as the Phone class which is also a data element.
    Any assistance would be greatly appreciated in creating instances of methods located in the targetNamespace="http://data.ws.ots.labcorp.com" of the wsdl.
    Thanks

    Thanks for the explanation and example. At first, I didn't understand what you were getting at, but after reading "Using Top-Level Containers" and "How to Use Root Panes" java tutorials it made much more sense. Unfortunately, the books I've read up to this point, did not cover those topics at all. The books simply stated that the first step in creating a Swing gui was to extend the JFrame, or JApplet, or etc.
    Unfortunately, my original problem persists. I continue to get compile-time errors such as:
    TestUserInterface.java:5: cannot find symbol
    symbol: class UserInterface
    location: class projects.web.TestUserInterface
                          UserInterface ui = new UserInterface(); Anyone know why?
    Both the classes are in the same named packaged. Below is my code:
    package projects.web;
    import java.awt.*;
    import javax.swing.*;
    public class UserInterface extends JFrame{
         JPanel menuPanel = new JPanel();
         JPanel contentPanel = new JPanel();
         JPanel selectionPanel = new JPanel();
         JButton save = new JButton("Save");
         JButton addFiles = new JButton("Add");
         public UserInterface(){
         super("File Upload");
         setSize(500, 500);
         menuPanel.add(addFiles);
         selectionPanel.add(save);
         setLayout(new BorderLayout());
         add(menuPanel, BorderLayout.NORTH);
         add(contentPanel, BorderLayout.CENTER);
         add(selectionPanel, BorderLayout.SOUTH);
         } // end constructor
    } // end UserInterface class
    package projects.web;
    public class TestUserInterface{
         public static void main(String[] args){
              UserInterface ui = new UserInterface();
    } // end TestUserInterface class

  • How to catch window event on jApplet

    Could you please let me know, How to catch �activate window� event on Japplet page. I am using the following class.
    public class CtApplet
          extends JApplet
          implements Runnable, ErrorHandlerI could implement the same on Jframe by using the following Api�s. I assume they don�t exist on Japplet.
    this.addWindowListener (��.);
    class ��
          extends java.awt.event.WindowAdapter
        public void windowActivated (WindowEvent e)
            ��..
    }Edited by: samtek on Oct 30, 2007 7:59 PM
    I extened my japplet class from WindowListener, and added function, windowActivated(), But not able to catch the event.

    Hi,
    I would try AWTEventListener; it should work with a JFrame.
    Now I probably could have done this better but I made 2 classes for this.
    HyperFrame to run the applet as an Application and have the Frame handle
    the AWT events, and AWTEventManager to process the Events when running as an Applet. In the future I will probably merge into 1 AWTEventManager.
    https://hyperview.dev.java.net/source/browse/hyperview/www/HyperView299/AWTEventManager.java?rev=1.3&view=markup
    https://hyperview.dev.java.net/source/browse/hyperview/www/HyperView299/HyperFrame.java?rev=1.11&view=markup
    Anyway, omit the View/List specific code and look at the setup; it should work for you. BTW Not ATM multi instance friendly but on my todo list several hundred down.
    You will need to tweak the Thread control as well; probably AWTEventManager is the class to study as it really shows all you need to implement an AWTEventListener
    Good Luck!
    (T)

Maybe you are looking for