Ajp Practical Answers
Ajp Practical Answers
Ajp Practical Answers
*;
class Demo {
public static void main(String args[]) {
Frame f = new Frame();
f.setLayout(new FlowLayout());
f.setVisible(true);
f.setSize(400, 400);
Label l1 = new Label("UserName");
Label l2 = new Label("Password");
TextField t1 = new TextField(20);
TextField t2 = new TextField(20);
t2.setEchoChar('*');
TextArea ta = new TextArea(10, 30);
Button b1 = new Button("Submit");
f.add(l1);
f.add(t1);
f.add(l2);
f.add(t2);
f.add(ta);
f.add(b1);
}
}
2)
import java.awt.*;
import java.applet.*;
/* <applet code="ListDemo" width=500 height=600 >
</applet> */
add(l1);
}
}
3)
import java.awt.*;
import java.applet.*;
/* <applet code="GridlLayoutDemo3" width=500 height=600 >
</applet> */
setLayout(gl);
for(int i=1;i<=9;i++)
{
add(new Button(""+i));
b1 =new Button("*");
b2 =new Button("0");
b3 = new Button("#");
add(b1);
add(b2);
add(b3);
}
}
4)
5)
import java.awt.*;
import java.applet.*;
mbr.add(edit);
mbr.add(view);
}
}
6)
import java.awt.*;
import javax.swing.*;
public class JCheckBoxDemo extends JFrame
{
JCheckBox cb1,cb2,cb3,cb4,cb5,cb6;
public JCheckBoxDemo()
{
Container c= getContentPane();
c.setLayout(null);
c.add(cb1);
c.add(cb2);
c.add(cb3);
c.add(cb4);
c.add(cb5);
c.add(cb6);
cb1.setBounds(30,50,100,30);
cb2.setBounds(150,50,100,30);
cb3.setBounds(30,100,100,30);
cb4.setBounds(150,100,100,30);
}
public static void main(String a[])
{
JCheckBoxDemo cbd = new JCheckBoxDemo();
cbd.setSize(800,700);
cbd.setVisible(true);
cbd.setTitle("Demonstrate the use of JCheckBox");
}
}
7)
import java.awt.*;
import javax.swing.*;
/*<applet code="treeDemo" width=300 height=300></applet> */
import javax.swing.tree.DefaultMutableTreeNode;
JTree t;
DefaultMutableTreeNode i = new DefaultMutableTreeNode("India");
i.add(a);
i.add(b);
a.add(a1);
a.add(a2);
a.add(a3);
a.add(a4);
t = new JTree(i);
c.add(t);
}
}
8)
import java.awt.*;
import javax.swing.*;
/*<applet code="JTableDemo1" width=300 height=300></applet> */
import javax.swing.tree.DefaultMutableTreeNode;
c.setLayout(new BorderLayout());
"101","Amit","670000"
},
{
"102","Jai","780000"
},
{
"103","Sachin","70000"
}
};
9)
import javax.swing.*;
public class ProgressBarExample extends JFrame{
JProgressBar jb;
int i=0,num=0;
ProgressBarExample(){
jb=new JProgressBar(0,2000);
jb.setBounds(40,40,160,30);
jb.setValue(0);
jb.setStringPainted(true);
add(jb);
setSize(250,150);
setLayout(null);
}
public void iterate(){
while(i<=2000){
jb.setValue(i);
i=i+20;
try{Thread.sleep(150);}catch(Exception e){}
}
}
public static void main(String[] args) {
ProgressBarExample m=new ProgressBarExample();
m.setVisible(true);
m.iterate();
}
}
10)
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*
<applet code="KeyEventDemo" height="400" width="400">
</applet>
*/
public class KeyEventDemo extends Applet implements KeyListener
{
String msg = "";
14)
import java.net.*;
class InetAddressDemo
{
public static void main(String args[]) throws UnknownHostException
{
InetAddress ia = InetAddress.getByName("localhost");
System.out.println("loaclhost: "+ia.getLocalHost());
}
}
15)
import java.net.*;
class InetAddressDemo
{
public static void main(String args[]) throws UnknownHostException
{
InetAddress ia = InetAddress.getByName("localhost");
System.out.println("loaclhost: "+ia.getLocalHost());
}
}