AJP Outputs
AJP Outputs
AJP Outputs
COLLAGE OF
Report On
“Advanced JAVA output “
Submitted by: -
Abhishek G. Chinchole
\
~0~
Practical no. 1: Write a program to demonstrate the use of AWT
components.
Q.1) Design 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);
}
}
Output :
~1~
Q.2) Design an applet/application to create from using Text Field, Text Area,
Button and Label.
import java.awt.*;
class Use_TxtArea
{
public static void main(String[] args)
{
int i;
Frame fr=new Frame("This Program is for Displaying the TextField");
fr.setSize(350,300);
fr.setLayout(new FlowLayout());
fr.setVisible(true);
Label L1=new Label("Enter your address here");
TextArea input1=new TextArea(10,20);
TextField input=new TextField(10);
Button B1=new Button("SUBMIT");
fr.add(input);
fr.add(L1);
fr.add(B1);
fr.add(input1);
}
}
Output:
~2~
Practical no. 2: Write a program to design a form using the
components list and choice.
import java.awt.*;
f.add(c);
}
}
Output:
~3~
Practical no. 3 :Write a program to design simple calculator with the
use of grid layout.
import java.awt.*;
public class GridDemo
{
public static void main( String args[] )
{
Frame f = new Frame();
f.setVisible(true);
f.setSize(400,400);
f.setLayout(new GridLayout(2,2));
Output:
~4~
Q.2)Write a program to display the number on button from 0 to 9.
import java.awt.*;
import java.awt.event.*;
public class Grid
{
Grid()
{
Output:
~5~
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.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Cardlayout extends JFrame implements ActionListener
{
CardLayout card;
JButton b1,b2,b3;
Container c;
Cardlayout()
{
c=getContentPane();
card=new CardLayout(40,30);
c.setLayout(card);
b1=new JButton("Abhishek");
b2=new JButton("G");
b3=new JButton("Chinchole");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
c.add("a",b1);
c.add("b",b2);
c.add("c",b3);
}
public void actionPerformed(ActionEvent e)
{
card.next(c);
}
public static void main (String[] args)
{
Cardlayout cl=new Cardlayout();
cl.setSize(400,400);
cl.setVisible(true);
cl.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
Output:
~6~
Practical no,5 :Write a program using AWT to create a menu bar
where menu bar contain menu item such as file, edit, view and
create a submenu under the file menu :New and Open.
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);
}
}
Output:
~7~
Practical no.6 :Write a program using swing to display a
ScrollPane and JComboBox in an JApplet with the items-
English, Marathi, Hindi, Sanskrit.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/*
<applet code="JComboBoxDemo" width=300 height=100>
</applet>
*/
public class JComboBoxDemo extends JApplet implements ItemListener
{
JLabel jl;
ImageIcon green, red, black, yellow; public void init()
{
Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());
JComboBox jc = new JComboBox();
jc.addItem("Mumbai");
jc.addItem("Solapur");
jc.addItem("Pune");
jc.addItem("Banglore");
jc.addItemListener(this);
contentPane.add(jc);
jl = new JLabel(new ImageIcon("green.jpg"));
contentPane.add(jl);
}
public void itemStateChanged(ItemEvent ie)
{
String s = (String)ie.getItem(); jl.setIcon(new ImageIcon(s + ".jpg"));
}
}
Output::
~8~
Practical no.7 :Write a program to create a JTree.
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
Output:
~9~
Q.2)Write a program code to generate the following output.
Output:
~ 10 ~
Practical no.8 :Write a program to create a JTable.
import java.awt.*;
import javax.swing.*;
/*
<applet code="JTableDemo" width=400 height=200>
</applet>
*/
public class JTableDemo extends JApplet
{
public void init()
{
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
final String[] colHeads = { "Name", "Phone", "Fax" }; final Object[][] data = {
{ "Pramod", "4567", "8675" },
{ "Tausif", "7566", "5555" },
{ "Nitin", "5634", "5887" },
{ "Amol", "7345", "9222" },
{ "Vijai", "1237", "3333" },
{ "Ranie", "5656", "3144" },
{ "Mangesh", "5672", "2176" },
{ "Suhail", "6741", "4244" },
};
JTable table = new JTable(data, colHeads);
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp = new JScrollPane(table, v, h);
contentPane.add(jsp, BorderLayout.CENTER);
}
}
Output:
~ 11 ~
~ 12 ~
Q.2)Write a program code to generate the following output.
import java.awt.*;
import javax.swing.*;
/*
<applet code="JTableDemo" width=400 height=200>
</applet>
*/
public class JTableDemo extends JApplet
{
public void init()
{
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
final String[] colHeads = { "ID", "Name", "Salary" }; final Object[][] data = {
{ "101", "jay", "80000" },
{ "102", "Sachin", "55000" },
{ "103", "Amit", "58000" },
};
JTable table = new JTable(data, colHeads);
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp = new JScrollPane(table, v, h);
contentPane.add(jsp, BorderLayout.CENTER);
}
}
Output:
~ 13 ~
Practical no.9: Write a program to launch a JProgressBar.
Output:
~ 14 ~
Practical no. 10: Write a program to demonstrate status of key on
Applet window such as keyPressed, keyReleased, keyUp, keyDown.
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class KeyEx extends Applet implements KeyListener
{
public void init()
{
addKeyListener(this);
} public void keyReleased(KeyEvent ke)
{}
public void keyPressed(KeyEvent ke)
{
showStatus("key pressed");
repaint();
}
public void keyTyped(KeyEvent ke) { }
}
Output:
~ 15 ~
Q.2) Developer program, which will implements function key, such
as function key and arrow keys.
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){
int key = k.getKeyCode();
switch(key){
case KeyEvent.VK_F1:
msg = msg + "F1 ";
break;
case KeyEvent.VK_F2:
msg = msg + "F2 ";
break;
case KeyEvent.VK_F3:
msg = msg + "F3 ";
break;
case KeyEvent.VK_F4:
msg = msg + "F4 ";
break;
case KeyEvent.VK_RIGHT:
msg = msg + "RIGHT ";
break;
case KeyEvent.VK_LEFT:
msg = msg + "LEFT ";
break;
case KeyEvent.VK_UP:
msg = msg + "UP ";
break;
case KeyEvent.VK_DOWN:
msg = msg + "DOWN ";
break;}
repaint();}
public void keyReleased(KeyEvent k){}
Output:
~ 16 ~
Practical no. 12:Write a Program to demonstrate the use of
JTextField and JPasswordField using listener interface.
import javax.swing.*;
import java.awt.*;
f.setVisible(true);
f.setSize(400,400);
f.setLayout(new FlowLayout());
pf.setEchoChar('#');
f.add(pf);
}
Output:
SIGNATURE
***
~ 17 ~