Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 22, 2007, 05:56 PM   #1
mcmacmcmac
macrumors member
 
Join Date: Oct 2007
Made an applet that runs - need HTML file..

Hi very new to programming here.. would really appreciate help with this

I just made an applet in eclipse on osx, when I run as Java Applet everything is perfect. But my professor is asking for the html file along with the java file, and I think i should be able to run the applet in a browser.

How can I find/create the html file and how can i get the applet to run in the browser.. thanks!
mcmacmcmac is offline   0 Reply With Quote
Old Nov 22, 2007, 06:08 PM   #2
rev316
macrumors regular
 
Join Date: Nov 2004
Just use the HTML applet tags along with the compiled .class file?
rev316 is offline   0 Reply With Quote
Old Nov 22, 2007, 06:11 PM   #3
mcmacmcmac
Thread Starter
macrumors member
 
Join Date: Oct 2007
rrrrrrright of course lol .. i don't think i stressed enough my ineptitude with this stuff. Though that sounds awfully simple i have no idea how to do it
mcmacmcmac is offline   0 Reply With Quote
Old Nov 22, 2007, 06:38 PM   #4
toddburch
macrumors 6502a
 
Join Date: Dec 2006
Location: Katy, Texas
Send a message via AIM to toddburch Send a message via MSN to toddburch
See this thread. http://forums.macrumors.com/showthread.php?t=363516

I've since taken that off my website, but here is the HTML I used for that example. You can use the commented applet tag to see how to use your local file system.

Code:
<html>
<head>
<title>HangMan</title>
</head>
<body>
<!--applet codebase="file:///Users/toddburch/Documents/myjava/" code="HangMan" width="400" height="400" -->
<applet codebase="http://www.burchwoodusa.com/cgi-bin/" code="HangMan" width="400" height="400">
</applet> 
</body>
</html>
Todd
toddburch is offline   0 Reply With Quote
Old Nov 22, 2007, 08:02 PM   #5
mcmacmcmac
Thread Starter
macrumors member
 
Join Date: Oct 2007
i created this and tried opening the file in browser to launch applet but no luck.. i feel like this is really simple i'm just completely lost

[HTML]<html>
<applet code = “GradeBookApplet.class” width = “300” height = “500”>
</applet>
</html>[/HTML]
mcmacmcmac is offline   0 Reply With Quote
Old Nov 22, 2007, 08:05 PM   #6
mcmacmcmac
Thread Starter
macrumors member
 
Join Date: Oct 2007
Here's the code if it matters at all..


Code:
import java.awt.Graphics;
import javax.swing.JApplet;
import javax.swing.JOptionPane;

public class GradeBookApplet extends JApplet
	{
	
		// initialization phase
		private int total = 0;
		private int gradeCounter = 0;
		private double classAverage;
		private int gradeFrequency [] = new int [11];
		
		public void init()
			{
				String gradeString = JOptionPane.showInputDialog("Enter a grade or -1 to quit");
				
				// convert grade to integer
				int grade = Integer.parseInt(gradeString);
				
				// loop until sentinel value read from user
				while ( grade != -1)
				{
					total += grade;
					++gradeCounter;
					
					if (grade < 10)
						++gradeFrequency[0];
					else if (grade < 20)
						++gradeFrequency[1];
					else if (grade < 30)
						++gradeFrequency[2];
					else if (grade < 40)
						++gradeFrequency[3];
					else if (grade < 50)
						++gradeFrequency[4];
					else if (grade < 60)
						++gradeFrequency[5];
					else if (grade < 70)
						++gradeFrequency[6];
					else if (grade < 80)
						++gradeFrequency[7];
					else if (grade < 90)
						++gradeFrequency[8];
					else if (grade < 100)
						++gradeFrequency[9];
					else if (grade == 100)
						++gradeFrequency[10];
					
					gradeString = JOptionPane.showInputDialog("Enter a grade or -1 to quit");
					
					// convert grade to integer
					grade = Integer.parseInt(gradeString);
				
				}
				
				
			}
				
				
		public void paint (Graphics g)
			{
				// call superclass version of method paint
				super.paint(g);
				
				// draw a string
				g.drawString("GRADES DISTRIBUTION FOR THE CLASS:",25,25);
				
				
				// for each array element output bar for chart
				for (int counter = 0; counter < gradeFrequency.length; counter++)
					{
						int a = counter * 10;
						int b = counter * 10 +9;
						int y;
						
						if (counter == 0)
							y = 50;
						else
							y = 50 + (counter *25);
						
						
						// output bar label
						if (counter==10)
							g.drawString("100:",50,y);
						else
							g.drawString(a + " - " + b + ": ",25,y);
						
						if (gradeFrequency[counter] != 0)
							{
								int x = 80;
								
								for(int stars = 0; stars < gradeFrequency[counter];stars++)
									{
										g.drawString("*", x, y);
										x = x+5;
									}
									
								
							}
						
						
					}
				
				if (gradeCounter != 0)
					{
						//calculate average of all grades entered
						classAverage = total/gradeCounter;
						
						
						g.drawString("Total: " + total,25,350);
						g.drawString("Number of grades: " + gradeCounter, 25, 375);
						g.drawString("Average: " + classAverage, 25, 400);
					}
			}
			
	}
mcmacmcmac is offline   0 Reply With Quote
Old Nov 23, 2007, 12:06 AM   #7
Aranince
macrumors 65816
 
Join Date: Apr 2007
Location: California
Quote:
Originally Posted by mcmacmcmac View Post
i created this and tried opening the file in browser to launch applet but no luck.. i feel like this is really simple i'm just completely lost

[HTML]<html>
<applet code = “GradeBookApplet.class” width = “300” height = “500”>
</applet>
</html>[/HTML]
You need to have body tags

Code:
<html>

<head>
   <title>This is my Java app</title
</head>

<body>

<applet code = “GradeBookApplet.class” width = “300” height = “500”>
</applet>

</body>
</html>
__________________
Don't tread on me.
Aranince is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
General: I have made a cydia repo. error the index file is courrupt no filename jobisho Jailbreaks and iOS Hacks 4 Jan 29, 2014 10:40 AM
how to view html file from the terminal hajime Mac Basics and Help 1 Nov 4, 2013 10:57 AM
Mountain Lion runs very clunky but Windows 7 runs quick filmfanatic24 OS X 2 Jan 29, 2013 02:39 PM
Mid 2011 MBP runs hot, and fan runs loud as f since updating to ML daynel MacBook Pro 2 Aug 20, 2012 12:37 AM
Need to convert to html or be able to open .adr file... nobodyhome Mac OS X 10.7 Lion 0 Aug 19, 2012 05:15 PM

Forum Jump

All times are GMT -5. The time now is 09:03 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC