Hello, I am a high school math teacher and my students and I am having difficulties getting my first java applet to work for my students using j# 2003. I have successfully written applets in miscrosoft visual j++ and want to run some of the same applets with j#.
Here is my problem.
I would like to run the same applet found at http://www.mrpowell.net/progra/java/example1.htm
But can not get the applet to run. I have tried various approaches, so I quess I would like answers to the following questions.
1. When creating a new project, which type do I select:
Visual # projects, Setup and deployment projects, other projects, or Visual studio solutions
2.When creating a new project which do I need to select from the templates section
If so, which one to I pick Empty web project, Empty project, ASP.net Web application, or another
- When creating a new text file to create my java applet code, where do I save it
In the same folder as my project or does it not matter
I would appreciate it if anyone has the time to write and help me and my students out.
Sam Powell
Powells@mcsin-k12.org
Blow is the applet code I am trying to run.
import java.applet.*; //imports Applet package
import java.awt.*; //imports the abstract window Tool Kit (AWT) class.
public class Example1 extends Applet
{
TextField StrNum1=new TextField(10);
TextField StrNum2=new TextField(10);
TextField StrNum3=new TextField(10);
TextField StrNum4=new TextField(10);
Button FindSum=new Button ("Find Sums");
Label Prompt1=new Label ("Enter an Integer :");
Label Prompt2=new Label ("Enter another Integer :");
Label Prompt3=new Label ("Enter a float :");
Label Prompt4=new Label ("Enter another float :");
TextArea Result=new TextArea(5,30);
public void init()
{
add(Prompt1);
add(StrNum1);
add(Prompt2);
add(StrNum2);
add(Prompt3);
add(StrNum3);
add(Prompt4);
add(StrNum4);
add(FindSum);
add(Result);
}
public boolean action(Event thisEvent, Object thisObject)
{
/*The next line will get the input from the
textfield and convert it to an integer*/
int num1=Integer.parseInt(StrNum1.getText());
int num2=Integer.parseInt(StrNum2.getText());//entering the second integer
/*The next line will get the input from the
textfield and convert it to a float*/
float num3=Float.valueOf(StrNum3.getText()).floatValue();
float num4=Float.valueOf(StrNum4.getText()).floatValue();
int sumi= num1 + num2; // adding the integers
float sumf = num3 + num4; // adding the floats
Result.appendText("The sum of your integers : "+num1+" and "+num2+"\n is "+sumi+"\n\n");
Result.appendText("The sum of your floats : "+num3+" and "+num4+"\n is "+sumf+"");
return true;
}
}

High School Teacher needs help
JackyLi
Thanks Christian, for sepending time and answering these queries. Please read my comments for more...
This is true that J# in VS 2003 didn't have integrated support for Applets. What we did have was “J# Browser Controls” (Equivalent to Applets in J#) that users can install on top for J# Redist v1.1. Please install it from here (if you haven't done so) as I guess you are working on VS 2003.
If you want to create a new Applet using J# then you need to write a class library. You can create it as follows...
1. Go to File > New > Project
2. Click on Visual J# projects in Project Types treeview.
3. Select Class Library from Templates.
4. Click ok.
5. Write appropriate import statements (eg. import java.applet.*; )and start working on it.
You should write a .jsl/java file instead of a .txt file because J# considers .jsl/.java only as code files. When you create a new J# class library, there will be a default class1.jsl. If you want to add more .jsl files then please follow below steps...
1. Right click on project name in Solution explorer.
2. Select Add > Add new item.
3. Select Class template from template list.
I have just complied the code you have posted. What all I did was ...
1. I installed "J# Browser Controls" from here.
2. Created a new J# class library (as i have mentioned above).
3. Replaced the code of default of .jsl file with your code and just complied. It went perfectly :).
To know more about JBC, you may like to refer this white paper. This whitepaper is a good starting point for JBC.
If you face any other issues in using J#, then please please post them here. J# is as good as any other .net language and we (J# team) are always there to help you out.
Thanks.
< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
ormistons
Thanks for the help.
Sam Powell
Northridge High School
Middlebury, IN
Mario Spanicciati
Hi, Sam. I've been doing some research and as far as I can tell, VS2005 is the first to offer applet support for J#. Note, I don't do J# at all, I've been using google to see if I could help here. In other words, I'm no expert on J#, just reporting what I have found.
You'd choose a J# project
ASP.NET is a whole different thing. If you don't need to host in a browser, you could choose a windows app. If you choose ASP.NET, you'll be creating a site that needs hosting. You could solve the problem that way, but it would take the form of individually written pages, with HTML in the front and code at the back to process the result. It would therefore make a round trip to the server every time anyone hit the 'calculate' button.
You'd typically right click and choose Add/New and it would create the file in the right folder and add it to your project.
Sorry I cannot help more. I'd definately suggest using C# instead unless you're specifically looking to teach Java, in which case I'd look into using Eclipse or something. J# is supported, but it's not very widely used. C# is similar enough in syntax that moving to it should not pose any great issues.
Having said that, I just found this:
http://blog.cmaeda.com/ p=32
It references this page:
http://windowsforms.net/articles/iesourcing.aspx
If you can reference a windows forms app in IE, then I don't see any reason why that app could not be written in J#. That would mean you'd create a windows forms app, make it work as a forms app ( outside the browser ) and follow these instructions to make it work within the browser.