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

BSC IT Sem 5 Advance Java Practical Solutions

The document describes a Java program that demonstrates using a split pane interface to display planetary information. The program divides the screen into two parts - the left side contains a list of planet names, and the right side displays the image of the selected planet. When a planet is selected from the list, the corresponding image and details like radius and number of moons are displayed on the right. The program imports necessary libraries, defines arrays of planet names and images, and creates JList, JLabel, JTextArea and JSplitPane components to build the interface.

Uploaded by

Ankit Patel
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
420 views

BSC IT Sem 5 Advance Java Practical Solutions

The document describes a Java program that demonstrates using a split pane interface to display planetary information. The program divides the screen into two parts - the left side contains a list of planet names, and the right side displays the image of the selected planet. When a planet is selected from the list, the corresponding image and details like radius and number of moons are displayed on the right. The program imports necessary libraries, defines arrays of planet names and images, and creates JList, JLabel, JTextArea and JSplitPane components to build the interface.

Uploaded by

Ankit Patel
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Practical 2.

Write java pro to demonstrate editable


employee details for software company.
import javax.swing.*;
import java.awt.*;
public class MyFrame extends JFrame {
JTable jt;
JScrollPane jsp;
Object[][] data = {
can provide your own details

//here you

{"NS","Vipul","atul kahate", new Integer(5)},


{"ST","sheth","unknown", new Integer(3)},
{"LA","Internet","wellknown", new
Integer(2)},
};
String[] title =
{"Subject","Source","Writer","Experience"};
public MyFrame()
{
super();
setSize(300,300);
Container cp = this.getContentPane();
cp.setLayout(new FlowLayout());
jt = new JTable(data,title);
jsp = new JScrollPane(jt);

cp.add(jsp);
}
}
class Prac2 {
public static void main(String args[])
{
MyFrame mf = new MyFrame();
mf.setVisible(true);
}
}
Output :

/*Practical 3
Write a java program using Split pane to
demonstrate a screen divided in two parts, one
part contains the names of Planets and another
Displays the image of planet. When user selects
the planet name form Left screen, appropriate
image of planet displayed in right screen.
*/
import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
class JSplitPaneDemo implements
ListSelectionListener
{
JFrame frame;
JScrollPane sp1,sp2,sp3;
JSplitPane splitpane1,splitpane2;
JList list;
String planet_name[] =
{"Mecury" ,"Venus" ,"Earth" ,"Mars" ,"Jupiter" ,"Sat
urn" ,"Uranus","Neptune", "Pluto"};
ImageIcon me,v,e,m,j,s,u,n,p;
JLabel label;
JPanel panel;
JTextArea text;

String info[] = {"Radius =2440 \nMoons = 0",


"Radius =6052 \nMoons = 0", "Radius =6378
Moons = 1", "Radius =3397 \nMoons = 2", "Radius
=71892 \nMoons = 16", "Radius =60268 \nMoons
= 18", "Radius =25559 \nMoons = 17", "Radius
=24766 \nMoons = 8",
"Radius =1137 \nMoons = 1"};
public JSplitPaneDemo()
{
frame = new JFrame("SplitPaneDemo");
frame.setVisible(true);
frame.setSize(500,500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_C
LOSE);
list = new JList(planet_name);
me = new ImageIcon("E:\\Planet\\Mercury.jpg");
v = new ImageIcon("E:\\Planet\\Venus.jpg");
e = new ImageIcon("E:\\Planet\\Earth.jpg");
m = new ImageIcon("E:\\Planet\\Mars.jpg");
j = new ImageIcon("E:\\Planet\\Jupiter.jpg");
s = new ImageIcon("E:\\Planet\\Saturn.jpg");
u = new ImageIcon("E:\\Planet\\Uranus.jpg");
n = new ImageIcon("E:\\Planet\\Neptune.jpg");
p = new ImageIcon("E:\\Planet\\Pluto.jpg");
panel = new JPanel(new FlowLayout());

label=new JLabel();
label.setIcon(me);
panel.add(label);
sp1 = new JScrollPane(list);
text = new JTextArea(info[0],20,10);
sp3 = new JScrollPane(text);
splitpane2 = new
JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,sp1,
panel);
splitpane1 = new
JSplitPane(JSplitPane.VERTICAL_SPLIT,true,splitpan
e2,sp3);
frame.add(splitpane1);
list.addListSelectionListener(this);
}
public void valueChanged(ListSelectionEvent le)
{
int selected;
selected=list.getSelectedIndex();
if(selected==0)
{
label.setIcon(me);
text.setText(info[selected]);
}

else if(selected==1)
{
label.setIcon(v);
text.setText(info[selected]);
}
else if(selected==2)
{
label.setIcon(e);
text.setText(info[selected]);
}
else if(selected==3)
{
label.setIcon(m);
text.setText(info[selected]);
}
else if(selected==4)
{
label.setIcon(j);
text.setText(info[selected]);
}
{

else if(selected==5)
label.setIcon(s);

text.setText(info[selected]);
}
else if(selected==6)
{
label.setIcon(u);
text.setText(info[selected]);
}
else if(selected==7)
{
label.setIcon(n);
text.setText(info[selected]);
}
else if(selected==8)
{
label.setIcon(p);
text.setText(info[selected]);
}
}
public static void main(String args[])
{
JSplitPaneDemo obj = new JSplitPaneDemo();
}

}
Output:

You might also like