Java Pract 233
Java Pract 233
Java Pract 233
Aim—Write a JDBC program that display the data of given table in a GUI
table.
Code--
select * from JAVA.PRODUCT;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
try
Class.forName("org.apache.derby.jdbc.ClientDriver");
Statement stmt=con.createStatement();
while(rs.next())
catch(Exception e)
System.out.println(e);
}
Output--
Practical no-5
Aim—Create a swing Application to demonstrate use of scrollpane to change its
color selected using color chooser.
code—
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ScrollPaneColorDemo {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
createAndShowGUI();
});
}
private static void createAndShowGUI() {
JFrame frame = new JFrame("ScrollPane Color Demo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 300);
frame.add(panel);
frame.setVisible(true);
}
}
Output—
Practical no-6
A)Aim :- Write a program for the Border Layout.
Code--
package borderex;
import java.awt.*;
import javax.swing.*;
FlowLayoutex()
f.add(b1);
f.add(b2);
f.add(b3);
f.add(b4);
f.setLayout(new FlowLayout());
f.setSize(500,600);
f.setVisible(true);
new FlowLayoutex();
} }
Output—
B)Aim :- Write a program for the Grid Layout.
Code-
package border1;
import java.awt.*;
import javax.swing.*;
GridLayoutex()
f.add (btn1);
f.add (btn2);
f.add (btn3);
f.add (btn4);
f.add (btn5);
f.add (btn6);
f.setLayout(new GridLayout());
f.setSize(300, 300);
f.setVisible(true);
{
new GridLayoutex ();
Output--
C)Aim :- Write a program for the Border Layout.
Code—
package border;
import java.awt.*;
import javax.swing.*;
public class Border {
JFrame f = new JFrame();
Border()
{
JButton b1 = new JButton("NORTH");
JButton b2 = new JButton("SOUTH");
JButton b3 = new JButton("EAST");
JButton b4 = new JButton("WEST");
JButton b5 = new JButton("CENTER");
f.add(b1,BorderLayout.NORTH);
f.add(b2,BorderLayout.SOUTH);
f.add(b3,BorderLayout.EAST);
f.add(b4,BorderLayout.WEST);
f.add(b5,BorderLayout.CENTER);
f.setSize(300,300);
f.setVisible(true);
}
public static void main(String[] args) {
new Border();
}
}
Output--
Practical no-7
A)Aim :- Write a program to demonstrate the Action Event.
code—
import java.awt.*;
import java.awt.event.*;
public class Main {
public static void main(String[] args) {
Frame f=new Frame("ActionListener Example");
final TextField tf=new TextField();
tf.setBounds(50,50, 150,20);
Button b=new Button("Click Here");
b.setBounds(50,100,60,30);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
tf.setText("Welcome to Javatpoint.");
}
});
f.add(b);f.add(tf);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
}
Output--
import java.awt.*;
import java.awt.event.*;
Label i;
MouseListenerex(){
addMouseListener(this);
i=new Label();
PopupMenu l;
i.setBounds(20,25,100,20);
add(i);
setSize(300,300);
setLayout(null);
setVisible(true);
i.setText("Mouse Clicked");
i.setText("Mouse Entered");
i.setText("Mouse Exited");
i.setText("Mouse Pressed");
i.setText("Mouse Released");
}
new MouseListenerex();
Output--
Practical no-8
Aim :- Demonstrate the use of Adapter Class in Event Handling.
Code--
package border12;
import java.awt.*;
import java.awt.event.*;
AdapterExample(){
f.addWindowListener(new WindowAdapter(){
});
f.setSize(400,400);
f.setLayout (null);
f.setVisible(true);
new AdapterExample();
Output—
Practical No- 9
Aim :- Demonstrate the use of Anonymous Inner Class in Event
Handling.
code—
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
frame.add(panel);
frame.pack();
frame.setVisible(true);
}
}
Output--
Output--