//creating a shopping form
//here I am creating a sample form by using the
JApplet class in the swings
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MyForm extends
JApplet implements ActionListener
{
//vars
JLabel n,a,i,lbl;
JTextField name;
JTextArea addr;
JList lst;
JButton b1,b2;
Object x[];
Container c;
String str=""
,str1="",str2="";
public void init()
{
//create frame and content
pane
JFrame jf = new JFrame();
c=jf.getContentPane();
c.setBackground(Color.yellow);
c.setLayout(null);
jf.setSize(500,400);
jf.setTitle("MyForm");
jf.setVisible(true);
//heading
lbl=new JLabel();
lbl.setForeground(Color.red);
lbl.setFont(new
Font("Dialog",Font.BOLD,36));
lbl.setText(" ONLINE
SHOPPING");
lbl.setBounds(200,10,550,40);
c.add(lbl);
//label and text fields for
name
n= new JLabel("Enter
name:",JLabel.RIGHT);
name=new JTextField(20);
n.setBounds(50,50,150,40);
name.setBounds(200,50,200,40);
c.add(n);
c.add(name);
//Label and textArea for
address
a=new JLabel("Enter
address:",JLabel.RIGHT);
addr=new JTextArea(6,20);
a.setBounds(50,100,150,40);
addr.setBounds(200,100,200,150);
c.add(addr);
c.add(a);
//a Label and ListBox for
user Selection
i=new JLabel("select
Items:",JLabel.RIGHT);
String data[]
={"T-shirts","Trousers","shorts","Jeans"};
lst=new JList(data);
i.setBounds(50,270,150,40);
lst.setBounds(200,270,200,100);
c.add(i);
c.add(lst);
//Push Buttons
b1= new
JButton("ok");
b2= new
JButton("Cancel");
b1.setBounds(200,400,150,40);
b2.setBounds(400,400,70,40);
c.add(b1);
c.add(b2);
//add ActionListener to
buttons
b1.addActionListener(this);
b2.addActionListener(this);
}
public void
actionPerformed(ActionEvent ae)
{
str=ae.getActionCommand();
if(str.equals("ok"))
{
str1+=name.getText()+"\n";
str1+=addr.getText()+"\n";
x=lst.getSelectedValues();
for(int
i=0;i<x.length;i++)
str2+=(String)x[i]+"\n";
//send the data into addr
addr.setText(str1+str2);
str1="";
str2="";
}
else
{
name.setText("");
addr.setText("");
lst.clearSelection();
}
}
}
//html file -1 it contains the above form class
<! This page contains My
form class>
<html>
<applet
code="MyForm.class" width=500 height=400>
</applet>
</html>
Another animated application
// here I am designing the animate class by using the
awt and applet conecpts
import java.awt.*;
import java.applet.*;
public class Animate extends
Applet
{
public void init()
{
}
public void paint(Graphics g)
{
Image i =
getImage(getDocumentBase(),"Gajanan.gif");
for(int x=0;x<800;x++)
{
g.drawImage(i,x,0,this);
try
{
Thread.sleep(20);
}
catch(InterruptedException
ie)
{ }
}
}
}
//html file with animate.class
<! this page contains
Animate class>
<html>
<applet
code="Animate.class" width=500 height=400>
</applet>
</html>
కామెంట్లు లేవు:
కామెంట్ను పోస్ట్ చేయండి