-
setting focus from one window to the next
Hi everyone,
I need help on seting focus on windows. I have a JFrame window that contains the main method and it is a gui interface. It creates another JFrame window with a button. When you run the program it creates both JFrame windows. I would like to have the window with the button to have focus so that the user can not access the gui interface until he closes the first window. I have tried to use setVisible(false) and setEnabled(false) in the constructor which accomplishes disabling the gui on start up but i can not re-enable it when i close the first window.
-
Call toFront on the frame with button. For more information
http://java.sun.com/j2se/1.4.2/docs/....html#toFront()
-
you need a simple modal frame , JOptionPane can do it:
http://java.sun.com/docs/books/tutor...ts/dialog.html
-
Thanks
Thanks mr1hy1,
I tried the link and it helped me out. I have a custom dialog box with a texbox and a password field. Are you able to connect a dialog box to a database? What i was trying to do was create a login window that connects to a database to search for accounts. And the window cannot loose focus to the main window.
Do you have any suggestions on this one?
-
JOptionPane give some standart modal frames.
even you can do more , becos its message is not a String , its Component ( even you can put a JPanel ).
but if you need something more special ,
you can write your own class which extends JDialog ( not JFrame ).
JDialog class has a constructor like this :
JDialog ( JFrame owner , boolean modal )
-
error message
Hi I tried to connect the JDialog box to a database using the same code as I have for other programs using JFrames. But when i compile it it gives me an error message stating that the line:
Statement st = conn.createStatement();
error message -> reference to Statement is ambiguous, both class java.sql.Statment in java.sql and class java.beans.Statement in java.beans match
I don't get this when i run this in a normal program only when i use it in a dialog box.
Here is the code that i used to connect to the database:
String data = "jdbc:mysql://localhost:3306/p1";
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(
data, "root", "pass");
--> Statement st = conn.createStatement();
ResultSet rec = st.executeQuery(
"SELECT * " +
"FROM ident ");
while(rec.next()) {
int n = 1;
System.out.println(rec.getString(++n) + "\t"
+rec.getString(++n) + "\t"
+rec.getString(++n) + "\t"
+rec.getString(++n) + "\t"
+ rec.getString(++n));
}
st.close();
} catch (SQLException s) {
System.out.println("SQL Error: " + s.toString() + " "
+ s.getErrorCode() + " " + s.getSQLState());
} catch (Exception ev) {
System.out.println(" Error: " + ev.toString()
+ ev.getMessage());
}
What do you think is the problem?
-
figured out
sorry i figured it out. I got it to work.
I've run into another glitch. I have a database with the name richard in it. I have the dialog box ask for a name you type in richard. Then the program is suppose to find the record with the name richard. and return the resultset. I try to check if what i have written in the textbox is the same as what has been retreived from the database. But when i use if (a==b) it doesn't work. It prints out "not found". When it should print out "found".
What i would like the program to do is ask for a name and then check to see if the name is in the database.
Here is the code:
String a = textField.getText();
String data = "jdbc:mysql://localhost:3306/p1";
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(
data, "root", "naofumi");
Statement st = conn.createStatement();
ResultSet rec = st.executeQuery(
"SELECT * " +
"FROM ident " +
"WHERE fname='"+a+"'");
System.out.println("First Name\t Last Name\t Account\t"+
"ID\t Password");
while(rec.next()) {
int n = 1;
String b = rec.getString(n);
System.out.println("this is what is in a " +a);
System.out.println("this is what is in b " +b);
if (a==b) {
System.out.println("found");
}
else {
System.out.println("not found");
}
}
st.close();
} catch (SQLException s) {
System.out.println("SQL Error: " + s.toString() + " "
+ s.getErrorCode() + " " + s.getSQLState());
} catch (Exception ev) {
System.out.println(" Error: " + ev.toString()
+ ev.getMessage());
}
Similar Threads
-
Replies: 0
Last Post: 01-03-2002, 01:41 AM
-
By Ryan Small in forum VB Classic
Replies: 4
Last Post: 06-08-2001, 05:11 AM
-
By Ryan Small in forum VB Classic
Replies: 0
Last Post: 06-06-2001, 04:21 PM
-
By TC in forum VB Classic
Replies: 8
Last Post: 09-26-2000, 02:34 AM
-
By TC in forum VB Classic
Replies: 0
Last Post: 09-25-2000, 09:06 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks