0% found this document useful (0 votes)
21 views25 pages

AJP Practical

Uploaded by

atullawale42
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)
21 views25 pages

AJP Practical

Uploaded by

atullawale42
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/ 25

Q.

1Design an applet/application to demonstrate the use of Radio

Button and Checkbox

import java.awt.*;
import java.util.*;

public class RadioDemo


{
public static void main( String args[] )
{
Frame f = new Frame();
f.setVisible(true);
f.setSize(400,400);
f.setLayout(new FlowLayout());

Label l1 = new Label("Select Subjects:");

Checkbox cb1 = new Checkbox("English");


Checkbox cb2 = new Checkbox("Sanskrit");
Checkbox cb3 = new Checkbox("Hindi");
Checkbox cb4 = new Checkbox("Marathi");

Label l2 = new Label("Select Gender:");


CheckboxGroup cg = new CheckboxGroup();
Checkbox c1 = new Checkbox("Male",cg,true);
Checkbox c2 = new Checkbox("Female",cg,true);

f.add(l1);
f.add(cb1);
f.add(cb2);
f.add(cb3);
f.add(cb4);
f.add(l2);
f.add(c1);
f.add(c2);
}

Q.2Design an applet/application to create form using Text Field,

Text Area, Button and Label.

import java.awt.*;

public class BasicAWT


{
public static void main(String args[])
{
Frame f = new Frame();
f.setSize(400,400);
f.setVisible(true);
f.setLayout(new FlowLayout() );

Label l1 = new Label();


l1.setText("Enter Your Name ");

TextField tf = new TextField("Atharva");

Label l2 = new Label("Address");


TextArea ta = new TextArea("",3,40);

Button b = new Button("Submit");

f.add(l1); f.add(tf); f.add(l2); f.add(ta); f.add(b);


}
}

Q.3Develop a program to select multiple languages known to user.

(e. g Marathi, Hindi, English, Sanskrit).

import java.awt.*;

public class Exp_1_4 { Exp_1_4()

Frame f= new Frame();

Choice c=new Choice();

c.setBounds(100,100, 75,75);

c.add("Marathi");

c.add("Hindi");

c.add("English");

c.add("Sanskrit");

c.add("Gujarati");

f.add(c);

f.setSize(400,400);

f.setLayout(null);

f.setVisible(true);

public static void main(String args[])


{

new Exp_1_4();

Q.4Develop an applet/ application using List components to add

names of 10 different cities

import java.awt.*;

import java.applet.*;

public class Cities extends Applet

public void init()

List l1=newList(10,true);

l1.add("Nashik");

l1.add("Pune");

l1.add("Mumbai");

l1.add("Nanded");

l1.add("Sinner");

l1.add("Jalgaon");

l1.add("Dhule");

l1.add("AhmedNagar");

l1.add("Nandurbar");

l1.add("Buldhana");

add(l1);

/*<applet code="Cities.java" width=300 height=300></applet>*/

Q.5Develop applet / application to select multiple names of news

papers
import java.awt.;\

import java.applet.;

public class Newspaper extends Applet

public void init()

List l1=new List(10,true);

l1.add("The IndianExpress");

l1.add("The Timesof India");

l1.add("Lokmat");

l1.add("Hindhustan Times");

add(l1);

/<applet code="Newspaper.java" width=300 height=300></applet>/

Q.7Write a program to display The Number on Button from 0 to 9

import java.awt.*;

import java.applet.*;

public class GridLayout_Demol extends Applet

GridLayout g;

Button b0,b1,b2,b3,b4,65,66,67,68,69;

public void init()

G=newGridLayout(5,2);

setLayout(g);

b0-new

Button("A");

b1=new

Button("B");
b2=new

Button("C");

b3=new

Button("D");

b4-new

Button("E");

b5=new

Button("F");

b6-new

Button("G");

b7-new

Button("H");

b8-new

Button("I");b9-new

Button("J");

add(b0);

add(b1);

add(b2);

add(b3);

add(b4);

add(b5);

add(b6);

add(b7);

add(b8);

add(b9);

/*<appletcode="GridLayout_Demo1.class" width=300height=300></applet>*/

Q.8Write a program to generate following output using Border

Layyout

import java.awt.*;

public class BorderDemo


{

public static void main( String args[] )

Frame f = new Frame();

f.setVisible(true);

f.setSize(400,400);

f.setLayout(new BorderLayout());

Button b1 = new Button("North");

Button b2 = new Button("South");

Button b3 = new Button("East");

Button b4 = new Button("West");

Button b5 = new Button("Center");

f.add(b1,BorderLayout.NORTH);

f.add(b2,BorderLayout.SOUTH);

f.add(b3,BorderLayout.EAST);

f.add(b4,BorderLayout.WEST);

f.add(b5,BorderLayout.CENTER);

Q.9Write Java program to display following output.

import java.awt.Button;

import java.awt.GridBagConstraints;

import java.awt.GridBagLayout;

import javax.swing.*;

public class GridBagLayoutExample extends JFrame{

public static void main(String[] args) {

GridBagLayoutExample a = new GridBagLayoutExample();


}

public GridBagLayoutExample() {

GridBagLayoutgrid = new GridBagLayout();

GridBagConstraints gbc = new GridBagConstraints();

setLayout(grid);

setTitle("GridBag Layout Example");

GridBagLayout layout = new GridBagLayout();

this.setLayout(layout);

gbc.fill = GridBagConstraints.HORIZONTAL;

gbc.gridx = 0;

gbc.gridy = 0;

this.add(new Button("Button One"), gbc);

gbc.gridx = 1;

gbc.gridy = 0;

this.add(new Button("Button two"), gbc);

gbc.fill = GridBagConstraints.HORIZONTAL;

gbc.ipady = 20;

gbc.gridx = 0;

gbc.gridy = 1;

this.add(new Button("Button Three"), gbc);

gbc.gridx = 1;

gbc.gridy = 1;

this.add(new Button("Button Four"), gbc);

gbc.gridx = 0;

gbc.gridy = 2;

gbc.fill = GridBagConstraints.HORIZONTAL;

gbc.gridwidth = 2;

this.add(new Button("Button Five"), gbc);

setSize(300, 300);

setPreferredSize(getSize());

setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);

Q.10Write a program which creates Menu of different colors and

disable menu item for Black color.

import java.awt.*;

class MenuEx extends Frame

MenuEx()

MenuBar mr=new MenuBar();

setMenuBar(mr);

Menu m1=new Menu("Colours");

MenuItem mn1=new MenuItem("RED");

MenuItem mn2=new MenuItem("YELLOW");

MenuItem mn3=new MenuItem("BLACK");

mn3.setEnabled(false);

MenuItem mn4=new MenuItem("BLUE");

MenuItem mn5=new MenuItem("GREEN");

m1.add(mn1);

m1.add(mn2);

m1.add(mn3);

m1.add(mn4);

m1.add(mn5);

mr.add(m1);

class MenuBarEx

{
public static void main(String args[]){

MenuEx m=new MenuEx();

m.setTitle("Menu Bar");

m.setSize(500,500);

m.setVisible(true);

Q.11Write a program to develop a frame to select the different

states of India using JComboBox .

import javax.swing.*;

public class CB2 {

CB2(){

JFrame f=new JFrame();

String s[]={"Maharashtra","Punjab","Gujrat","TamilNadu"};

JComboBox cb=new JComboBox(s);

cb.setBounds(50, 50,90,20);

f.add(cb);

f.setLayout(null);

f.setSize(400,400);

f.setVisible(true);

public static void main(String[] args) {

new CB2();

Q.12Develop a program to demonstrate the use of ScrollPane in

Swings

import javax.swing.*;
import java.awt.*;

public class JScrollPaneDemo

public static void main(String[] args)

/* Container contentPane = getContentPane();

contentPane.setLayout(new BorderLayout());

*/

JFrame JFrameMain = new JFrame();

JFrameMain.setVisible(true);

JFrameMain.setSize(400,400);

JPanel JPanelButton = new JPanel();

JPanelButton.setLayout(new GridLayout(20,10));

for( int i = 1 ; i <= 200 ; i++ )

String s = "";

s = s.valueOf(i);

JPanelButton.add(new JButton( s ) );

int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;

int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED ;

JScrollPane JScrollPaneObj = new JScrollPane(JPanelButton , v,h);

JFrameMain.add(JScrollPaneObj , BorderLayout.CENTER);
}

Q.13Develop a program to demonstrate the use of tree component in

swing.

import javax.swing.*;

import javax.swing.tree.*;

import java.awt.*;

public class JTreeDemo

public static void main(String[] args) {

JFrame JFrameMain = new JFrame();

JFrameMain.setVisible(true);

JFrameMain.setSize(400,400);

DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("India");

DefaultMutableTreeNode maharashtraNode = new DefaultMutableTreeNode("Maharashtra");

DefaultMutableTreeNode gujrathNode = new DefaultMutableTreeNode("Gujrath");

rootNode.add(maharashtraNode);

rootNode.add(gujrathNode);

DefaultMutableTreeNode mumbaiSubNode = new DefaultMutableTreeNode("Mumbai");

DefaultMutableTreeNode puneSubNode = new DefaultMutableTreeNode("Pune");

DefaultMutableTreeNode nashikSubNode = new DefaultMutableTreeNode("Nashik");

DefaultMutableTreeNode nagpurSubNode = new DefaultMutableTreeNode("Nagpur");

maharashtraNode.add(mumbaiSubNode);
maharashtraNode.add(puneSubNode);

maharashtraNode.add(nashikSubNode);

maharashtraNode.add(nagpurSubNode);

JTree tree = new JTree(rootNode);

JFrameMain.add(tree);

Q.14Develop a program to demonstrate the use of JTable.

import javax.swing.*;

import java.awt.*;

import javax.swing.table.*;

public class JTableDemo

public static void main(String[] args) {

JFrame JFrameMain = new JFrame();

JFrameMain.setVisible(true);

JFrameMain.setSize(400,400);

String colHeads[] = {"ID","Name","Salary"};

Object data[][] = {

{101,"Amit",670000},

{102,"Jai",780000},

{101,"Sachin",700000}
};

JTable JTableObj = new JTable(data,colHeads);

int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;

int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;

JScrollPane jsp = new JScrollPane(JTableObj,v,h);

JFrameMain.add(jsp,BorderLayout.CENTER);

//JFrameMain.add(JTableObj);

Q.15Write a program code to generate the following output

import javax.swing.*;

import java.awt.*;

import javax.swing.table.*;

public class JTableDemo

public static void main(String[] args) {

JFrame JFrameMain = new JFrame();

JFrameMain.setVisible(true);

JFrameMain.setSize(400,400);

String colHeads[] = {"ID","Name","Salary"};

Object data[][] = {

{101,"Amit",670000},
{102,"Jai",780000},

{101,"Sachin",700000}

};

JTable JTableObj = new JTable(data,colHeads);

int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;

int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;

JScrollPane jsp = new JScrollPane(JTableObj,v,h);

JFrameMain.add(jsp,BorderLayout.CENTER);

//JFrameMain.add(JTableObj);

Q.16Write a Java program to create a table of Name of Student,

Percentage and Grade of 5 students using JTable.

import java.awt.BorderLayout;

import javax.swing.JApplet;

import javax.swing.JTable;

import javax.swing.ScrollPaneConstants;

import javax.swing.JScrollPane;

public class JTableStudents extends JApplet

public void init()

setVisible(true);

setSize(400,400);

//setLayout( new BorderLayout() );


String collumnHeading[] = {"Name","Percentage","Grade"};

Object data[][]={

{"A1",98,"A"},

{"A2",90,"C"},

{"A3",88,"A"},

{"A4",99,"A"},

{"A5",59,"A"},

{"A6",94,"D"},

{"A7",92,"A"},

{"A8",42,"C"},

{"A9",85,"A"},

{"A10",98,"B"}

};

JTable JTableObj = new JTable(data,collumnHeading);

int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;

int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;

JScrollPane jsp = new JScrollPane(JTableObj,v,h);

add(jsp,BorderLayout.CENTER);

/*

<applet code="JTableStudents" height="400" width="400">

</applet>

*/
Q.17Write a program code to generate the following output

import javax.swing.*;

import java.awt.*;

public class JProgresBarDemo

JProgressBar JProgressBarObj;

int i=0,num=0;

JProgresBarDemo()

JFrame JFrameMain = new JFrame();

JFrameMain.setVisible(true);

JFrameMain.setSize(400,400);

JFrameMain.setLayout(new FlowLayout());

JProgressBarObj = new JProgressBar(0,2000);

JProgressBarObj.setValue(0);

JProgressBarObj.setStringPainted(true);

JFrameMain.add(JProgressBarObj);

public static void main(String[] args)

JProgresBarDemo jpd = new JProgresBarDemo();

jpd.iterate();

public void iterate()


{

while(i<=2000){

JProgressBarObj.setValue(i);

i =i+20;

try

Thread.sleep(150);

catch(Exception e)

Q.18Write a program to generate KeyEvent when a key is pressed

and display “Key Pressed” message.

import java.awt.*;

import java.applet.*;

import java.awt.event.*;

public class KeyEventDemo extends Applet implements KeyListener

String msg = "";

public void init()

addKeyListener(this);

public void keyPressed(KeyEvent k)

{
showStatus("Key Pressed");

repaint();

public void paint(Graphics g)

g.drawString(msg, 10, 10);

Q.19 (1) Write a program to change the background color of Applet

when user performs events using Mouse

import java.awt.*;

import java.applet.*;

import java.awt.event.*;

public class MouseColor extends Applet implements MouseMotionListener

public void init()

addMouseMotionListener(this);

public void mouseDragged(MouseEvent me)

setBackground(Color.red);

repaint();

public void mouseMoved(MouseEvent me)

setBackground(Color.green);
repaint();

/*

<applet code="MouseColor" width=300 height=300>

</applet>

*/

Q.19 (2) Write a program to count the number of clicks performed by the

user in a Frame window

import java.awt.*;

import java.applet.*;

import java.awt.event.*;

public class MouseCount extends Applet implements MouseListener

int count = 0;

public void init()

addMouseListener(this);

public void mouseClicked(MouseEvent me)

count++;

showStatus("Number of time Clicked:"+count);

repaint();

public void mouseEntered(MouseEvent me)


{

public void mouseExited(MouseEvent me)

public void mousePressed(MouseEvent me)

public void mouseReleased(MouseEvent me)

/*

<applet code="MouseCount" width=300 height=300>

</applet>

*/

Q.21 Write a program using JPasswordField and JTextField to

demonstrate the use of user authentication

import javax.swing.*;

import java.awt.*;

public class JPasswordChange

public static void main(String[] args)

JFrame f = new JFrame();

f.setVisible(true);

f.setSize(400,400);

f.setLayout(new FlowLayout());
JPasswordField pf = new JPasswordField(20);

pf.setEchoChar('#');

f.add(pf);

Q.22 (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 displayyed“Password length must be

>6 characters”.

import javax.swing.*;

import java.awt.event.*;

public class PasswordFieldeEx1 {

public static void main(String[] args)

JFrame F=new JFrame("Password Field Example");

final JPasswordField value = new JPasswordField();

value.setBounds(100,75,100,30);

JLabel L1=new JLabel("Username:-");

L1.setBounds(20,20, 80,30);

JLabel L2=new JLabel("Password:-");

L2.setBounds(20,75, 80,30);

JButton B = new JButton("Login");

B.setBounds(100,120, 80,30);

final JTextField text = new JTextField();

text.setBounds(100,20, 100,30);
F.add(value);

F.add(L1);

F.add(L2);

F.add(B);

F.add(text);

F.setSize(300,300);

F.setLayout(null);

F.setVisible(true);

B.addActionListener(new ActionListener()

public void actionPerformed(ActionEvent event) {

event.getSource();

char[] password = value.getPassword();

if (password.length < 6) { System.out.println("Password length must be >6 characters");

Else

System.out.println("Login successfully");

});

Q.22(2) Write a program using JTextField to perform the addition

of two numbers.

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class JTextAdd implements ActionListener


{

JTextField tf , tf1 ;

JLabel res;

JTextAdd()

JFrame f = new JFrame();

f.setVisible(true);

f.setSize(400,400);

f.setLayout(new FlowLayout());

JLabel jl = new JLabel("Enter 1st Number:");

tf = new JTextField(5);

JLabel jl1 = new JLabel("Enter 2nd Number:");

tf1 = new JTextField(5);

res = new JLabel("Addition");

tf1.addActionListener(this);

f.add(jl);

f.add(tf);

f.add(jl1);

f.add(tf1);

f.add(res);

public static void main(String[] args) {

JTextAdd jt = new JTextAdd();

}
public void actionPerformed(ActionEvent ae)

String str1 = tf.getText();

double fn = Double.parseDouble(str1);

double sn = Double.parseDouble(tf1.getText());

res.setText("Sum is " + (fn+sn));

Q.23 Write a Program to create a Student Table in database and

insert a record in a Student table

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.Statement;

import java.sql.SQLException;

public class InsertStaticOracle

public static void main(String args[])

Statement st = null;

Connection connection = null;

try{

oracle.jdbc.OracleDriver driverObj = new oracle.jdbc.OracleDriver();

String url = "jdbc:oracle:thin:@localhost:1521:XE", username = "System" ,password = "pass";

connection =DriverManager.getConnection(url,username,password);
if(connection!=null)

System.out.println("Connection established successfully");

st = connection.createStatement();

String qry = "Insert into Student values(104 ,'Atharva Agrawal','Dhule')";

int count = st.executeUpdate(qry);

System.out.println(count+" Statement Created Successfully ");

catch(Exception e)

e.printStackTrace();

finally{

try

if(st != null)

st.close();

if(connection != null)

connection.close();

catch(SQLException e){

e.printStackTrace();

You might also like