Results 1 to 5 of 5
- 12-18-2009, 08:47 AM #1
Member
- Join Date
- Dec 2009
- Posts
- 2
- Rep Power
- 0
How to pass user-id between .java programs
Hi,
Can any one help to get rid of this problem.
I have login.java, admin_menu.java and user_menu.java classes.
When user starts the application login.java is invoked and the user get appropriate menu like admin_menu.java or user_menu.java.
I have added an option to change password in admin_menu.java and user_menu.java.
How to pass user-id from login.java to admin_menu.java and user_menu.java
after successful login.
Any idea , please help.
- 12-18-2009, 03:36 PM #2
Senior Member
- Join Date
- Aug 2009
- Location
- Pittsburgh, PA
- Posts
- 284
- Rep Power
- 4
Information can be passed from one class to anotherlogin.java is invoked and the user get appropriate menu like ...
via a method call, a command line string, or through a file.
It all depends on how control is passed from login.java to the menu.
Let's assume you are making a new admin_menu or user_menu.
I recommend creating another class of object just to keep the userId
and other global information. The login class creates one of these
communication objects and passes it to any children.
Children can then access the global data from the object.
- 12-22-2009, 08:19 AM #3
Member
- Join Date
- Dec 2009
- Posts
- 2
- Rep Power
- 0
Thank you.
If it is possible , can you please give and example (very small).
sothat I can incorporate the same idea. Now I have login program. I am listing it here. Kindly show what should be done to pass the use_id to
adm_menu.java and clk_menu.java.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.io.*;
import java.sql.*;
import java.util.*;
import MyPack.*;
public class bislogin extends JFrame
{
JLabel jl1,jl2,jl3,jl4;
JTextField jt1;
JPasswordField jpf1;
JButton jb1;
JPanel top,mid,bot;
Connection con = null;
public amlogin()
{
setTitle("Login To System");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container pane = getContentPane();
JPanel top = new JPanel();
JLabel Title = new JLabel("AM Information system");
Title.setFont(new Font("TimesRoman",Font.BOLD,25));
Title.setForeground(new Color(254,255,232));
top.setBackground(new Color(151,51,2));
top.setPreferredSize(new Dimension(500,50));
top.setMinimumSize(new Dimension(500,25));
top.setMaximumSize(new Dimension(500,25));
top.add(Title);
pane.add("North",top);
JPanel mid = new JPanel();
mid.setLayout(null);
mid.setBackground(new Color(251,206,198));
mid.setBorder(new EmptyBorder(new Insets(20,20,20,20)));
mid.setPreferredSize(new Dimension(500,80));
mid.setMinimumSize(new Dimension(500,80));
mid.setMaximumSize(new Dimension(500,80));
pane.add("Center", mid);
jl1 = new JLabel("UserName");
jl1.setHorizontalAlignment(SwingConstants.LEFT);
jl1.setForeground(new Color(0,0,255));
jl2 = new JLabel("Password");
jl2.setHorizontalAlignment(SwingConstants.LEFT);
jl2.setForeground(new Color(0,0,255));
jl3 = new JLabel("Enter Username and Password To Login");
jl3.setHorizontalAlignment(SwingConstants.LEFT);
jl3.setForeground(new Color(0,0,255));
jl4 = new JLabel("BIS System Project is Developed for the Completion of IGNOU MCA");
jl4.setForeground(new Color(254,255,232));
jt1 =new JTextField();
jt1.setForeground(new Color(0, 0, 255));
jt1.setSelectedTextColor(new Color(0, 0, 255));
jt1.setToolTipText("Enter your Username");
jt1.addKeyListener(new KeyAdapter()
{
public void keyReleased(KeyEvent e)
{
JTextField textField = (JTextField) e.getSource();
String text = textField.getText();
textField.setText(text.toLowerCase());
}
});
jt1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
// jt1_actionPerformed(e);
}
});
jpf1 = new JPasswordField();
jpf1.setForeground(new Color(0, 0, 255));
jpf1.setSelectedTextColor(new Color(0, 0, 255));
jpf1.setToolTipText("Enter your Password");
jpf1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
//jpf1_actionPerformed(e);
}
});
jb1 = new JButton();
jb1.setBackground(new Color(204, 204, 204));
jb1.setForeground(new Color(0, 0, 255));
jb1.setText("Login");
jb1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String username = new String(jt1.getText());
String password = new String(jpf1.getText());
String uid="";
String pwd="";
String rol="";
if(username.equals("") || password.equals(""))
{
jb1.setEnabled(false);
JLabel errorFields = new JLabel("<HTML><FONT COLOR = Blue> "+
" You must enter a username and password to login.</FONT></HTML>");
JOptionPane.showMessageDialog(null,errorFields);
jt1.setText("");
jpf1.setText("");
jb1.setEnabled(true);
}
else
{
try
{
con = db_connect.getConnection();
String sql1 = "select user_id,user_pass,user_role from user_dir where "+
"user_id=?";
PreparedStatement ps1= con.prepareStatement(sql1);
ps1.setString(1,jt1.getText());
ResultSet prs1 = ps1.executeQuery();
while (prs1.next())
{
uid = prs1.getString(1);
pwd = prs1.getString(2);
rol = prs1.getString(3);
}
prs1.close();
ps1.close();
}
catch(Exception e1){e1.printStackTrace();};
if(username.equals(uid) && password.equals(pwd) && rol.equals("ADM"))
{
jb1.setEnabled(false);
jt1.setText(null);
jpf1.setText(null);
new admin_menu();
}
else if(username.equals(uid) && password.equals(pwd) && rol.equals("CLK"))
{
jb1.setEnabled(false);
jt1.setText(null);
jpf1.setText(null);
new clk_menu();
}
else
{
JOptionPane.showMessageDialog(null,"Login Failed !!!!"+
" Enter Proper Username/Password");
jt1.setText(null);
jpf1.setText(null);
}
}
}
});
jl1.setBounds(50,100,106,18);
jl2.setBounds(50,125,97,18);
jl3.setBounds(50,50,300,18);
jt1.setBounds(210,100,183,22);
jpf1.setBounds(210,125,183,22);
jb1.setBounds(210,175,83,28);
mid.add(jl1);mid.add(jl2);mid.add(jl3);
mid.add(jt1);mid.add(jpf1);mid.add(jb1);
Graphics g = mid.getGraphics();
JPanel bot = new JPanel();
bot.setPreferredSize(new Dimension(500,50));
bot.setMinimumSize(new Dimension(500,50));
bot.setMaximumSize(new Dimension(500,50));
bot.setBackground(new Color(151,51,2));
pane.add("South",bot);
bot.add("Center", jl4);
pack();
setSize(800,600);
setVisible(true);
setResizable(false);
}
public void paint(Graphics g)
{
super.paint(g);
//g.drawLine(30,30,30,30);
g.drawRect(40,100,700,400);
//g.drawOval(60,400,120,120);
}
public static void main(String[] args)
{
new amlogin();
}
}
- 12-22-2009, 03:58 PM #4
Senior Member
- Join Date
- Aug 2009
- Location
- Pittsburgh, PA
- Posts
- 284
- Rep Power
- 4
Change names to java standard of capitalized words: ClickMenu
Change the constructor of ClickMenu to have an argument.
instead of new clk_menu(), the code becomesJava Code:class ClickMenu { String loginID; ClickMenu(String name) { loginID = name; } ... }
Java Code:new ClickMenu(jt1.getText());
- 12-22-2009, 04:30 PM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I think it's better to read more about methods in java. Start from the suns' tutorial.
Defining Methods (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
Similar Threads
-
[SOLVED] Running java programs from the command prompt
By wiz0r in forum New To JavaReplies: 6Last Post: 04-20-2009, 04:34 AM -
Java Programs to Test Performance
By testarosa in forum Advanced JavaReplies: 4Last Post: 02-27-2009, 01:04 PM -
Running 3 Java programs in sequence.
By loktamu in forum New To JavaReplies: 2Last Post: 11-23-2008, 06:50 PM -
Problem in running java programs
By aravind in forum New To JavaReplies: 0Last Post: 07-14-2008, 11:19 AM -
Execute small java programs through Internet.........is thst possible??
By atanu.dey in forum New To JavaReplies: 1Last Post: 01-05-2008, 07:48 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks