Untitled
Untitled
Untitled
Roll No: 26
Code:
import java.awt.*;
public Practical1()
setLayout(new FlowLayout());
add(lb);
add(tf);
add(ta);
add(b1);
P1.setVisible(true);
}
Output:
Practical No 2: Write a program to design a form using the componets List and Choice.
Roll No: 26
Code:
import java.awt.*;
import java.applet.*;
</applet>*/
Ls1.add("Summer");
Ls1.add("Winter");
Ls1.add("Rainy");
add(Ls1);
}
Output:
Practical No 3: Write a program to design simple calculator with thw use of Grid Layout.
Roll No: 26
Code:
import java.awt.*;
import java.applet.*;
/*
</applet>
*/
setFont(new Font("SansSerif",Font.BOLD,24));
setLayout(g1);
for(int i=1;i<=9;i++)
add(new Button(""+i));
add(bt2);
add(bt3);
}
Output:
Practical No 4: Use of CardLayout to write a program to create a two-level card deck that
allows the user to select an operating system.
Roll No: 26
Code:
import java.awt.Button;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.*;
public GridBagLayoutExample()
setLayout(grid);
this.setLayout(layout);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridx = 1;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.ipady = 20;
gbc.gridx = 0;
gbc.gridy = 1;
gbc.gridx = 1;
gbc.gridy = 1;
gbc.gridx = 0;
gbc.gridy = 2;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridwidth = 2;
setSize(300,300);
setPreferredSize(getSize());
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
Output:
Practical No 5: Write a program using AWT to create a menu bar where menu bar contains
menu items such as File,Edit,View and Create a submenu under the File menu:New and Open.
Roll No: 26
Write a program which creates Menu of diiferent colors and disable menu item for Black
color.
Code:
import java.awt.*;
MenuEx()
setMenuBar(mr);
mn3.setEnabled(false);
m1.add(mn1);
m1.add(mn2);
m1.add(mn3);
m1.add(mn4);
m1.add(mn5);
mr.add(m1);
class Practical5
m.setTitle("Menu Bar");
m.setSize(500,500);
m.setVisible(true);
}
Output:
Practical No 6: Write a program using swing to display a ScrollPane and JcomboBox in nan
JApplet with the items –English,Marathi,Hindi,Sanskrit.
Roll No: 26
Write a program to develop a frame to select the different states of India using JcomboBox .
Code:
import javax.swing.*;
Practical6()
cb.setBounds(50,50,90,20);
f.add(cb);
f.setLayout(null);
f.setSize(400,400);
f.setVisible(true);
new Practical6();
}
}
Output:
Practical No 7: Write a program to create a JTree.
Roll No: 26
Code:
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
Tree()
s.add(s3);
s2.add(s4);
s2.add(s5);
s2.add(s6); s2.add(s7);
JTree j=new JTree(s);
f.add(j);
f.setSize(200,200);
f.setVisible(true);
new Tree();
}
Output:
Practical No 8: Write a program to create a Jtable.
Roll No:
Code:
import javax.swing.*;
JFrame f;
TableExample(){
f=new JFrame();
{"102","Sanika","780000"},
{"101","Anushka","700000"}};
String column[]={"ID","NAME","SALARY"};
jt.setBounds(30,40,200,300);
f.add(sp);
f.setSize(300,400);
f.setVisible(true);
new TableExample();
}
}
Output:
Practical No 10: Write a program to demonstrate status of key on Applet window such as
KeyPressed,KeyReleased,KeyUp,KeyDown.
Roll No: 26
Code:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
</applet>*/
addKeyListener(this);
showStatus("Key Down");
showStatus("Key Up");
}
msg += ke.getKeyChar();
repaint();
g.drawString(msg, X, Y);
}
Output:
Practical No 11: Write a program to demonstrate various mouse events using MouseListener
and MouseMotion listener interface.
Roll No: 26
Code:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
</applet>*/
Label l;
add(l);
addMouseListener(this);
int a=me.getClickCount();
showStatus("Mouse Clicked");
}
int a=me.getClickCount();
showStatus("Mouse Clicked");
int a=me.getClickCount();
showStatus("Mouse Clicked");
showStatus("Mouse Clicked");
showStatus("Mouse Clicked");
}
Output:
Practical No 12: Write a program to demonstrate the use of JtextField and JpasswordField
using Listener Interface .
Roll No: 26
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
JLabel l1;
JTextField t1;
JLabel l2;
JTextField t2;
JButton b;
JLabel l3;
public Abc()
setLayout(new FlowLayout());
t1=new JTextField(20);
t2=new JTextField(20);
b=new JButton("Add");
l3=new JLabel("Result");
add(l1);
add(t1);
add(l2);
add(t2);
add(b);
add(l3);
b.addActionListener(this);
setVisible(true);
setSize(250,400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
int num1=Integer.parseInt(t1.getText());
int num2=Integer.parseInt(t2.getText());
int value=num1+num2;
l3.setText(""+value);
}
Output:
Practical No 14: Write a program to demonstrate the use of InetAddress class and its factory
methods.
Roll No: 26
Code:
import java.net.*;
import java.util.*;
public class B
String hostname=sc.nextLine();
System.out.println(myIP.getHostAddress());
}
Output:
Practical No 15: Write a program to demonstrate the use of URL and URLConnection class and
its methods .
Roll No: 26
Code:
import java.net.*;
System.out.println("Protocol: "+ul.getProtocol());
System.out.println("Port: "+ul.getPort());
System.out.println("Host: "+ul.getHost());
System.out.println("File: "+ul.getFile());
}
Output: