Results 1 to 11 of 11
Thread: JApplet display problem
- 06-03-2010, 07:55 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 9
- Rep Power
- 0
JApplet display problem
Hello,
I'm beginner in Java and totally new to making java (web) applets. I have made simple applet, my class is extending swing's JApplet class, there is a label and a button. I'm trying to test my applet in web browser, using <applet> html tag pointed to my jar file. I'm getting "Applet test3.Main started" info, but I can't see my applet on the page.
My Java Console is giving me this information:
For me everything looks fine. Could you help me?basic: Making reference to classloader: sun.plugin.ClassLoaderInfo @ 1e3bb9e, refcount = 2
basic: Added progress Client: sun.plugin.util.GrayBoxPainter $ GrayBoxProgressListener @ 1fc493
basic: Loading applet ...
Basic: Initiates applet ...
basic: Starting applet ...
basic: completed perf rollup
Basic: I stop an applet ...
basic: Removed customer's progress: sun.plugin.util.GrayBoxPainter $ GrayBoxProgressListener @ 653ad5
Basic: Destruction applet ...
Basic: Removing the applet ...
Basic: Connecting thread applet ...
Basic: Connected applet thread ...
Basic: I find information ...
Basic: fired classloader: sun.plugin.ClassLoaderInfo @ 1e3bb9e, refcount = 1
Basic: Ready ...
I'm attaching all my project files.
- 06-03-2010, 08:54 PM #2
Are there any error messages in the browser's Java console? Copy and paste them here.
- 06-03-2010, 09:04 PM #3
Member
- Join Date
- Jun 2010
- Posts
- 9
- Rep Power
- 0
I'm using FireFox 3.6. I don't know if there is a browser's Java Console, I only know about the browser-independent Java Console that comes with Java on Mac OS X. I've already past messages form that console in previous post.
- 06-03-2010, 09:27 PM #4
Your code works for me with AppletViewer and FF on WinXP.
I see a label "test 3" and a button.
- 06-03-2010, 10:14 PM #5
when i import the class Main.java in eclipse i got a punch of errors saying
org.jdesktop.layout.GroupLayout cannot be resolved to a type
http://java.sun.com/docs/books/tutor...upExample.htmlLast edited by j2me64; 06-03-2010 at 10:25 PM.
- 06-03-2010, 10:33 PM #6
OP must be using netbeans. It likes to use its own classes for GUI. I dug out swing-layout-1.0.3.jar and used it to compile and execute.
Using netbeans means you need to find its jar files and pass them out along with your applet's jar file. UGGGH!!Last edited by Norm; 06-03-2010 at 10:35 PM.
- 06-03-2010, 10:36 PM #7
with the following code i could eliminate all compiling errors and run the code
Java Code:import javax.swing.GroupLayout; import javax.swing.JButton; import javax.swing.JLabel; public class Main extends javax.swing.JApplet { /** Initializes the applet Main */ public void init() { try { java.awt.EventQueue.invokeAndWait(new Runnable() { public void run() { initComponents(); } }); } catch (Exception ex) { ex.printStackTrace(); } } /** * This method is called from within the init() method to initialize the * form. WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" // desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new JLabel("TEST 3"); jButton1 = new JButton("TEST BUTTON"); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup( GroupLayout.Alignment.LEADING).addGroup( layout.createSequentialGroup().addContainerGap().addComponent( jLabel1).addContainerGap(18, 18).addComponent(jButton1) .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); layout.setVerticalGroup(layout.createParallelGroup( GroupLayout.Alignment.LEADING).addGroup( layout.createSequentialGroup().addContainerGap().addGroup( layout.createParallelGroup( GroupLayout.Alignment.BASELINE).addComponent( jLabel1).addComponent(jButton1)) .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; // End of variables declaration//GEN-END:variables }
i changed some lines, for example add(18, 18, 18) to addContainerGap(18, 18) only to run the code. you can look at the output in the attachment.
- 06-03-2010, 11:43 PM #8
Why is the OP not able to get that output? Are there error messages in the Java console?
@OP do you reference the jar file with the org.jdesktop.layout package in your html and have that jar file in folder with html file?
- 06-04-2010, 11:07 PM #9
Member
- Join Date
- Jun 2010
- Posts
- 9
- Rep Power
- 0
Thank you guys, I'm glad to get your support. I think the problem is in browser cache or life cycle of an applet. I have to restart my browser (checked in FireFox and Chrome) any time I want to test some changes in applet. Otherwise the browser running old version of applet, even if I delete my browser's history and cache.
Now I know that using NetBeans form designer for web applets it's not good choice. Btw there is so many limitation for JApplets, that I'm going to build desktop application first. Thanks a lot again.
- 06-05-2010, 06:46 AM #10
Congratulations on discovering for yourself what most newbies are unwilling to accept even when told repeatedly.
Indeed, you should avoid any visual GUI designer at least until you are competent to read and understand the code it generates. And desktop applications are indeed easier for a beginner than applets with their sandboxed environment and attendant security restrictions.
Just don't make the only-too-common mistake of extending JFrame for all your desktop applications, even though that's the approach you'll find in many tutorials, including the one on the Sun/Oracle site.
db
- 06-05-2010, 07:02 AM #11
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
Indeed as
Daryl.Burke said earlier, coding GUI's by hand is so rewarding and providing the right layout manager, far more control, try GridBagLayout() complicated but rewarding.
The reasons for applet restrictions is obvious when you think about it. If an applet could have access to an operating system e.g. a file then all kind of security breaches would happpen!!! better to get your own little server like xampp and sign your own applets for testing. I use xampp for testing out php and mysql and use the localhost webserver everybody has..Personally I think applets are dead and not worth it anymore....
like I tell everybody read, read and read, the more serious you are about programming the more you are above your peers. and the more you WANT to read.
good luck....
Similar Threads
-
Loops and display problem
By lk1001 in forum New To JavaReplies: 6Last Post: 02-26-2010, 04:26 PM -
JFrame to JApplet or JApplet to JApplet
By ramesh.8189 in forum AWT / SwingReplies: 13Last Post: 02-08-2009, 06:14 AM -
JApplet Problem
By tanmoy.b81 in forum AWT / SwingReplies: 2Last Post: 07-28-2008, 06:56 AM -
Another problem in JApplet :S
By juju in forum Java AppletsReplies: 2Last Post: 12-30-2007, 07:46 PM -
How to display an image in JApplet
By fred in forum Java AppletsReplies: 1Last Post: 07-24-2007, 02:02 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks