
Hi All,
I m creating a swing/awt based window application which will take some data from user and according to that data it will display some information from DB to user etc.. Now when I will create a frame which have few buttons and Text Box to get some data from user at this time when I will click on submit button then next frame should be open with in same wondow (like in JSP forward and send-redirect). what shud I do to acheive this , I dont want to open a new window. shud I hide previous window when I ahve to open new frame or there is some other way to acheive this.
I need a reply ASAP.
Regards, Amish

Hi Friend,
Try the following code:
import java.sql.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class Data{
JLabel l,lab1,lab2;
JTextField text,text1,text2;
JButton button;
Data(){
l=new JLabel("Enter ID: ");
text=new JTextField(20);
JFrame frame=new JFrame();
frame.setLayout(null);
button=new JButton("Submit");
lab1=new JLabel("Name: ");
text1=new JTextField(20);
lab2=new JLabel("Address: ");
text2=new JTextField(20);
l.setBounds(10,10,100,20);
text.setBounds(120,10,100,20);
button.setBounds(120,40,90,20);
lab1.setBounds(10,70,100,20);
text1.setBounds(120,70,100,20);
lab2.setBounds(10,110,100,20);
text2.setBounds(120,110,100,20);
lab1.setVisible(false);
text1.setVisible(false);
lab2.setVisible(false);
text2.setVisible(false);
frame.add(l);
frame.add(text);
frame.add(button);
frame.add(lab1);
frame.add(text1);
frame.add(lab2);
frame.add(text2);
frame.setVisible(true);
frame.setSize(500,500);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String id=text.getText();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:student");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from data where id='"+id+"'");
String name="",address="";
while(rs.next()){
name=rs.getString("name");
address=rs.getString("address");
}
text1.setText(name);
text2.setText(address);
lab1.setVisible(true);
text1.setVisible(true);
lab2.setVisible(true);
text2.setVisible(true);
l.setVisible(false);
text.setVisible(false);
button.setVisible(false);
}
catch(Exception ex){}
}
});
}
public static void main(String[] args)
{
new Data();
}
}
Thanks

thanks yaar .
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.