Results 1 to 3 of 3
Thread: Help with creating an applet
- 02-23-2009, 04:50 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 9
- Rep Power
- 0
Help with creating an applet
I have no idea what I am doing wrong. All my applet is display the Welcome to java programming string I have in my paint method. Right now I just want to get a label put on a JFrame. Can anyone help please?
Java Code:import java.awt.*; import java.applet.*; import javax.swing.JFrame; import javax.swing.JApplet; import javax.swing.JLabel; import java.awt.BorderLayout; public class SampleApplet extends JApplet { public void init() { } public static void main(String[] args) { //... Create an initialize the applet. JApplet theApplet = new SampleApplet(); theApplet.init(); // Needed if overridden in applet //theApplet.start(); // Needed if overridden in applet //... Create a window (JFrame) and make applet the content pane. JFrame window = new JFrame("Sample Applet and Application"); window.setContentPane(theApplet); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.pack(); // Arrange the components. //System.out.println(theApplet.getSize()); window.setVisible(true); // Make the window visible. JLabel label1 = new JLabel("Test Label"); label1.setBackground(Color.CYAN); label1.setOpaque(true); window.add(label1, BorderLayout.SOUTH); } public SampleApplet() { add(new JLabel("This is both an Applet and Application!")); } public void paint(Graphics g) { g.drawString("Welcome to Java!!", 50, 60 ); } }
-
You're trying to create an applet with incorrect assumptions, that's the problem. There are too many problems here to correct, and so I think you should just throw this code out and start afresh. Have a look at the Sun tutorial about applets and you'll see that many of your assumptions are incorrect (for instance trying to instantiate an applet object in the init method, trying to mix jframes with applets, trying to paint directly within the applet,....). It will give you sample code too.I have no idea what I am doing wrong.
Good luck.
-
Heck, I already told you all this in your previous post, one that you never acknowledged, and based on your post here, one you never read. So why post here if you are just going to ignore all advice? Why should we help you in the future if we're just wasting our energies?
Similar Threads
-
Calling another applet on click of button in one applet
By niteshwar.bhardwaj in forum Java 2DReplies: 1Last Post: 02-19-2009, 12:54 PM -
Creating .Jar files
By Deathmonger in forum New To JavaReplies: 6Last Post: 06-22-2008, 11:59 PM -
Looking for team members for creating the applet game.
By M77 in forum Reviews / AdvertisingReplies: 10Last Post: 05-28-2008, 08:25 AM -
Creating Calendar in Applet
By wco5002 in forum New To JavaReplies: 2Last Post: 04-09-2008, 04:21 AM -
Applet, To center text and To open I engage in a dialog in an Applet
By Marcus in forum Java AppletsReplies: 4Last Post: 06-08-2007, 06:15 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks