0% found this document useful (0 votes)
5 views5 pages

dddd

Uploaded by

divya darshini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

dddd

Uploaded by

divya darshini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

1.

class welcome
{
public static void main(string args[])
{
system.out.println("welcome to java");
}
}

2.import java.util.calendar;
class CalDemo
{
public static void main(string args[])
{
calendar calendar = calendar.getInstance();
string[]month=new string[]{"jan",...."dec"};
system.out.println("calendar month = "+month[calendar.get(calendar.month)]);
}
}

3.class divisionbyzeroDemo
{
public static void main(string args[])
{
int a=5;
int b=0;
try
{
system.out.println(a/b);
}
catch(arthmeticexception e)
{
system.out.println("division by zero is not possible");
}
}
}

4.import java.awt.*;
import java.awt.event.mouse event;
import java.awt.event.mouse listener;
public class mouse listener example implements mouse listener
{
label lb1,lbl2;
frame fr;
string s;
mouse listener example
{
fr=new frame("java mouse listener example");
lbl1=new label("demo for the mouse event,label.centre");
lbl2=new label();
fr.setlayout(new floatlayout());
fr.lbl1();
fr.lbl2();
fr.mouselistener(this);
fr.set size(250,250);
fr.setVisible(true);
}
public void mouseClicked(mouse event ev){
lbl2.settext("mouse button clicked");
fr.setVisible(true);
}
public void mouseEntered(mouse event ev){
lbl2.settext("mouse entered the area of window");
fr.setVisisble(true);
}
public void mouseExited(mouse event ev){
lbl2.settext("mouse left the area of window");
fr.setVisisble(true);
}
public void mousePresses(mouse event ev){
lbl2.settext("mouse button being pressed"):
fr.setVisible(true);
}
public void mouseReleased(mouse event ev){
lbl2.settext("mouse button being released");
fr.setVisible(true);
}
public static void main(string args[]){
new mouse listener example();
}
}

5.import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*
<applet code="width"=400 height=400>
</applet>
*/
public class arrowkeys extends applet implements key listen
int x1=100,y1=50,x2=250,y2=200;
public void init(){
add keylistener(this);
}
public void keypressed(key event ke)
show status("key down");
int key=ke.get keycode();
switch(key);
case keyevent.VK_LEFT:x1=x1-10; x2=x2-10;
case keyevent.VK_RIGHT:x1=x1+10; x2=x2+10;
case keyevent.VK_UP:y1=y1-10; y2=y2-10;
case keyevent.VK_DOWN:y1=y1+10; y2=y2+10;
}
repaint();
}
public void key released(key event ke){
}
public void key typed(key event ke){
repaint();
}
public void paint(graph g){
g.drawline(x1,y1,x2,y2);
g.drawreact(x1,y1+160,100,50);
g.drawoval(x1,y1+235,100,50);
}
}

6.import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class personal details extends applet implements action listener{
string s1=" ",s2=" ",s3=" ",s4=" ",s5=" ";
public void init(){
setlayout(null)
setsize(400,300)
button btn=new button("CLICK HERE FOR MY PERSONAL DETAILS");
add(btn);
btn.setBounds(20,50,300,30);
btn.addaction listener(this);
}
public void actionperformed(action event e){
s1= "Full name:divya darshini s";
s2=" Father name: sridhar Mother name: manjula age=19";
s3= "regno:jhnkabfjbdf college name:jain college";
s4= "nationality:indian contact no:8050804836":
s5= "address: 75th cross inidra nagar bangalore";
repaint();
}
public void paint(graph g){
g.setfont(new font("times roman",font.bold,14));
g.drawstrings(s1,20,110);
g.drawstrings(s2,20,160);
g.drawstrings(s3,20,180);
g.drawstrings(s4,20,230);
g.drawstrings(s5,20,280);
}
}

7.import java.awt.*;
import java.applet.*;
public class grid extends applet{
public void pain(graphics g){
int row,column,x,y=20;
for(row=1;row<5;row++){
x=20;
fpr(column=1;column<5;column++){
g.drawreact(x,y,40,40);
x=x+20;
}
y=y+20;
}
}
}
/*
<applet code="grid class"width=500 height=500>
</applet>
*/

8.import java.awt.*;
public class drawing extends canvas{
public void paint(graphics g){
g.drawrect(40,50,90,70);
g.fillrect(30,60,20,50);
g.drawroundrect(100,40,80,150,30,70);
g.fillroundrect(230,80,150,130,80,30);
g.drawoval(70,130,180,50,70,120);
g.filloval(40,220,120,50,70,80);
g.drawarc(40,50,120,70);
g.fillarc(50,20,120,70);
}
public static void main(string args[])
drawings m = new drawing()
frame f=new frame("shape");
f.add(m);
f.addsize(300,400);
f.setvisible(true);
}
}

9.import java.awt.*;
public class frame demo(){
frame demo(){
frame fm=new frame();
fm.set tiltle("my first frame");
label lb=new label("welcome to gui programming");
fm.add(lbl);
fm.size(300,300);
fm.setVisible(true);
}
public static void main(string args[])
{
frame demo ta=new frame demo();
}
}

10.class testfinally block


{
public static void main(string args[])
{
try{
int data=25/5;
s.o.p(data);
}
catch(null pointer exception e)
{
s.o.p(e);
}
finally
{
s.o.p("finally block is always executed");
}
s.o.p("rest of code...");
}
}

11.import student.fulltime.bca.student
public class main
{
public static void main(string args[])
{
student student1=new student("john",19,"male");
s.o.p("student1");
s1.display();
student student2=new student("alice",20,"female");
s.o.p("/n student2");
s2.display();
}
}

12.public class negative array size exception example


{
public static void main(string args[])
{
try{
int[]array=new int[-5];
}
catch(negative array size exception nase)
{
nase.printstacktrace();
}
s.o.p("continuing execution...");
}
}

13.

You might also like