Results 1 to 5 of 5
Thread: Java Applet Not Running
- 10-06-2009, 05:31 AM #1
Member
- Join Date
- Sep 2009
- Posts
- 12
- Rep Power
- 0
Java Applet Not Running
For some reason, my code won't compile. I don't understand why it won't. I'm new to Java & even newer to JApplets.
Java Code://AppletDrawingMain.java import javax.swing.JPanel; import javax.swing.JFrame; import java.awt.Font; import java.awt.Color; import java.awt.Graphics; import javax.swing.JApplet; public class AppletDrawingMain extends JApplet { public static void main(String[] args) { //create frame JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //declaring & adding dBoard to frame DrawingBoard dBoard = new DrawingBoard(); frame.add(dBoard); //frame paramaters frame.setSize(800, 800); frame.setVisible(true); } }
Java Code://DrawingBoard.java import java.awt.Font; import java.awt.Color; import java.awt.Graphics; import javax.swing.JPanel; import javax.swing.JApplet; //package drawinginapplet; public class DrawingBoard extends JApplet { public void paintComponent(Graphics g) { //call to superclass super.paintComponent(g); //upper left "Hello World" declaration g.setFont( new Font("Comic Sans", Font.PLAIN, 12) ); g.drawString("Hello World", 0, 0); //lower right "I am here!" declaration g.setFont(new Font("Impact", Font.PLAIN, 10) ); g.drawString("I am here!", 775, 800); //square with a black border and red fill g.setColor(Color.red); g.drawRect(15, 15, 50, 50); g.fillRect(15, 15, 50, 50); //rectangle with a blue border and no fill g.setColor(Color.white); g.drawRect(50, 50, 60, 130); g.fillRect(50, 50, 60, 130); //circle with a grey border and blue fill g.setColor(Color.blue); g.drawOval(80, 130, 30, 30); g.fillOval(80, 130, 30, 30); //oval with a pink border and no fill g.setColor(Color.PINK); g.drawOval(130, 150, 75, 25); //arch with a green border and yellow fill g.setColor(Color.yellow); g.fillArc(220, 220, 75, 75, 0, 180); g.drawArc(220, 220, 75, 75, 0, 180); } }
- 10-06-2009, 09:14 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Learn to read the error messages that the compiler gives you. They tell you the reason why the code doesn't compile. What error messages did you get?
- 10-07-2009, 03:24 AM #3
Member
- Join Date
- Sep 2009
- Posts
- 12
- Rep Power
- 0
Ahhh!
When I had the following code,
and attempted to debug it, it told me that there was no main class. I added this:Java Code://DrawingBoard.java import java.applet.*; import java.awt.Font; import java.awt.Color; import java.awt.Graphics; //import java.awt.Graphics2D; //import javax.swing.JPanel; //import javax.swing.JApplet; public class DrawingBoard extends Applet { public void init() { setSize(500,550); setVisible(true); } public void paint(Graphics g) { //call to superclass //super.paintComponent(g); //upper left "Hello World" declaration g.setFont( new Font("Comic Sans", Font.PLAIN, 12) ); g.drawString("Hello World", 0, 0); //lower right "I am here!" declaration g.setFont(new Font("Impact", Font.PLAIN, 10) ); g.drawString("I am here!", 775, 800); //square with a black border and red fill g.setColor(Color.black); g.drawRect(15, 15, 50, 50); g.setColor(Color.red); g.fillRect(16, 16, 49, 49); //rectangle with a blue border and no fill g.setColor(Color.blue); g.drawRect(50, 50, 60, 130); //circle with a gray border and blue fill g.setColor(Color.gray); g.drawOval(80, 130, 30, 30); g.setColor(Color.blue); g.fillOval(81, 131, 29, 29); //oval with a pink border and no fill g.setColor(Color.PINK); g.drawOval(130, 150, 75, 25); //arch with a green border and yellow fill g.setColor(Color.green); g.fillArc(220, 220, 75, 75, 0, 180); g.setColor(Color.yellow); g.drawArc(219, 219, 75, 75, 0, 180); } }
I honestly didn't think that this was right, but was just trying out different things to get this applet running. It said that the build was successful, but it never displayed the applet. I am completely confused at this point.Java Code:public static void main(String[] args) { }
- 10-07-2009, 08:20 AM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
You are running the Applet as a normal Java application. Read the Applets tutorial from Sun to find out how to run Applets.
- 10-08-2009, 12:11 AM #5
Member
- Join Date
- Sep 2009
- Posts
- 12
- Rep Power
- 0
Similar Threads
-
Problem in running Java swing wizard in jre 1.6 while it is running in jre 1.4
By Sanjay Dwivedi in forum AWT / SwingReplies: 0Last Post: 08-26-2009, 01:03 PM -
[SOLVED] [newbie] running an applet ??
By jon80 in forum New To JavaReplies: 4Last Post: 05-31-2009, 09:42 PM -
Running applet from command prompt
By niteshwar.bhardwaj in forum Java 2DReplies: 1Last Post: 03-12-2009, 08:10 AM -
First Applet not running on browsers
By Centinela66 in forum Java AppletsReplies: 11Last Post: 10-09-2008, 01:58 PM -
Getting url of page applet is running on
By damounh in forum Java AppletsReplies: 1Last Post: 05-09-2008, 05:49 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks