I created and applet which works fine on Windows, but users on a MAC get a red X.
Is there anything special that I have to do to my source code or HTML code to get MAC users to use my applet ?
I created and applet which works fine on Windows, but users on a MAC get a red X.
Is there anything special that I have to do to my source code or HTML code to get MAC users to use my applet ?
need more information as to why applet is crashing with red X.
Can you post the output of the Java Console? It should contain an exception that explains why its failing.
This is what MAC Users get with my Applet, but they’re able to run other applets.
Also He doesn’t get an exception.
The exception will be in the Java Console which must be enabled to see it.
I tested the console on Windows and I was able to see the trace of any exceptions I created. On a mac the console doesn’t provide any feedback.
This is the source code for the Applet. It adds 2 numbers and displays the progress on the console.
import java.awt.Graphics; // program uses class Graphics
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JApplet; // program uses class JApplet
import javax.swing.JButton;
import javax.swing.JOptionPane;
public class AdditionApplet extends JApplet{
public JButton RunButton;
private double sum; // sum of values entered by user
public void init(){
// Run Program Button
RunButton = new JButton("Run");
// Add Run Button Action Listener
RunButton.addActionListener(new RunButtonListener());
// Add the Run Button to the JApplet
add(RunButton);
}
public void start(){
}
public void paint( Graphics g ){
// call superclass version of method paint
super.paint( g );
}
public void doWork(){
// Get raphic Object
Graphics g = getGraphics();
// Update the Frame (Redraw)
update(g);
// Method Call
myPaint(g);
}
public void myPaint(Graphics g){
String firstNumber; // first string entered by user
String secondNumber; // second string entered by user
double number1; // first number to add
double number2; // second number to add
// obtain first number from user
firstNumber = JOptionPane
.showInputDialog("Enter first floating-point value");
System.out.println("First Number Entered = " + firstNumber);
// obtain second number from user
secondNumber = JOptionPane
.showInputDialog("Enter second floating-point value");
System.out.println("Second Number Entered = " + secondNumber);
// convert numbers from type String to type double
number1 = Double.parseDouble(firstNumber);
number2 = Double.parseDouble(secondNumber);
sum = number1 + number2; // add numbers
// draw rectangle starting from (15, 10) that is 270
// pixels wide and 20 pixels tall
g.drawRect(15, 10, 270, 20);
// draw results as a String at (25, 25)
g.drawString("The sum is " + sum, 25, 25);
System.out.println("The result is = " + sum);
}
// Inner class which will dictate RunButton Actions
class RunButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
remove(RunButton); // Remove the Button when Pressed
doWork(); // Do Some Work
}
}
}// end Applet Class
This is the HTML Page that I’m using to call the Applet.
<html>
<applet codebase = "bin/"
code = "AdditionApplet.class"
Width = 700
Height = 300>
</applet>
</html>
Actually, run:
/Applications/Utilities/Console
Which is the system-wide console. It will have the stack traces, etc. The Java console in the browser is always blank (very irritating, especially because when you click the Details button it always takes you there).
try
<html>
<body>
<applet codebase="./bin" code="AdditionApplet.class" width=700 height=300>
</applet>
</body>
</html>
Nothing works. I was reading on it online and apparently It’ll work if I compile my source code on a MAC Computer. I don’t have a MAC so I’ll look around some more and let you guys know If I find anything.
That makes no sense whatsoever. Don’t waste time on that.
Applets ‘just work’ on a Mac.
Create an applet that fills a red rectangle, work from there.
It has been a while since I had access to a mac so this might not be true anymore but I had to compile for java 1.5. Also mac is case sensitive where as windows is not so maybe a file name isn’t is the proper case.
This.
Don’t waste time trying crazy workarounds. If it’s not working then you did something wrong (like using the wrong file separators or something), and you’re just going to need to start with something simple and work up from there.