
using JSplitPane split pane in three part. 1st in textField 2nd label and 3rd description. in textField we enter the primary key in textField than it show its all two part as label(image) and description of user.
thanks

import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
public class SplitPane extends JFrame {
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
JPanel p3 = new JPanel();
public SplitPane() {
p1.setLayout(null);
p2.setLayout(null);
p3.setLayout(null);
final JTextField text = new JTextField(20);
text.setBounds(5, 5, 150, 20);
p1.add(text);
final JLabel label = new JLabel();
label.setBounds(5, 5, 450, 200);
p2.add(label);
final JTextArea area = new JTextArea(5, 20);
JScrollPane pane = new JScrollPane(area);
pane.setBounds(5, 5, 450, 200);
setBounds(5, 5, 640, 450);
p3.add(pane);
JSplitPane sp1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
sp1.setDividerSize(8);
sp1.setDividerLocation(160);
sp1.add(p1);
JSplitPane sp2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
sp2.setDividerLocation(200);
sp2.add(p2);
sp2.add(p3);
sp1.add(sp2);
setContentPane(sp1);
setVisible(true);
text.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent e) {
area.setText("");
try {
int id = Integer.parseInt(text.getText());
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/test", "root", "root");
Statement st = con.createStatement();
ResultSet rs = st
.executeQuery("select * from data where id=" + id
+ "");
String str = "";
Blob b = null;
while (rs.next()) {
str = "Name: " + rs.getString("name") + "\nAddress: "
+ rs.getString("address") + "\nContact No: "
+ rs.getString("contactNo");
b = rs.getBlob("image");
}
ImageIcon icon = new ImageIcon(b.getBytes(1L, (int) b
.length()));
label.setIcon(icon);
area.append(str);
} catch (Exception ex) {
}
}
});
}
public static void main(String[] args) {
new SplitPane();
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.