I would like to convert my Simple Java program to an Applet Program. I’ve looked for different tutorials but all were in general most of it didn’t talk about GUI to Applet.
This is my simple program if you could instruct me to do it or comment on the changed lines I would be so much appreciated.
Here is the code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Test_Exam_091 {
public static void main(String[] args) {
new MyFrame();
}
}
class MyFrame extends JFrame implements MouseListener {
public MyFrame() {
setTitle("Playing With The Mouse!");
setSize(400, 400);
setResizable(false);
setVisible(true);
addMouseListener(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
show();
}
public void mouseEntered(MouseEvent me) {
System.out.println("Mouse entered at: ("
+ me.getX() + ", " + me.getY() + ")");
}
public void mouseExited(MouseEvent me) {
System.out.println("Mouse exited at: ("
+ me.getX() + ", " + me.getY() + ")");
}
public void mouseClicked(MouseEvent me) {
System.out.println("Mouse clicked at: ("
+ me.getX() + ", " + me.getY() + ")");
}
public void mousePressed(MouseEvent me) {
System.out.println("Mouse pressed at: ("
+ me.getX() + ", " + me.getY() + ")");
}
public void mouseReleased(MouseEvent me) {
System.out.println("Mouse released at: ("
+ me.getX() + ", " + me.getY() + ")");
}
} // End of MyFrame class
Some tips: Most of the lines of the constructor are irrelevant to applets.
In the listener methods..
Will cause problems, since that output will end up in the Java Console which is generally invisible to the end user (and most developers). It was not particularly appropriate to the
JFrameform either. It will be necessary to add aJLabelor similar to the GUI, in which to display the results.