Results 1 to 15 of 15
- 09-07-2011, 11:15 PM #1
Member
- Join Date
- Jul 2011
- Posts
- 53
- Rep Power
- 0
JApplet works in eclipse but refuses to show online
So I got this JApplet that has a JPanel attached to it. (code below)
When I run the program in Eclipse (Indigo) it works perfectly.
So I build the entire .java to .class files and insert it in a html code:
But the problem doesn't seem to be related to the HTML code (that's my guess!! I could be wrong). All I see when I open the site is a white background (you can slightly see the contours of the applet)Java Code:<P><applet code="MaraudersOfDeepSpace.class" width="650" height="400"> Your browser does not support the <code>applet</code> tag. </applet></P>
The code I'm trying to display on the site:
JApplet:
JPanel:Java Code:import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Color; import java.awt.Graphics; import javax.swing.JApplet; import javax.swing.JPanel; public class MaraudersOfDeepSpace extends JApplet { /** * */ private static final long serialVersionUID = 1L; MenuPanel mainMenu; final String MENU = "Menu"; final String LOAD = "Load"; final String OBJECTIVE = "Objective"; final String CONTROLS = "Controls"; private CardLayout cardsLayout = new CardLayout(); private JPanel cards = new JPanel(cardsLayout); public void init() { [COLOR="#FF0000"]System.out.print("1/");[/COLOR] mainMenu = new MenuPanel(this); cards.add(mainMenu, MENU); //cards.add(load, LOAD); //cards.add(objective, OBJECTIVE); //cards.add(controls, CONTROLS); this.setSize(650, 400); this.add(cards, BorderLayout.CENTER); cards.setOpaque(true); setContentPane(cards); [COLOR="#FF0000"]System.out.print("4/");[/COLOR] } public void swapCards(String key) { cardsLayout.show(cards, key); } }
So it's actually just a simple JApplet with a JPanel...but it refuses to show on the siteJava Code:import java.awt.Color; import java.awt.Container; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Random; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JPanel; public class MenuPanel extends JPanel implements ActionListener { /** * */ private static final long serialVersionUID = 1L; Image title,earth,jupiter; Random random = new Random(); int[][] StarArray = new int[1000][2]; private MaraudersOfDeepSpace mar = null; public MenuPanel(MaraudersOfDeepSpace mar) { [COLOR="#FF0000"]System.out.print("2/");[/COLOR] this.mar=mar; this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); this.add(Box.createRigidArea(new Dimension(0,180))); AddAButton("New", this); //NEEDS MODIFICATION WHEN TIME IS RIGHT this.add(Box.createRigidArea(new Dimension(0,20))); AddAButton(mar.LOAD, this); this.add(Box.createRigidArea(new Dimension(0,20))); AddAButton(mar.OBJECTIVE, this); this.add(Box.createRigidArea(new Dimension(0,20))); AddAButton(mar.CONTROLS, this); [COLOR="#FF0000"]System.out.print("3/");[/COLOR] } private void AddAButton(String text, Container container) { JButton button = new JButton(text); button.setAlignmentX(CENTER_ALIGNMENT); button.addActionListener(this); container.add(button); } public void paintComponent(Graphics g) { g.setColor(Color.BLACK); g.fillRect(0, 0, getWidth(), getHeight()); System.out.print("5/"); } @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub } }
What did I already try?? (before you think I'm just too lazy!! :o)
- Putting another JApplet in place in the HTML-code, works fine (my conclusion: nothing wrong with HTML code??)
- Invoking a paint() procedure in the JApplet (simple one: just color the background black) and it works, the black JApplet is shown on the site (but it doesn't show the JPanel)
- Adding setVisible(true) in the JPanel --> nope (would be too easy -_-)
- Adding setContentPane(cards) or setContentPane(mainMenu) --> nothing..
- Adding setOpaque(true) in the JPanel --> nope..
- Reading the tutorial on Oracle about JApplet with JPanels, didn't get anything out of it...
Thanks in advance,
Resk
(PS: sorry for disturbing peace and quiet again...:s)Last edited by Reskaillev; 09-10-2011 at 12:23 AM.
- 09-07-2011, 11:31 PM #2
Re: JApplet works in eclipse but refuses to show online
Are there any error messages in the browser's java console?
- 09-07-2011, 11:55 PM #3
Member
- Join Date
- Jul 2011
- Posts
- 53
- Rep Power
- 0
- 09-07-2011, 11:56 PM #4
Re: JApplet works in eclipse but refuses to show online
Start adding some printlns so you can see where the execution flow is going.
- 09-08-2011, 12:10 AM #5
Member
- Join Date
- Jul 2011
- Posts
- 53
- Rep Power
- 0
Re: JApplet works in eclipse but refuses to show online
Not sure how to add system.out.prints when I can't see the JApplet in the browser? (and thus can't see the prints)
- 09-08-2011, 12:11 AM #6
Re: JApplet works in eclipse but refuses to show online
The printouts go to the java console.
- 09-09-2011, 11:19 PM #7
Member
- Join Date
- Jul 2011
- Posts
- 53
- Rep Power
- 0
Re: JApplet works in eclipse but refuses to show online
Okay I added the printouts to the code:
system.out.print("1/") <--at the start on the init() of JApplet
system.out.print("2/") <--at the start of the constructor of my MenuPanel() class
system.out.print("3/") <--at the end on the constructor of my MenuPanel() class
system.out.print("4/") <--at the end of the init() of JApplet
console in eclipse gives me: 1/2/3/4/
Not sure if you wanted me to test this also when the JApplet is online when I open the site? I have enabled the java console but it doesn't show the 1/2/3/4/
- 09-09-2011, 11:22 PM #8
Re: JApplet works in eclipse but refuses to show online
What do you see in the java console when you load the html page with the applet in a browser?
- 09-09-2011, 11:59 PM #9
Member
- Join Date
- Jul 2011
- Posts
- 53
- Rep Power
- 0
Re: JApplet works in eclipse but refuses to show online
Err nothing much..it's supposed to show the prints right??
none of that..this is what I get:
UPDATE: well...this is certainly strange...Java Code:Java Plug-in 1.7.0 Using JRE version 1.7.0-ea-b119 Java HotSpot(TM) Client VM User home directory = C:\Users\Pete Ravenshard ---------------------------------------------------- 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> ----------------------------------------------------
I added "this.setcontentpane(cards);" and "cards.setOpaque(true)" to the init()
Now when I try to load the webpage it gives nothing like always
BUT if I reload the page a few times there's a CHANCE that the applet loads perfectly..
really strange...
Would be best if you were able to experience it yourself??
Raw Menu Beta
- 09-10-2011, 12:02 AM #10
Re: JApplet works in eclipse but refuses to show online
I see you are using java 1.7
I have no idea why your prints are not showing on the java console.
- 09-10-2011, 12:10 AM #11
Member
- Join Date
- Jul 2011
- Posts
- 53
- Rep Power
- 0
Re: JApplet works in eclipse but refuses to show online
Yes but I build them with java 1.6 in JDK. Could there be any conflict?
Neither do I :(
What do you make of the "chance" to get the black screen? or does the black screen always show for you?
PS: updated the above JPanel and JApplet code to correspond the changes I madeLast edited by Reskaillev; 09-10-2011 at 12:21 AM.
- 09-10-2011, 12:20 AM #12
Re: JApplet works in eclipse but refuses to show online
Can you find a 1.6 plugin on another computer and test your applet there?
- 09-10-2011, 12:51 AM #13
Member
- Join Date
- Jul 2011
- Posts
- 53
- Rep Power
- 0
Re: JApplet works in eclipse but refuses to show online
not at the moment..
I tried building the applet in 1.7 and see if the problem would be fixed then...but to no avail..still the "chance" and still no prints
- 09-10-2011, 10:35 AM #14
Member
- Join Date
- Jul 2011
- Posts
- 53
- Rep Power
- 0
Re: JApplet works in eclipse but refuses to show online
Ok I found a pc with java 1.6, enabled the java console and loaded the website...
The applet works now 100%, but it still doesn't show the printlns in the console?
the biggest atm remains: why do I get the "chance" to see the applet on my java 1.7 pc?? (the printlns are strange, but don't really matter in the full run)
- 09-10-2011, 01:36 PM #15
Similar Threads
-
[ask] why doesn't eclipse show hints?
By aegean247 in forum EclipseReplies: 0Last Post: 08-29-2011, 08:51 PM -
Works in Eclipse but not in browser
By panini in forum Java AppletsReplies: 3Last Post: 12-14-2009, 03:34 AM -
JFrame to JApplet or JApplet to JApplet
By ramesh.8189 in forum AWT / SwingReplies: 13Last Post: 02-08-2009, 06:14 AM -
netbeans 6.0 not show commpunent or show blank page
By fahimaamir in forum NetBeansReplies: 1Last Post: 01-26-2008, 06:20 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks