swing frame problem

swing frame problem

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

View Answers

November 20, 2010 at 5:12 PM

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


November 24, 2010 at 4:36 PM

thanks yaar .









Related Tutorials/Questions & Answers:
swing frame problem
swing frame problem  Hi All, I m creating a swing/awt based window... 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
Frame refresh problem - Swing AWT
Frame refresh problem  Whenever I close a child frame and reload it using the button on parent frame controls on the child frame load twice... to correct this problem....its urgent!! thnks in adv..  Hi Friend
Advertisements
Swing Problem on submission of button
Swing Problem on submission of button  How to close current frame (Frame1) and open a new frame (Frame2) already created and pass the data to frame2 from frame1 on the clicking of button in swing
Java Frame/ Applet /swing/awt
Java Frame/ Applet /swing/awt  I have produced a .exe file with the help of .jar file................... Now How can I Protect my software( .exe ) file bulid in Java from being Copy and Paste....????????? please reply
how to set a image in frame? - Swing AWT
how to set a image in frame?  how to set a image in frame using swing
tooltip problem - Swing AWT
to embed swing components into SWT Composite. I am using a Swing JButton in SWT Composite. My problem is that I am unable to see the tooltip for this button even...[]) { JFrame frame = new JFrame("Tooltip
Swing and AWT Problem - Swing AWT
Swing and AWT Problem  hi sir i have a problem i know from one Jframe...); and another Frame is public class AnotherPrintDemo extends JFrame...; } } so i want to send those three textfields values to the next frame
problem in swing-awt
problem in swing-awt  I am doing project in core java and i am facing one problem. I have to add command prompt(terminal) to the fream at bottom but not getting the solution. So please help me. thanks and regards, Aakash
jdbc and swing problem in netbeans
jdbc and swing problem in netbeans  i reteived the table from database in a jdbc program. next i want to do is place the table as it is in a jpanel.. i am using netbeans IDE can u tel me how to do that one?? urgent
jdbc and swing problem in netbeans
jdbc and swing problem in netbeans  i reteived the table from database in a jdbc program. next i want to do is place the table as it is in a jpanel.. i am using netbeans IDE can u tel me how to do that one?? urgent
add button to the frame - Swing AWT
table with database data JFrame frame = new JFrame("View Patients... for more information. http://www.roseindia.net/java/example/java/swing
How to make non resizable frame in Swing?
How to make non resizable frame in Swing?  I want code for making JFrame no re-sizable in the Swing based desktop application. Share me the code for this purpose. Thanks   Hi, Please check the tutorial Making a Frame
swing text field problem
swing text field problem  I want to navigate the content of text...(100,100,100,30); btn1=new JButton("click for second frame"); btn1.setBounds... JButton("click for first frame"); btn2.setBounds(100,250,100,30
swing text field problem
swing text field problem  I want to navigate the content of text...(100,100,100,30); btn1=new JButton("click for second frame"); btn1.setBounds... JButton("click for first frame"); btn2.setBounds(100,250,100,30
problem with JTable - Swing AWT
problem with JTable  hi guys, i was a student and i am very new to swings.i was having an assignment like i need to create a JTable...); } } public static void main(String s[]) { JFrame frame = new
Java Problem Steps - Swing AWT
Java Problem Steps  How to create a Jar File From the Dos prompt of a Swing program having two classes in the program with one is public class one of them
Jfree chart problem - Swing AWT
Jfree chart problem  hello i have a problem related to jfree chart... area chart and line chart both in a single frame. That is hybrid combination of stacked areachart and line chart in one frame. I want to display hybrid graph
java swing problem - Java Beginners
java swing problem  i doesn't know about the panel in swings here i had created one frame then created a panel and i added that to my frame but which is not adding any item and it not showing that item on the panel tell me how
Multiple session problem - Swing AWT
Multiple session problem  I am working in a Linux based java swing application. Problem: I have optimized JDialog and JPanel for my use.... This problem is quite critical as UI looks quite unpredictable due
Java Swings problem - Swing AWT
Java Swings problem  Sir, I am facing a problem in JSplitPane. I want the divider in the splitpane to be customized. I have a splitpane with Horizontal orientation and here, there lies the divider between left component and right
FRAME
FRAME  WHILE I'M RUNNINGFILE OF A GUI PROGRAMME(JDBC CONNECTION) INSTEAD OF OUTPUT FRAME ONLY TWO BLANK FRAMES ARE GETTING DISPLAYD... CAN ANYONE HELP ME TO SOLVE DS PROBLEM
FRAME
FRAME  WHILE I'M RUNNINGFILE OF A GUI PROGRAMME(JDBC CONNECTION) INSTEAD OF OUTPUT FRAME ONLY TWO BLANK FRAMES ARE GETTING DISPLAYD... CAN ANYONE HELP ME TO SOLVE DS PROBLEM
SWT_AWT bridge ,jtextfield edit problem - Swing AWT
bridge in my code to embed swing components in to SWT Composite. I am using SWT_AWT bridge frame and adding JTextfield to it, My problem is that the JTextfield...); java.awt.Frame frame = SWT_AWT.new_Frame(composite); JApplet applet==new JApplet
problem in adding a fullscreen frame nd adding a glass pane to it
problem in adding a fullscreen frame nd adding a glass pane to it  hi , here is my code import java.awt.*; import javax.swing.*; import java.awt.ToolKit; class MyFrame extends Jframe{ Container c; JPanel glass; MyFrame
New Problem in Form Resizing - Swing AWT
New Problem in Form Resizing  Hi, I am using a MDI application...)); The problem is arising when the user resizes the form. The EditorPane(old... HeadPane.setBounds(0, 0, this.getWidth(), 100); But it creates another problem. it overwrites
Problem when resizing the form - Swing AWT
Problem when resizing the form  Hi, I am facing a problem when resizing the form. I have a JTextPane on the JInternalFrame which occupy all... The EditorPane(Old) overlaps the HeadPane(new). I think this problem is occuring whenever
java image loadin and saving problem - Swing AWT
the frame savin is nt done plzz help me with this code......... import...){} } JFrame frame = new JFrame(); JPanel panel = new UploadImage
Creating a Frame
Creating a Frame : Swing Tutorials       This program shows you how to create a frame in Java Swing Application. The frame in java works like the main window where your components
frame
frame  how to creat a frame in java   Hi Friend, Try the following code:ADS_TO_REPLACE_1 import java.awt.*; import javax.swing.*; import java.awt.event.*; class RetrieveDataFromTextFields{ public static void
problem in swing program for opening two windows with same login credentials
problem in swing program for opening two windows with same login credentials  I Face two problems while writing the code in swing program 1.i... representation problem is when i delete a node the tree is not automatically
Setting an Icon for a Frame in Java
an icon for the frame in Java Swing. This program helps us to set the icon (image) on the title bar of the frame. When you open frame or window the icon... Setting an Icon for a Frame in Java   
billing frame
billing frame  how to generate billing frame using swing which contain sr. no, name of product, quantity, price & total
Java Swing : JFrame Example
Java Swing : JFrame Example In this section, you will learn how to create a frame in java swing. JFrame : JFrame class is defined in javax.swing.JFrame.... JFrame swing.  Create object of JFrame as - JFrame frame=new JFrame
SWING
SWING  A JAVA CODE OF MOVING TRAIN IN SWING
frame update another frame.
frame update another frame.   How do I make a link or form in one frame update another frame
How to make frame in java
How to make frame in java We are going to discus about frame in java. In this example We have make frame in java Swing. We have created JFrame class... of the window or frame. We have used setVisible(true) function. The setVisible
how to print JInternal frame component ?
how to print JInternal frame component ?  hello sir, i devalop a swing application .but problem is that how display report & print it. some data prefech from database & keep to jtable but how it is print with table
swing
swing  Write a java swing program to delete a selected record from a table
swing
swing  How to make swing component auto-resizable when JFrame resize
Swing
Swing  Write a java swing program to search the details of the students. Searching is performed on studentā??s first name. The details of all those students having same name as in given in searching criterion will be displayed
Swing
Swing  Write a java swing program to search the details of the students. Searching is performed on studentā??s first name. The details of all those students having same name as in given in searching criterion will be displayed
Image on frame
Image on frame   Hi, This is my code. In this I am unable to load the image.I want to know the problem with this code. import java.awt.*; import java.awt.event.*; public class AwtImg extends Frame { Image img; public
swing question
swing question  how to write multiple line text area in a single frame
one frame update another frame
one frame update another frame  How do I make a link or form in one frame update another frame
panel and frame
panel and frame  What is the difference between panel and frame
Java Frame
Java Frame  What is the difference between a Window and a Frame
Creating a Frame
Java Swing In this section we are giving many tutorial example of Java... applications. It is used only with the swing based applications. It can't be used in web based applications. For web based application that you can use swing
Frame query
Frame query  Hi, I am working on Images in java. I have two JFrame displaying same image. We shall call it outerFrame and innerFrame.In innerFrame i am rotating the image.After all the rotations i need to display this image
frame generation
frame generation  Hi I wnat to genarate one frame with two tabs working ,production..and I want two radiobuttons sector ,others in the frames..based on the tab selection I want to clikc the radio button..when i ckick the radio
Frame

Ads