Skip to content

Commit e145051

Browse files
authored
Merge pull request #55 from JayNakum/main
Adding programs of JavaApplets
2 parents 3183266 + 2b5d76d commit e145051

31 files changed

+1015
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import java.awt.*;
2+
import java.awt.event.*;
3+
4+
public class ActionListenerDemo extends Frame implements ActionListener {
5+
Button b;
6+
Label l;
7+
ActionListenerDemo() {
8+
b = new Button("Buttom");
9+
l = new Label("Click it!");
10+
Image icon = Toolkit.getDefaultToolkit().getImage("../icon.png");
11+
setIconImage(icon);
12+
setTitle("ActionDemo.java");
13+
setSize(420, 420);
14+
setLayout(new FlowLayout(FlowLayout.CENTER));
15+
b.addActionListener(this);
16+
add(b);
17+
add(l);
18+
setVisible(true);
19+
}
20+
public void actionPerformed(ActionEvent ae) {
21+
l.setText("Clicked " + ae.getActionCommand());
22+
}
23+
public static void main(String[] args) {
24+
new ActionListenerDemo();
25+
}
26+
}

AWT/Behaviour/AdapterTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import java.awt.*;
2+
import java.awt.event.*;
3+
4+
public class AdapterTest extends MouseAdapter {
5+
AdapterTest() {
6+
Frame frame = new Frame();
7+
Image icon = Toolkit.getDefaultToolkit().getImage("../icon.png");
8+
frame.setIconImage(icon);
9+
frame.setTitle("AdapterTest.java");
10+
frame.setSize(420, 420);
11+
frame.addMouseListener(this);
12+
frame.setVisible(true);
13+
}
14+
15+
public void mouseClicked(MouseEvent me) {
16+
System.out.println("Mouse Clicked");
17+
}
18+
19+
public static void main(String[] args) {
20+
new AdapterTest();
21+
}
22+
}

AWT/Behaviour/KeyListenerDemo.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import java.awt.*;
2+
import java.awt.event.*;
3+
4+
public class KeyListenerDemo extends Frame implements KeyListener {
5+
TextField textField;
6+
7+
KeyListenerDemo() {
8+
Image icon = Toolkit.getDefaultToolkit().getImage("../icon.png");
9+
setIconImage(icon);
10+
setTitle("KeyListenerDemo.java");
11+
setSize(420, 420);
12+
setLayout(new FlowLayout(FlowLayout.LEFT));
13+
textField = new TextField(25);
14+
textField.addKeyListener(this);
15+
add(textField);
16+
setVisible(true);
17+
}
18+
19+
public void keyPressed(KeyEvent ke) {
20+
System.out.println("KeyPressed = " + ke.getKeyChar());
21+
}
22+
23+
public void keyReleased(KeyEvent ke) {
24+
System.out.println("KeyReleased = " + ke.getKeyChar());
25+
}
26+
27+
public void keyTyped(KeyEvent ke) {
28+
System.out.println("KeyTyped = " + ke.getKeyChar());
29+
}
30+
31+
public static void main(String[] args) {
32+
new KeyListenerDemo();
33+
}
34+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import java.awt.*;
2+
import java.awt.event.*;
3+
4+
public class MouseListenerDemo extends Frame implements MouseListener {
5+
MouseListenerDemo() {
6+
Image icon = Toolkit.getDefaultToolkit().getImage("../icon.png");
7+
setIconImage(icon);
8+
setTitle("MouseListenerDemo.java");
9+
setSize(420, 420);
10+
addMouseListener(this);
11+
setVisible(true);
12+
}
13+
14+
public void mouseEntered(MouseEvent me) {
15+
System.out.println("Mouse Entered");
16+
}
17+
public void mousePressed(MouseEvent me) {
18+
System.out.println("Mouse Pressed");
19+
}
20+
public void mouseReleased(MouseEvent me) {
21+
System.out.println("Mouse Released");
22+
}
23+
public void mouseClicked(MouseEvent me) {
24+
System.out.println("Mouse Clicked");
25+
}
26+
public void mouseExited(MouseEvent me) {
27+
System.out.println("Mouse Exited");
28+
}
29+
30+
public static void main(String[] args) {
31+
new MouseListenerDemo();
32+
}
33+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import java.awt.*;
2+
import java.awt.event.*;
3+
4+
public class MouseMotionListenerDemo extends Frame implements MouseMotionListener {
5+
Label label;
6+
int x, y;
7+
8+
MouseMotionListenerDemo() {
9+
Image icon = Toolkit.getDefaultToolkit().getImage("../icon.png");
10+
setIconImage(icon);
11+
setTitle("MouseMotionListenerDemo.java");
12+
setSize(420, 420);
13+
setLayout(new FlowLayout());
14+
label = new Label("(Coordinates)");
15+
add(label);
16+
addMouseMotionListener(this);
17+
setVisible(true);
18+
}
19+
20+
public void mouseMoved(MouseEvent me) {
21+
x = me.getX();
22+
y = me.getY();
23+
label.setText("(" + x + ", " + y + ")");
24+
}
25+
public void mouseDragged(MouseEvent me) {} // Compulsory to override
26+
27+
public static void main(String[] args) {
28+
new MouseMotionListenerDemo();
29+
}
30+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import java.awt.*;
2+
import java.awt.event.*;
3+
4+
public class WindowListenerDemo extends Frame implements WindowListener {
5+
WindowListenerDemo() {
6+
Image icon = Toolkit.getDefaultToolkit().getImage("../icon.png");
7+
setIconImage(icon);
8+
setTitle("WindowListenerDemo.java");
9+
setSize(420, 420);
10+
addWindowListener(this);
11+
setVisible(true);
12+
}
13+
14+
public void windowOpened(WindowEvent we) {
15+
System.out.println("Window Opened");
16+
}
17+
public void windowClosing(WindowEvent we) {
18+
System.out.println("Window Closing");
19+
System.exit(0);
20+
}
21+
public void windowClosed(WindowEvent we) {
22+
System.out.println("Window Closed");
23+
}
24+
public void windowIconified(WindowEvent we) {
25+
System.out.println("Window Iconified");
26+
}
27+
public void windowDeiconified(WindowEvent we) {
28+
System.out.println("Window Deiconified");
29+
}
30+
public void windowActivated(WindowEvent we) {
31+
System.out.println("Window Activated");
32+
}
33+
public void windowDeactivated(WindowEvent we) {
34+
System.out.println("Window Deactivated");
35+
}
36+
37+
public static void main(String[] args) {
38+
new WindowListenerDemo();
39+
}
40+
}

AWT/FirstCanvas.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import java.awt.*;
2+
3+
public class FirstCanvas {
4+
Frame f1;
5+
Label l1;
6+
Panel p1;
7+
8+
FirstCanvas() {
9+
f1 = new Frame("FirstCanvas.java");
10+
f1.setSize(420, 420);
11+
f1.setLayout(new GridLayout(3, 1));
12+
l1 = new Label();
13+
p1 = new Panel();
14+
f1.add(l1);
15+
f1.add(p1);
16+
17+
l1.setText("Canvas");
18+
Canvas c = new Canvas();
19+
c.setSize(69, 69);
20+
c.setBackground(Color.GRAY);
21+
// f1.add(c);
22+
p1.add(c);
23+
24+
f1.setVisible(true);
25+
}
26+
27+
public static void main(String[] args) {
28+
FirstCanvas canvas = new FirstCanvas();
29+
}
30+
}

AWT/FirstFrame.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import java.awt.*;
2+
3+
public class FirstFrame {
4+
public static void main(String[] args) {
5+
Frame f = new Frame("FirstFrame.java");
6+
f.setSize(420, 69);
7+
f.setVisible(true);
8+
}
9+
}

AWT/FrameFromApplet.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// <applet
2+
// code = "FrameFromApplet.class"
3+
// width = "420"
4+
// height = "69"
5+
// alt = "Applet Here"
6+
// name = "FrameFromApplet"
7+
// align = "center"
8+
// >
9+
// </applet>
10+
11+
import java.applet.Applet;
12+
import java.awt.*;
13+
14+
class MyFrame extends Frame {
15+
MyFrame(String title) {
16+
// super(title); // Only needed if want to set properties like this (title in this case)
17+
setTitle(title);
18+
19+
// Label l = new Label("Frame");
20+
// l.setAlignment(Label.CENTER);
21+
// add(l);
22+
23+
// setVisible(true); // NOT NEEDED
24+
}
25+
public void paint(Graphics g) {
26+
g.drawString("Frame", 69, 69);
27+
}
28+
}
29+
30+
public class FrameFromApplet extends Applet{
31+
Frame f;
32+
public void init() {
33+
f = new MyFrame("FrameFromApplet.java");
34+
f.setSize(420, 420);
35+
// f.setVisible(true); // NOT NEEDED
36+
}
37+
public void start() {
38+
f.setVisible(true);
39+
}
40+
public void stop() {
41+
f.setVisible(false);
42+
}
43+
public void paint(Graphics g) {
44+
g.drawString("from Applet", 9, 20);
45+
}
46+
}

AWT/FrameTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import java.awt.*;
2+
3+
public class FrameTest extends Frame{
4+
FrameTest(String title) {
5+
super(); // Calling the super class constructor (Frame)
6+
this.setTitle(title);
7+
this.setSize(420, 420);
8+
this.setVisible(true);
9+
}
10+
public static void main(String[] args) {
11+
FrameTest f = new FrameTest("FrameTest.java");
12+
}
13+
}

0 commit comments

Comments
 (0)