Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mcmacmcmac

macrumors member
Original poster
Oct 2, 2007
86
0
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

macrumors member
Original poster
Oct 2, 2007
86
0
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
 

toddburch

macrumors 6502a
Dec 4, 2006
748
0
Katy, Texas
See this thread. https://forums.macrumors.com/threads/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
 

mcmacmcmac

macrumors member
Original poster
Oct 2, 2007
86
0
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>
 

mcmacmcmac

macrumors member
Original poster
Oct 2, 2007
86
0
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);
					}
			}
			
	}
 

Aranince

macrumors 65816
Apr 18, 2007
1,104
0
California
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>

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>
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.