Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


sunil kumar pandey
java swings
2 Answer(s)      4 years and 6 months ago
Posted in : Java Beginners


When we click on the button , than open a frame, How to create a link on button to frame ,
example :

Suppose I Have to create a login page and on login page there are three button like login, reset, and register. If user is new than click on the register button , when he click on the register button than open a new frame for ditailes of users ,plz tell me how to create a link?

Advertisement
View Answers

January 27, 2010 at 11:16 AM


Hi Friend,

Try the following code:

1)LoginDemo.java:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
class LoginDemo extends JFrame{
JButton SUBMIT,ADD;
JPanel panel;
JLabel label1,label2;
final JTextField text1;
final JPasswordField text2;
LoginDemo(){
label1 = new JLabel();
label1.setText("UserName:");
text1 = new JTextField(15);
label2 = new JLabel();
label2.setText("Password:");
text2 = new JPasswordField(15);
SUBMIT=new JButton("Login");
ADD=new JButton("Create Account");
panel=new JPanel(new GridLayout(4,2));
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(SUBMIT);
panel.add(ADD);
add(panel,BorderLayout.CENTER);
SUBMIT.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
String value1=text1.getText();
String value2=text2.getText();
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "test";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "root";
String user1="";
String pass1="";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db, user, pass);
Statement st = con.createStatement();
ResultSet res = st.executeQuery("SELECT * FROM login where username='"+value1+"' && password='"+value2+"'");
while (res.next()) {
user1 = res.getString("username");
pass1 = res.getString("password");
}
if (value1.equals(user1) && value2.equals(pass1)) {
NextPage page=new NextPage();
page.setVisible(true);
JLabel label = new JLabel("Welcome:"+value1);
page.getContentPane().add(label);
}
else{
JOptionPane.showMessageDialog(null,"Incorrect login or password","Error",JOptionPane.ERROR_MESSAGE);
}
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
});
ADD.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
CreateAccount account=new CreateAccount();
account.setVisible(true);
}
});
}
public static void main(String arg[]) {
LoginDemo frame=new LoginDemo();
frame.pack();
frame.setVisible(true);
}
}


January 27, 2010 at 11:17 AM


continue..

2)CreateAccount.java:

import javax.swing.*;
import java.awt.*;
import java.sql.*;
import java.awt.event.*;
class CreateAccount extends JFrame{
JTextField text1,text2,text3,text4,text5;
JPasswordField pass1;
JLabel label1,label2,label3,label4,label5,label6;
JPanel panel;
JButton button;
CreateAccount() {
text1=new JTextField(15);
text2=new JTextField(15);
text3=new JTextField(15);
pass1=new JPasswordField(15);
text4=new JTextField(15);
text5=new JTextField(15);
label1=new JLabel("First Name");
label2=new JLabel("Last Name");
label3=new JLabel("User Name");
label4=new JLabel("Password");
label5=new JLabel("Address");
label6=new JLabel("Phone No");
button=new JButton("Save");
panel=new JPanel(new GridLayout(7,2));
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(label3);
panel.add(text3);
panel.add(label4);
panel.add(pass1);
panel.add(label5);
panel.add(text4);
panel.add(label6);
panel.add(text5);
panel.add(button);

button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
String value1=text1.getText();
String value2=text2.getText();
String value3=text3.getText();
String value4=pass1.getText();
String value5=text4.getText();
String value6=text5.getText();

Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "test";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "root";
String user1="";
String pass1="";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db, user, pass);
Statement st = con.createStatement();
ResultSet rs=st.executeQuery("Select * from login where username='"+value3+"'");
String usern="";
if(rs.next()){
usern=rs.getString("username");
JOptionPane.showMessageDialog(null,"Invalid UserName");
}
else {

int k=st.executeUpdate("insert into login(firstname,lastname,username,password,address,contactno) values('"+value1+"','"+value2+"','"+value3+"','"+value4+"','"+value5+"','"+value6+"')");
JOptionPane.showMessageDialog(null,"Data is successfully saved");
}

}
catch(Exception e){}
}
});
add(panel);
setSize(300,400);
setVisible(true);
}



}

Thanks


Related Tutorials/Questions & Answers:
Java Swings
Java Swings  I am doing one project on java Swings, in this i have created one jframe where i defined some JButtons and Jcombobox's, here i need to insert one JTable with headers(IN CURRENT JFrame only).pls help me urgently
java swings - Java Beginners
java swings   Do you want to add textfields on the JPanel
Advertisements
java swings - Java Beginners
java swings   Hi, I need the code for click the refresh button then list values will be refresh.Please send the code ........... Thanks, Valarmathi
java swings
java swings  hi... I am having multiple swing forms.. when i click on a button another form is going to opening but it is opening as different form... Now i want it to be open dynamically instead separately.... Is there any
java swings
java swings  Hi, I need a sample code for once click the exit tab the frame window will be closed. Instead of button close i need tab close option.Please send the sample code immediately.......?Its very urgent........ Thanks
java swings
java swings  how can we use the shared locks of dbms in java? I am working on a mini project which is based on the eamcet councilling .i am struck with a problem where if a student select a college and a branch and sees
java swings
java swings  Hi, I have one class file using three panel methods,the three methods is used for three tabs.then how can i set the background image.Please send the sample code for me. I already posted two questions,but i didnt get
java swings
java swings  Hi, I need the sample code for how to set the background image using jframe and also set the jtext field and jlable boxes under the bachground image. Please send the code immediately,its very urgent.Please send me
java code using swings
java code using swings  code that should be able to enter data of student details using all swings into the access database using jdbc connectivity
java swings - Java Beginners
java swings   Hi, I need the code for joptionpane with jcombobox. my requirement is click on add button,one joptionpane will come.from the option pane i need to select the combobox values. Please send the sample code
about swings - Java Beginners
about swings   Dear sir,Good evening, i am doing mca sir,i am doing the project in swings,so plz provide the material about swings sir...: http://www.roseindia.net/java/example/java/swing/ Hope
java swings - Java Beginners
java swings   Hi, I already posted the question for three times.... I have two listboxes.If i select first value in the first listbox and moved to second listbox.The next time the same value will not able to move the first
java swings - Swing AWT
write the code for bar charts using java swings.  Hi friend, I am...java swings  I am doing a project for my company. I need a to show.... http://www.roseindia.net/java/example/java/swing/draw-simple-bar
java swings - Java Beginners
java swings   Hi, I have two classes(two tabbed panes). how can i get the one class jtextfield value into another class method. Please send the code as sson as possible. Thanks, Valarmathi  Hi Friend, Try
java swings - JavaMail
java swings  Hi sir,i am doing a project on swings,i don't have any...://www.roseindia.net/java/example/java/swing/GrideComponents.shtml http://www.roseindia.net/java/example/java/swing/AbsCoordinate.shtml http://www.roseindia.net
java swings - Java Beginners
java swings   Hi, This is my code. How can i set the jtextfield...", Font.BOLD, 12)); javapathname = new JLabel("Java Path"); javatextpath = new JTextField(33); javatextpath.setToolTipText("Java Installation Path
java swings - Java Beginners
java swings   Hi , I have two listboxes.I want to move one listbox... correct the value and send it to me. This is my java code package...,because place the xml file in the c:/ directly and run the java code
java swings - Java Beginners
java swings   hi, I posted the same question two times,but i didnt get the reply. Please change the jframe look and feel type of code.please send the code immediately. This is my code package com.zsl.ibm.mqtool; import
swings - Java Beginners
for this in google, but i got very difficult programs. i am beginner in java swings . i want...); } } For more information, visit the following link: http://www.roseindia.net/java/example/java/swing/ Thanks
java-swings - Java Beginners
java-swings  How to write a program for JTree within a JTable cell in java swings.A table should be displayed when i click on the cell of the table. Please help. Thank u
java swings - Java Beginners
java swings  Hi, I need simple code for JButton JOptionPane.Please send the code. Thanks, Valarmathi
Java-Swings - Java Beginners
Java-Swings  How to set size of JButton depending on it's dynamic caption in java? Here caption is not known at desing time it is geerated at runtime.  Hi friend, Please give in details and full source code where
Java Swings - Java Beginners
Java Swings  hi , I am doing project using netbeans. I have a combobox . I want to add items in that combobox from a method.For this i found... code: http://www.roseindia.net/java/example/java/swing
java swings - Java Beginners
java swings  Hi, I need the code for how to jlistbox value enable disable . please send the code as soon as possible. Please its urgent. Thanks, Valarmathi
java swings - Java Beginners
java swings  Hi, I have two listboxes .Move the one listbox value into another listbox using add button.Move the value one by one into another listbox.Please give the code using jpanel. Thanks, Valarmathi
java swings - Java Beginners
java swings  Hi, I already send the question. But i didnt get the reply. I can't able to set the jfiledialog directory selection in the textbox. Please send the code urgently. Thanks, Valarmathi
Java-Swings - Java Beginners
Java-Swings  How to set the size of a JButton,JLabel depending on it's caption?  Hi, import javax.swing.*; import java.awt....://www.roseindia.net/java/example/java/swing/ Thanks
java swings - Java Beginners
java swings  Hi, I need the code for how can i set the joptionpane color(background and foreground). can i set the delay time for joptionpane display. Please send the code .its urgent. Thanks, Valarmathi
java swings - Java Beginners
java swings  Hi, I have JoptionPane combobox,in the joptionpane jcombobox have array of values. If i select one value from the joptionpane combobox ,then the selected value will be displayed in the listbox. Please send
Java-swings - Java Beginners
Java-swings  How to move JLabels in a Frame  Hi friend, plz specify in detail. I am sending you a text drag code one textarea...); } } ------------------------------------------------- Visit for more information: http://www.roseindia.net/java/example/java
java swings - Java Beginners
java swings  Hi, I need the sample code for bulk of text added using jpanel. I need the code urgent. Please sedn the code as soon as possible. Thanks, Valarmathi   Hi Friend, Do you want to add textfields
java swings - Java Beginners
java swings  Hi, How can i set the color in joptionpane. Please send the code as soon as possible. Thanks, valarmathi  Hi Friend, Try the following code: import java.awt.*; import javax.swing.*; public
SWINGS
SWINGS  WHAT ARE THE DIFFERENCES BETWEEN AWT AND SWINGS
Java Swings - Java Beginners
Java Swings  Hi, I am sending example button program. Please check it and give answer. I have an urgent requuirement with this. //The sample program import javax.swing.*; class ButtonSizeTest extends JFrame { JButton
java swings - Java Beginners
java swings  how to send the data in database using java swing. Example : how to design the registration page using java swing, and how to write the coding to store the data into data base. Plz help........ 
java swings - Java Beginners
java swings  hi, can i set the delay time for joptionpane. I need the sample code. And i need the Refresh jbutton sample code. ie i have two listboxes.I need to move the value from first listbox into second listbox.then
java swings - Java Beginners
java swings  hi, I can't able to set the directory path in the text file. For this code ... import java.awt.*; import java.io.*; import javax.swing.*; import java.awt.event.*; public class UploadPhoto extends
java swings - Java Beginners
java swings  hi, I already send the questions ,but i didnt get the reply. i need joptionpane with jcombobox. please send the sample example code. please send the code immediately. Regards, valar  Hi Friend
java swings - Java Beginners
java swings  Hi , This code is select the filechooser option for file only. I need only for directory like c://jboss5.0 import java.awt.*; import java.io.*; import javax.swing.*; import java.awt.event.*; public
java swings - Java Beginners
java swings  Hi, I already send the same question.Please help me. I cant able to add the directory path in the textbox. This is the code import java.awt.*; import java.io.*; import javax.swing.*; import java.awt.event.
java swings - Java Beginners
java swings  Hi, I need to Pass the two arguments from the joptionpane message dialog . JOptionPane.showMessageDialog(listTransferButton, "Succesfully Migrated the +listvalue Active MQ to IBM MQ", "Migration
java swings - Java Beginners
java swings  Hi, I have two listboxes.If i select first value in the first listbox and moved to second listbox.The next time the same value will not able to move the first list box to second listbox. (duplicate value
java swings - Java Beginners
java swings  Hi, I have two listboxes.If i select first value in the first listbox and moved to second listbox.The next time the same value will not able to move the first list box to second listbox. (duplicate value
java swings - Java Beginners
java swings  Hi, I have two listboxes.I need to move the lisstbox values from one list to another one(ie first listbox to second listbox).I wnat the code for duplicate value no need to move the first listbox into second
java swings - Java Beginners
java swings  Hi, I have two list boxes.From the first listbox i have some value ,i can select the value from the first listbox and it is moved to the second listbox using add button and the value is moved into one by one
java swings - Java Beginners
java swings  hi, I already send the question 4 times. I have two listboxes.If i select first listbox first value moved to second listbox. Second time i select the same value means,i can't able select the value ie., the value
java swings - Java Beginners
java swings  Hi, I have joptionpane inputmessage combobox . but hoew can i select the particular value in joptionpane jcombobox. Please send the sample code. This is very urgent.please help me. Thanks, Valarmathi. 
java swings - Java Beginners
java swings  Hi, I need how to get the one class textfield information into another class method. Form the code i have one textfield named as jbosstextpath ,browse the path and set the path information in the textfield
java swings - Java Beginners
java swings  Hi, I need the listbox example. I have two listboxes first one have data then move the data from first listbox to second listbox using add button.This is my code .... package com.zsl.test; import
java swings - Java Beginners
java swings  Hi, I need only directory selection filedialog. This code is only for text file selection ..ie, c:/valar/file.txt or c:/valar/file.pdf,file.html.... but i need c:/valar only import java.awt.*; import
 

 

 

DMCA.com