Ajp 10 More
Ajp 10 More
Q1
import java.awt.*; }
{ }
TextArea TA; }
{ }
L.setBounds(50,55,80,35); {
TA.setBounds(10,10,15,15); k.setSize(400,450);
TA.addKeyListener(this); k.setVisible(true);
add(L); }
add(TA); }
Output :-
Q2 -
{addKeyListener(this);} break;
switch(key) }
{ repaint();
case KeyEvent.VK_F1: }
case KeyEvent.VK_F3: }
break; /*
break; */
case KeyEvent.VK_RIGHT:
Output :-
Q3– add(T1);
{ b.addActionListener(this);
TextField T1,T2,T3; }
T1=new TextField(15); }}
T3=new TextField(15); {
add(L1); }
Output :-
Practical 11
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
implements MouseMotionListener
{ addMouseMotionListener(this);}
{setBackground(Color.red);
repaint();}
setBackground(Color.green);
repaint();
/*
</applet>
*/
Output :-
Q2 –
import java.awt.*;
import java.awt.event.*;
button.addActionListener(new ActionListener() {
System.out.println("Button clicked!");
}});
frame.add(button);
frame.setSize(300, 300);
frame.setLayout(null);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
System.exit(0);
}});}}
Output :-
Q3 –
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
int x = 0, y = 0; // Coordinates
addMouseMotionListener(this);
x = me.getX();
y = me.getY();
repaint();
x = me.getX();
y = me.getY();
repaint();
g.drawString(msg, x, y);
}}
</applet>*/
Output :-
Practical 12
Q1 -
import javax.swing.*;
value.setEchoChar('#');
l1.setBounds(20,100,80,30);
value.setBounds(110,110,110,40);
F.add(value);
F.add(l1);
F.setSize(330,350);
F.setLayout(null);
F.setVisible(true);
Output :-
Q2 –
{ F.add(value);
Output :-
Q3 –
tf1.setBounds(50,50,150,20); e.getSource()==b1)
tf2=new JTextField(); {
tf2.setBounds(50,100,150,20); c=a+b;
tf3=new JTextField(); }
tf3.setEditable(false); tf3.setText(result);
b1=new JButton("+"); }
b1.addActionListener(this); {
f.add(tf3); f.add(b1); }
f.setSize(300,300); f.setLayout(null); }
Output :-
Q4-
O/P
Practical 13
import java.awt.event.*; }
{ }
Op
2
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
b.addActionListener((new ActionListener() {
System.out.println("SAURAV!!");
}));
in.add(b);
in.pack();
in.setVisible(true);
}}
Op
3
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public MouseMotionEx() {
addMouseMotionListener(new MouseMotionAdapter() {
});
setSize(400, 400);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
new MouseMotionEx();
Op
Practical 14
import java.net.InetAddress;
import java.util.Scanner;
System.out.println("Enter a hostname:");
try {
} catch (Exception e) {
}
2
import java.net.InetAddress;
try {
} catch (Exception e) {
Op
Practical 15
import java.net.URL;
try {
} catch (Exception e) {
Op
2
import java.net.URL;
import java.net.URLConnection;
import java.util.Scanner;
System.out.println("Enter a URL:");
try {
} catch (Exception e) {
}}}
Op