Adv Java Adi
Adv Java Adi
Aim:- Implements and create five button and put on different direction and centre by
using border layout manager.
Roll no :- 36 Class:-BCA-II
___________________________________________________________________
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
BorderLayoutDemo() {
JPanel pa = new JPanel();
pa.setLayout(new BorderLayout());
pa.add(new JButton("NORTH"), BorderLayout.NORTH);
pa.add(new JButton("SOUTH"), BorderLayout.SOUTH);
pa.add(new JButton("EAST"), BorderLayout.EAST);
pa.add(new JButton("WEST"), BorderLayout.WEST);
pa.add(new JButton("CENTER"), BorderLayout.CENTER);
add(pa);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300, 300);
setVisible(true);
}
}
class MainFrame {
public static void main(String[] args) {
new BorderLayoutDemo();
}
}
Output:-
Practical No 2
Aim:-Implementation of AWT to create dialog box
Roll no :- 36 Class:-BCA-II
___________________________________________________________________________
Code:-
import java.awt.*;
import java.awt.event.*;
public class DialogExample {
private static Dialog d;
DialogExample() {
Frame f= new Frame();
d = new Dialog(f , "Dialog Example", true);
d.setLayout( new FlowLayout() );
Button b = new Button ("OK");
b.addActionListener ( new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
DialogExample.d.setVisible(false);
}
});
d.add( new Label ("Click button to continue."));
d.add(b);
d.setSize(300,300);
d.setVisible(true);
}
public static void main(String args[])
{
new DialogExample();
}
}
Output:-
Practical No 3
fileMenu.add(exitItem);
menuBar.add(fileMenu);
frame.setSize(300, 300);
frame.setVisible(true);
}
}
Output:-
Practical No 4
Code:-
import java.awt.*;
ListExample1() {
Frame f = new Frame();
List l1 = new List(5);
l1.add("java");
l1.add("python");
l1.add("css");
l1.add("DBMS");
l1.add("HTML");
f.add(l1);
f.setSize(400, 400);
f.setLayout(null);
f.setVisible(true);
}
Output:-
Practical No 5
import java.awt.*;
import java.awt.event.*;
ChoiceExample2() {
label.setAlignment(Label.CENTER);
label.setSize(400, 100);
f.add(c);
f.add(label);
f.add(b);
f.setSize(400, 400);
f.setLayout(null);
f.setVisible(true);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String data = "Programming language Selected: "+ c.getItem(c.getSelectedIndex());
label.setText(data);
}
});
}
Output:-
Practical No 06
import java.awt.*;
public one1() {
frame.add(checkbox);
frame.setSize(400, 200);
frame.setLayout(null);
frame.setVisible(true);
}
public static void main(String[] args) {
new one1();
}
}
Output:-
Practical No 07
import java.awt.*;
import java.awt.Font.*;
import java.awt.Label.*;
import java.awt.Scrollbar.*;
l.setForeground(Color.RED);
f.add(l);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
}
Output:-
Practical No 08
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
JRadioButton jRadioButton1;
JRadioButton jRadioButton2;
JButton jButton;
ButtonGroup G1;
JLabel L1;
public Demo()
{
this.setLayout(null);
jRadioButton1 = new JRadioButton();
G1 = new ButtonGroup();
L1 = new JLabel("Qualification");
jRadioButton1.setText("Under-Graduate");
jRadioButton2.setText("Graduate");
this.add(jRadioButton1);
this.add(jRadioButton2);
this.add(jButton);
this.add(L1);
G1.add(jRadioButton1);
G1.add(jRadioButton2);
}
}
class RadioButton {
public static void main(String args[])
{
Demo f = new Demo();
f.setTitle("RadioButtons");
f.setVisible(true);
}
}
Output:-
Practical No 09
import java.awt.BorderLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JFrame;
import javax.swing.JToggleButton;
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
System.out.println("Deselected");
}
}
};
toggleButton.addItemListener(itemListener);
frame.add(toggleButton, BorderLayout.NORTH);
frame.setSize(300, 125);
frame.setVisible(true);
}
}
Output:-
Practical No 10
import javax.swing.*;
import java.awt.*;
SwingUtilities.invokeLater(new Runnable() {
public void run() {
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setSize(400, 300);
window.add(tabPanel);
window.setVisible(true);
}
});
}
}
Output:-
Practical No 11
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
DefaultMutableTreeNode root
= new DefaultMutableTreeNode("Root");
DefaultMutableTreeNode parent1
= new DefaultMutableTreeNode("Parent 1");
DefaultMutableTreeNode child1_1
= new DefaultMutableTreeNode("Child 1.1");
DefaultMutableTreeNode child1_2
= new DefaultMutableTreeNode("Child 1.2");
parent1.add(child1_1);
parent1.add(child1_2);
DefaultMutableTreeNode parent2
= new DefaultMutableTreeNode("Parent 2");
DefaultMutableTreeNode child2_1
= new DefaultMutableTreeNode("Child 2.1");
DefaultMutableTreeNode child2_2
= new DefaultMutableTreeNode("Child 2.2");
parent2.add(child2_1);
parent2.add(child2_2);
root.add(parent1);
root.add(parent2);
frame.add(new JScrollPane(tree));
frame.setSize(400, 400);
frame.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Output:-