0% found this document useful (0 votes)
20 views

1.create A Simple Applet. Import Java - Awt. Import Java - Applet.

This document contains 5 sections that provide examples of creating different types of Java applets and frames. Section 1 creates a simple applet that draws text to the screen. Section 2 creates an applet that changes the background color when the mouse is pressed or released using an adapter class. Section 3 creates a simple Swing applet. Section 4 indicates a simple Swing frame will be created but does not provide any code. Section 5 creates a Swing applet with a text field, password field, and two buttons in a grid layout.

Uploaded by

nirav68127245
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

1.create A Simple Applet. Import Java - Awt. Import Java - Applet.

This document contains 5 sections that provide examples of creating different types of Java applets and frames. Section 1 creates a simple applet that draws text to the screen. Section 2 creates an applet that changes the background color when the mouse is pressed or released using an adapter class. Section 3 creates a simple Swing applet. Section 4 indicates a simple Swing frame will be created but does not provide any code. Section 5 creates a Swing applet with a text field, password field, and two buttons in a grid layout.

Uploaded by

nirav68127245
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

1.Create a simple Applet. import java.awt.*; import java.applet.

*;

/* <applet code="simple.java" width=200 height=200> </applet> */

public class simple extends Applet {

public void paint(Graphics g) { g.drawString("Hello World !!!!.",50,100); } }

2.Write a applet that uses Adaptarclass to implement MouseEvent. import java.applet.*; import java.awt.*; import java.awt.event.*; /* <applet code=tuto12 width="200" height="200"> </applet> */ public class tuto12 extends Applet { public void init()

{ setBackground(Color.blue);

addMouseListener(new MouseAdapter() {

public void mousePressed(MouseEvent me) {

setBackground(Color.pink);

repaint();

public void mouseReleased(MouseEvent me) { setBackground(Color.gray); repaint(); }

});

} }

3.Create a simple Swing Applet. import javax.swing.*; import java.applet.*; import java.awt.*;

/*

<applet code="t1p3" height=200 width=200> </applet>

*/ public class t1p3 extends JApplet { public void init() { Container c = this.getContentPane(); JLabel l=new JLabel("Hello World"); c.add(l); } }

4.Create a simple Swing Frame.

5.Create a Swing Applet that contains textfield,paswwordfield and command button. import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.applet.*;

/* <applet code="pro5" height=300 width=300> </applet> */

public class pro5 extends JApplet {

Container c; JLabel l1; JLabel l2; JPasswordField p; JTextField tf; JButton b1; JButton b2;

public void init() { c=this.getContentPane(); setLayout(new GridLayout());

l1= new JLabel("User name"); c.add(l1);

tf= new JTextField(" "); c.add(tf);

l2= new JLabel("Password"); c.add(l2);

p= new JPasswordField(); c.add(p);

c.add(tf); b1=new JButton("OK");

c.add(b1); b2= new JButton("CANCLE"); c.add(b2);

You might also like