0% found this document useful (0 votes)
38 views38 pages

22202B0042 Ninad - Kadam

Uploaded by

ninadk340
Copyright
© © All Rights Reserved
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)
38 views38 pages

22202B0042 Ninad - Kadam

Uploaded by

ninadk340
Copyright
© © All Rights Reserved
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/ 38

DEPARTMENT OF INFORMATION TECHNOLOGY

Subject: Advanced Java Subject Code: 22517


Programming
Semester: 5 Course:
Laboratory No: Name of Teacher: Archana Gopnarayan
Name of Student: Ninad Kadam Roll ID:22202B0042

Experiment No: 1
Title of Write a program to demonstrate the use of AWT components.
Experiment

Program 1:

Design an applet/application to demonstrate the use of Radio Button and Checkbox

Code:

import java.awt.*;

import java.applet.*;

public class Radio extends Applet

public void init()

Checkbox c1 = new Checkbox ("Java");

Checkbox c2 = new Checkbox ("CSS");

c1.setBounds(20,50,100,100);

c2.setBounds(20,60,100,110);

add(c1);

add(c2);
CheckboxGroup cg= new CheckboxGroup();

Checkbox c3= new Checkbox("IF",cg,true);

c3.setBounds(50,20,50,100);

Checkbox c4= new Checkbox("CO",cg,true);

c4.setBounds(50,30,50,110);

add(c3);

add(c4);

/*<applet code ="Radio" width=500 height= 500> </applet>*/

Output:
Program 2:

Develop a program to select multiple languages known to user.

Code:

import java.awt.*;

public class Listdemo extends Frame

Listdemo()

setSize(500,500);

setTitle("Langauges");

setVisible(true);

setLayout(null);

List l = new List(4,true);

l.add("Marathi");

l.add("Hindi");

l.add("English");

l.add("Gujrati");

l.setBounds(50,50,100,100);

add(l);

public static void main(String args[])

Listdemo l1= new Listdemo();

}}
Output:
Subject: Advanced Java Subject Code: 22517
Programming
Semester: 5 Course:
Laboratory No: Name of Teacher: Archana Gopnarayan
Name of Student: Ninad Kadam Roll ID:22202B0042

Experiment No: 2
Title of Write a program to design a form using the components List and
Experiment Choice.

Program 1:Develop an applet /application using List components to add names of 10


different cities

Code:

import java.awt.*;

import java.applet.*;

public class Cities1 extends Applet

public void init()

List l = new List(10,true);

l.add("Mumbai");

l.add("Pune");

l.add("Kolkata");

l.add("Surat");

l.add("Delhi");

l.add("Jaipur");

l.add("Hydrabad");

l.add("Kolhapur");

l.add("Nashik");
l.add("Nagpur");

l.setBounds(50,50,100,100);

add(l);

/*<applet code= "Cities1" width=200 height =200> </applet>*/

Output:
Subject: Advanced Java Subject Code: 22517
Programming
Semester: 5 Course:
Laboratory No: Name of Teacher: Archana Gopnarayan
Name of Student: Ninad Kadam Roll ID:22202B0042

Experiment No: 3
Title of Write a program to design simple calculator with the use of Grid
Experiment Layout.

Program:

import java.awt.*;

public class Grid1 extends Frame

Grid1()

setSize(500,500);

setVisible(true);

setLayout(new GridLayout(5,5,20,20));

setTitle("GRIDLAYOUT");

for( int i=0; i<25; i++)

add(new Button("Button"+i));

public static void main(String args[])

Grid1 g= new Grid1();

}}
Output:
Subject: Advanced Java Subject Code: 22517
Programming
Semester: 5 Course:
Laboratory No: Name of Teacher: Archana Gopnarayan
Name of Student: Ninad Kadam Roll ID:22202B0042

Experiment No: 4
Title of Use of CardLayout to write a program to create a two-level card deck
Experiment that allows the user to select an operating system.

Program:

import java.awt.*;

public class Grid extends Frame

Grid()

setSize(500,500);

setTitle("GridBagLayout");

setVisible(true);

setLayout(new GridBagLayout());

GridBagConstraints g = new GridBagConstraints();

g.fill=GridBagConstraints.HORIZONTAL;

g.gridx=0;

g.gridy=0;

add(new Button("Button One"),g);

g.gridx = 1;

g.gridy = 0;

add(new Button("Button Two"),g);


g.fill = GridBagConstraints.HORIZONTAL;

g.gridx = 0;

g.ipadx = 20;

g.gridy = 1;

add(new Button ("Button Three"),g);

g.gridx=1;

g.ipadx=20;

g.gridy=1;

add(new Button("Button Four"),g);

g.fill= GridBagConstraints.HORIZONTAL;

g.gridx=0;

g.gridy=2;

g.gridwidth=2;

add(new Button("Button Five"),g);

public static void main (String args[])

Grid g= new Grid();

}
Output:
Subject: Advanced Java Subject Code: 22517
Programming
Semester: 5 Course:
Laboratory No: Name of Teacher: Archana Gopnarayan
Name of Student: Ninad Kadam Roll ID:22202B0042

Experiment No: 5
Title of Write a program using AWT to create a menu bar where menu bar
Experiment contains menu items such as File, Edit, View and create a submenu
under the File menu: New and Open

Program:

import java.awt.*;

import javax.swing.*;

public class MenuColor extends JFrame

MenuColor()

setTitle("Color Menu Demo");

setSize(400,400);

setVisible(true);

setLayout(new BorderLayout());

MenuBar mb= new MenuBar();

setMenuBar(mb);

Menu m = new Menu("colors");

mb.add(m);

MenuItem m1 =new MenuItem("Red");

m.add(m1);

MenuItem m2= new MenuItem("Green");


m.add(m2);

MenuItem m3= new MenuItem("Yellow");

m.add(m3);

MenuItem m4= new MenuItem("Black");

m.add(m4);

m4.setEnabled(false);

public static void main(String args[])

MenuColor mc =new MenuColor();

}
Output:

Program 2:

import javax.swing.*;

import java.awt.*;

public class GridLayoutExample {

public static void main(String[] args) {

JFrame frame = new JFrame("GridLayout Example");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setSize(300, 200);

frame.setLayout(new GridLayout(2, 3));

JButton button1 = new JButton("Button 1");

JButton button2 = new JButton("Button 2");


JButton button3 = new JButton("Button 3");

JButton button4 = new JButton("Button 4");

JButton button5 = new JButton("Button 5");

frame.add(button1);

frame.add(button2);

frame.add(button3);

frame.add(button4);

frame.add(button5);

frame.setVisible(true);

Output :
Program :

import java.awt.*;

import java.awt.event.*;

public class Menudemo extends Frame

Menudemo()

setSize(500,500);

setVisible(true);

setTitle("MenuBar-Ninad Kadam-22202B0042");

setLayout(null);

MenuBar m1=new MenuBar();

setMenuBar(m1);

Menu m2=new Menu("file");

m1.add(m2);

MenuItem i1=new MenuItem("New");

MenuItem i2=new MenuItem("Open");

MenuItem i3=new MenuItem("Save as");

MenuShortcut ms = new MenuShortcut(KeyEvent.VK_X);

MenuItem i4=new MenuItem("Exit",ms);

m2.add(i1);

m2.add(i2);

m2.add(i3);

m2.addSeparator();

m2.add(i4)003B
Subject: Advanced Java Subject Code: 22517
Programming
Semester: 5 Course:
Laboratory No: Name of Teacher: Archana Gopnarayan
Name of Student: Ninad Kadam Roll ID:22202B0042

Experiment No: 7
Title of Write a program to create a JTree.
Experiment

Code:

import java.awt.*;

import javax.swing.*;

import javax.swing.tree.*;

import javax.swing.event.*;

public class demoTreeExample extends JFrame implements TreeSelectionListener

JTree jt;

DefaultMutableTreeNode a1,a2,a3,a4,a5,a6,a7;

JLabel l1;

demoTreeExample()

setLayout(new FlowLayout());

setSize(400,400);

setTitle("Ninad Kadam");

setVisible(true);

a1 = new DefaultMutableTreeNode("India");

a2 = new DefaultMutableTreeNode("Maharashtra");

a3 = new DefaultMutableTreeNode("Mumbai");

a4 = new DefaultMutableTreeNode("Pune");

a5 = new DefaultMutableTreeNode("Nashik");
a6 = new DefaultMutableTreeNode("Nagpur");

a7 = new DefaultMutableTreeNode("Gujrat");

a1.add(a2);

a2.add(a3);

a2.add(a4);

a2.add(a5);

a2.add(a6);

a1.add(a7);

jt = new JTree(a1);

jt.addTreeSelectionListener(this);

add(jt);

l1 = new JLabel();

add(l1,BorderLayout.SOUTH);

public void valueChanged(TreeSelectionEvent e)

l1.setText(""+e.getPath());

public static void main(String []args)

new demoTreeExample();

Output:
Subject: Advanced Java Subject Code: 22517
Programming
Semester: 5 Course:
Laboratory No: Name of Teacher: Archana Gopnarayan
Name of Student: Ninad Kadam Roll ID:22202B0042

Experiment No: 8
Title of Write a program to create a JTable
Experiment

Code:

import java.awt.*;

import javax.swing.*;

import javax.swing.table.*;

public class demoTableExample extends JFrame

JTable jt;

JScrollPane sp;

demoTableExample()

setSize(400,400);

setLayout(new FlowLayout());

setTitle("Ninad Kadam");

setVisible(true);

Object data[][]={

{"Ninad Kadam",90,"A"},

{"Saad Ansari",91,"A"},
{"Parth Patel",93,"A"},

{"Sanmitra Pawar",80,"A"},

{"Neel Gadekar",74,"B"},

{"Nitesh Bandi",70,"B"},

{"Rohan Kamble",70,"B"},

{"Apurv Madaye",65,"C"},

{"Gaurav More",65,"C"},

{"Vedh Pookie",65,"C"},

};

String Heading[]=

{"Name","Percentage","Grade"};

jt = new JTable(data,Heading);

sp = new JScrollPane(jt);

add(sp);

public static void main(String []args)

new demoTableExample();

Output:
Subject: Advanced Java Subject Code: 22517
Programming
Semester: 5 Course:
Laboratory No: Name of Teacher: Archana Gopnarayan
Name of Student: Ninad Kadam Roll ID:22202B0042

Experiment No: 9
Title of
Experiment Write a program to launch a JProgressBar

Code :

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class Jprogdemo extends JFrame implements ActionListener

JProgressBar j;

JButton b;

Jprogdemo()

setSize(300,300);

setVisible(true);

setTitle("NinadProgressbar");

setLayout(new FlowLayout());

j=new JProgressBar(0,100);

j.setValue(0);

j.setStringPainted(true);

b=new JButton("Show Progress");

add(j);
add(b);

b.addActionListener(this);

public void actionPerformed(ActionEvent a)

new Thread(()->

int i=0;

while(i<=100)

j.setValue(i);

i=i+10;

try{

Thread.sleep(1000);

catch(Exception e)

}).start();

public static void main(String args[])

Jprogdemo jb=new Jprogdemo();


}

Output :

Subject: Advanced Java Subject Code: 22517


Programming
Semester: 5 Course:
Laboratory No: Name of Teacher: Archana Gopnarayan
Name of Student: Ninad Kadam Roll ID:22202B0042

Experiment No: 10
Title of
Experiment Write a program to demonstrate status of key on Applet window
such as KeyPressed, KeyReleased, KeyUp, KeyDown

Program 1: Develop a program to accept two numbers and display product of two numbers
when user pressed “Multiply” button.

Code:

import javax.swing.*;

import java.awt.event.*;

public class demo9 extends JFrame implements ActionListener {

JTextField textField1, textField2;

JLabel resultLabel, num1Label, num2Label;

JButton multiplyButton;

public demo9() {

setTitle("Ninad");

setSize(300, 200);

setLayout(null);

setDefaultCloseOperation(EXIT_ON_CLOSE);

setVisible(true);

num1Label = new JLabel("Enter Number");

num1Label.setBounds(50, 10, 150, 20);


add(num1Label);

textField1 = new JTextField();

textField1.setBounds(50, 30, 80, 30);

add(textField1);

num2Label = new JLabel("Enter Number");

num2Label.setBounds(150, 10, 150, 20);

add(num2Label);

textField2 = new JTextField();

textField2.setBounds(150, 30, 80, 30);

add(textField2);

multiplyButton = new JButton("Multiply");

multiplyButton.setBounds(100, 80, 100, 30);

add(multiplyButton);

resultLabel = new JLabel("Result: ");

resultLabel.setBounds(100, 120, 150, 30);

add(resultLabel);

multiplyButton.addActionListener(this);

public void actionPerformed(ActionEvent e) {


try {

double num1 = Double.valueOf(textField1.getText());

double num2 = Double.valueOf(textField2.getText());

double result = num1 * num2;

resultLabel.setText("Result: " + result);

} catch (NumberFormatException ex) {

resultLabel.setText("Invalid Input. Please enter numbers.");

public static void main(String[] args) {

new demo9();

OUTPUT :
Subject: Advanced Java Programming Subject Code: 22517
Semester: 5 Course: IF5I
Laboratory No: Name of Teacher: Archana Gopnarayan
Name of Student: Ninad Kadam Roll ID: 22202B0042

Experiment No: 11
Title of Experiment Write a program to demonstrate various mouse events using MouseListener
and MouseMotionListener interface

Program 1: Write a program to demonstrate various mouse events using MouseListener and
MouseMotion listener interface.
Code:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class demo11 extends Applet implements MouseListener,MouseMotionListener


{
String msg;

public void init()


{
setVisible(true);
addMouseListener(this);
addMouseMotionListener(this);
}
public void mouseClicked(MouseEvent e)
{
msg="Mouse Clicked";
repaint();
}

public void mousePressed(MouseEvent e)


{
msg="Mouse Pressed";
repaint();
}

public void mouseReleased(MouseEvent e)


{
msg="Mouse Released";
repaint();
}

public void mouseEntered(MouseEvent e)


{
msg="Mouse Entered";
repaint();
}

public void mouseExited(MouseEvent e)


{
msg="Mouse Exited";
repaint();
}

public void mouseMoved(MouseEvent e)


{
msg="Mouse Moved:"+e.getX()+" "+e.getY();
repaint();
}

public void mouseDragged(MouseEvent e)


{
msg="Mouse Dragged:"+e.getX()+" "+e.getY();
repaint();
}

public void paint(Graphics g)


{
g.drawString(msg,50,50);
g.drawString("Saad",50,30);
}
}
/*<applet code="demo11" height="400" width="400"></applet>*/
OUTPUT :
Program 2: Write a program to count the number of clicks performed by the user in a Frame
window
Code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class demo11_2 extends JFrame


{
int count=0;
JLabel l1;

demo11_2()
{
setTitle("Ninad");
setSize(400,400);
setLayout(new FlowLayout());
setVisible(true);
addMouseListener(new click());

l1=new JLabel("");
add(l1);
}
public class click extends MouseAdapter
{
public void mouseClicked(MouseEvent e)
{
count++;
l1.setText("Mouse Clicks:"+count);
}
}
public static void main(String args[])
{
demo11_2 d1=new demo11_2();
}
}
OUTPUT :
Subject: Advanced Java Programming Subject Code: 22517
Semester: 5 Course: IF5I
Laboratory No: Name of Teacher: Archana Gopnarayan
Name of Student: Ninad Kadam Roll ID: 22202B0042

Experiment No: 12
Title of Experiment Write a program to demonstrate the use of JTextField and JPasswordField
using Listener Interface

Program 1: Write a program using JPasswordField to accept password from user and if the length is
less than 6 characters then error message should be displayed “Password length must be >6
characters”
Code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class demo12 extends JFrame implements ActionListener
{
JLabel l1;
JButton b1;
TextField jp1;
JLabel t1,result;
String pass;
int passsize;
demo12()
{
setTitle("Ninad Kadam");
setSize(400,400);
setLayout(new FlowLayout());
setVisible(true);

t1=new JLabel("Enter Password");


jp1=new TextField(20);
jp1.setEchoChar('*');
add(t1);
add(jp1);

b1=new JButton("Check");
result=new JLabel();
add(b1);
add(result);

b1.addActionListener(this);
}

public void actionPerformed(ActionEvent e)


{
pass=jp1.getText();
passsize=pass.length();
if(passsize<=6)
{
result.setText("Error:Password too small");
}
else
{
result.setText("Good");
}
}

public static void main(String args[])


{
demo12 d1=new demo12();
}
}
OUTPUT :
Subject: Advanced Java Programming Subject Code: 22517
Semester: 5 Course: IF5I
Laboratory No: Name of Teacher: Archana Gopnarayan
Name of Student: Ninad Kadam Roll ID: 22202B0042

Experiment No: 13
Title of Experiment Write a program to demonstrate the use of WindowAdapter class.

Program 1: Write a program to demonstrate the use of WindowAdapter class


Code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class demo13 extends Frame


{
JLabel l1;
JButton b1;

demo13()
{
setTitle("Ninad");
setSize(400,400);
setLayout(new FlowLayout());
setVisible(true);

b1=new JButton("Click");
add(b1);
addWindowListener(new clicks());

l1=new JLabel("");
add(l1);
}
public class clicks extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
public static void main(String args[])
{
demo13 d1=new demo13();
}
}
Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy