Switch to full style
Graphics and animation Java code examples
Post a reply

JDialog usage example

Thu Jan 31, 2013 11:19 pm

JDialog usage example , this dialog is opened based on some action in application, this dialog is used to enter data about a book. This dialog has panel, and this panel has button, label, and comboBox.
JDialog.gif
Dialog
JDialog.gif (37.82 KiB) Viewed 5595 times

java code
package connectingdatabase.Search;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;

/**
*
* @author sami
*/
public class BookSearch extends JDialog {

/**
* Creates a new instance of VisitorPanel
*/
public BookSearch(Connection connection, JFrame myMother) {
super(myMother, "Search Book", true);
this.connection = connection;
MetaData = new MyComboBox(connection, "Book");
setSize(400, 300);
setLocation(100, 100);

Search.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DoSearch();

}
});
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

hide();
}
});

setLayout(new FlowLayout());
forma.setBorder(new TitledBorder(new LineBorder(Color.GRAY, 2), "Search panel"));
forma.setSize(400, 100);
forma.setLocation(10, 30);
forma.setLayout(new GridLayout(2, 2));


forma.add(MetaData);
forma.add(Search);
forma.add(SearchLabel);
forma.add(SearchFiled);
add(forma);

add(cancel);


}

public void DoSearch() {

String Col = (String) MetaData.getSelectedItem();
String Value = SearchFiled.getText();
mySearchResult showrs;

String query = "Select * from Book where " + Col + " Like('%" + Value + "%');";
try {

Statement stat = connection.createStatement();
rs = stat.executeQuery(query);
showrs = new mySearchResult(rs, this);
showrs.show();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
private Connection connection;
private JTextField SearchFiled = new JTextField(20);
private MyComboBox MetaData;
private JLabel SearchLabel = new JLabel("Search :");
private JPanel forma = new JPanel();
private JButton Search = new JButton("Search");
private JButton cancel = new JButton("Cancel");
private ResultSet rs;
}




Post a reply
  Related Posts  to : JDialog usage example
 Usage of sup tag     -  
 Usage of ins tag     -  
 usage of kbd tag     -  
 tt usage example     -  
 Usage of UL tag     -  
 Usage of sub tag     -  
 dir tag usage     -  
 dd tag usage     -  
 var tag usage     -  
 usage of ol tag     -  

Topic Tags

Java Swing