0% found this document useful (0 votes)
16 views

Java Practical 2

This document contains code for a Java Swing application that displays a progress bar. It creates a JProgressBar, sets its minimum and maximum values, and adds it to the frame. In a progress() method, it uses a Thread.sleep in a loop to increment the progress bar value over time, simulating long-running work. The progress bar is updated on each loop iteration until it reaches the maximum value.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Java Practical 2

This document contains code for a Java Swing application that displays a progress bar. It creates a JProgressBar, sets its minimum and maximum values, and adds it to the frame. In a progress() method, it uses a Thread.sleep in a loop to increment the progress bar value over time, simulating long-running work. The progress bar is updated on each loop iteration until it reaches the maximum value.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

//******************** (Practical 6) X1 ************************

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Practical1 extends JFrame implements ItemListener
{
JLabel l=new JLabel("Where are you");
public Practical1()
{
setLayout(new FlowLayout());
JComboBox jcb = new JComboBox();
jcb.addItemListener(this);
jcb.addItem("pune");
jcb.addItem("solapur");
jcb.addItem("Bengluru");
jcb.addItem("mumbai");
add(jcb);
add(l);
this.setSize(300,300);
this.setVisible(true);
}
public void itemStateChanged(ItemEvent ie)
{
String s = (String)ie.getItem();
l.setText("you are in "+s);
}
public static void main(String a[])
{
Practical1 p = new Practical1();
}
}
//OUTPUT :
//******************** (Practical 6) XIII1 ************************
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Practical1 extends JFrame implements ItemListener
{
JLabel l=new JLabel("Where are you");
public Practical1()
{
setLayout(new FlowLayout());
JComboBox jcb = new JComboBox();
jcb.addItemListener(this);
jcb.addItem("Maharashtra");
jcb.addItem("Gujrat");
jcb.addItem("Kerala");
jcb.addItem("Karnataka");
jcb.addItem("Goa");
jcb.addItem("Rajsthan");
add(jcb);
add(l);
this.setSize(300,300);
this.setVisible(true);
}
public void itemStateChanged(ItemEvent ie)
{
String s = (String)ie.getItem();
l.setText(""+s);
}
public static void main(String a[])
{
Practical1 p = new Practical1();
}
}
//OUTPUT :
//******************** (Practical 6) XIII2 ************************
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Practical1 extends JFrame
{
public Practical1()
{
setLayout(new FlowLayout());

int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
JTextArea jta = new JTextArea(20,20);
JScrollPane jsp = new JScrollPane(jta,v,h);
add(jsp);
this.setSize(300,300);
this.setVisible(true);
}
public static void main(String a[])
{
Practical1 p = new Practical1();
}
}
//OUTPUT :
//******************** (Practical 7) X 1,2 ************************
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import java.awt.*;
import java.awt.event.*;
public class Practical1 extends JFrame
{
public Practical1()
{
setLayout(new FlowLayout());

DefaultMutableTreeNode country = new


DefaultMutableTreeNode("India",true);
DefaultMutableTreeNode s1 = new
DefaultMutableTreeNode("Maharashtra",true);
s1.add(new DefaultMutableTreeNode("Mumbai"));
s1.add(new DefaultMutableTreeNode("Nashik"));
s1.add(new DefaultMutableTreeNode("Pune"));
s1.add(new DefaultMutableTreeNode("Nagpur"));
country.add(s1);
DefaultMutableTreeNode s2 = new
DefaultMutableTreeNode("Gujrat",true);
s2.add(new DefaultMutableTreeNode("Ahamdabad"));
s2.add(new DefaultMutableTreeNode("Gandhinagar"));
country.add(s1);
country.add(s2);

JTree jt = new JTree(country);


this.add(jt);

this.setSize(300,300);
this.setVisible(true);
}
public static void main(String a[])
{
Practical1 p = new Practical1();
}
}
//OUTPUT :
//******************** (Practical 7) XIII ************************
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import java.awt.*;
import java.awt.event.*;
public class Practical1 extends JFrame
{
public Practical1()
{
setLayout(new FlowLayout());

DefaultMutableTreeNode drive = new


DefaultMutableTreeNode("DRIVE",true);
DefaultMutableTreeNode s1 = new
DefaultMutableTreeNode("FOLDER 1",true);
s1.add(new DefaultMutableTreeNode("FILE 1"));
s1.add(new DefaultMutableTreeNode("FILE 2"));
s1.add(new DefaultMutableTreeNode("FILE 3"));
s1.add(new DefaultMutableTreeNode("FILE 4"));
drive.add(s1);
DefaultMutableTreeNode s2 = new
DefaultMutableTreeNode("FOLDER 2",true);
s2.add(new DefaultMutableTreeNode("FILE 1"));
s2.add(new DefaultMutableTreeNode("FILE 2"));
drive.add(s1);
drive.add(s2);

JTree jt = new JTree(drive);


this.add(jt);

this.setSize(300,300);
this.setVisible(true);
}
public static void main(String a[])
{
Practical1 p = new Practical1();
}
}
//OUTPUT :
//******************** (Practical 8) X 1,2 ************************
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import java.awt.*;
import java.awt.event.*;
public class Practical1 extends JFrame
{
public Practical1()
{
setLayout(new FlowLayout());

final String[] th = {"ID","NAME","SALARY"};


final Object[][] table = {
{101,"Amit",670000},
{102,"Jai",700000},
{101,"Sachin",70000}};

JTable jt = new JTable(table,th);


JScrollPane jsp = new JScrollPane(jt,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HO
RIZONTAL_SCROLLBAR_ALWAYS);

add(jsp);
this.setSize(300,300);
this.setVisible(true);
}
public static void main(String a[])
{
Practical1 p = new Practical1();
}
}
//OUTPUT :
//******************** (Practical 8) XIII 1 ************************
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import java.awt.*;
import java.awt.event.*;
public class Practical1 extends JFrame
{
public Practical1()
{
setLayout(new FlowLayout());

final String[] th = {"NAME","PERCENTAGE","GRADE"};


final Object[][] table = {
{"student 1",95.67,"A+"},
{"student 2",80,"A+"},
{"student 3",60,"A"},
{"student 4",89,"A+"},
{"student 5",78,"A+"},
{"student 6",49,"B+"},
{"student 7",89,"A+"},
{"student 8",89,"A+"},
{"student 9",78,"A+"},
{"student 10",78,"A+"}};

JTable jt = new JTable(table,th);


JScrollPane jsp = new JScrollPane(jt,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HO
RIZONTAL_SCROLLBAR_ALWAYS);

add(jsp);
this.setSize(300,300);
this.setVisible(true);
}
public static void main(String a[])
{
Practical1 p = new Practical1();
}
}

//OUTPUT :
//******************** (Practical 9) X 1 ************************
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import java.awt.*;
import java.awt.event.*;
public class Practical1 extends JFrame
{
JProgressBar jpb = new JProgressBar(0,100);
public Practical1()
{
setLayout(new FlowLayout());

jpb.setStringPainted(true);
jpb.setValue(0);
add(jpb);

this.setSize(300,300);
this.setVisible(true);
progress();
}
public void progress()
{
int i = 1;
try {
while (i <= 500) {
Thread.sleep(1000);
jpb.setValue(i);
i++;
}
}
catch(Exception e)
{

}
}
public static void main(String a[])
{
Practical1 p = new Practical1();
}
}
//OUTPUT :
//******************** (Practical 9) XIII 1,2
************************
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import java.awt.*;
import java.awt.event.*;
public class Practical1 extends JFrame implements ActionListener
{
JProgressBar jpb = new JProgressBar(0,100);
Button b = new Button("Progress");
public Practical1()
{
setLayout(new FlowLayout());

jpb.setStringPainted(true);
add(jpb);
add(b);
b.addActionListener(this);
this.setSize(300,300);
this.setVisible(true);
}
public void actionPerformed(ActionEvent ae) {

int i = 1;
try {
while (i <= 100) {
Thread.sleep(10);
jpb.setValue(i);
i++;
}
} catch (Exception e) {

}
public static void main(String a[])
{
Practical1 p = new Practical1();
}
}
//OUTPUT :

You might also like