Total members 11889 |It is currently Fri Mar 29, 2024 9:50 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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.
Attachment:
File comment: Dialog
JDialog.gif
JDialog.gif [ 37.82 KiB | Viewed 5555 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;
}




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : JDialog usage example
 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     -  
 Usage of sup tag     -  



Topic Tags

Java Swing
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com