• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Query about event for refresh button??

 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all friends,
Iam new to swing I prepare one login dialog box using swing and i add one refresh button on that dialog box now i want to give one event on that refresh button so that when user click on refresh button that dialog box should refresh because if user type wrong username or password then they can refresh that dialog box and they can type again just like as html file's refresh button.
below r my codes:-
refresh.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
//what should be the code here
}
});
Regards
Bikash
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Did u mean u want to refresh the TextFields in the dialog box?
If so, assuming the text fields are userTF and passwordTF,
in the actionPerformed() method put the following code:
userTF.setText("");
passwordTF.setText("");

That's it!!
Shashi
 
Bikash Paul
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks for ur reply now it working fine I want to send the userid and password to my servlet on the action event of my submit button for that i try to code like below but it is not sending userid and password to my servlet.Can any one plz guide me how i can do that.

submit.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try{
String userid1;
String password1;
String url="http://127.0.0.1:8080/examples/servlet/loginServlet";
userid1 = userid.getText();
password1 = password.getText();
u = new URL(url+"?name=" +userid1 + "&path=" + password1);
uc = (HttpURLConnection)u.openConnection();
uc.setDoOutput(true);
uc.setDoInput(true);
uc.setUseCaches(false);
uc.setRequestProperty("Content-Type","application/octet-stream");
printout = new DataOutputStream(uc.getOutputStream ());
}catch(Exception ex){System.out.println("Error from actionPerformed :" +
ex.getMessage());}
}
});
Regards
Bikash
 
Shashi Kanta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
uc = (HttpURLConnection)u.openConnection();
I hope uc above is an URLConnection object.
if so change the code to:
uc = u.openConnection(); //no need to type cast
and remove the lines after this line including uc.setRequestProperty()
these lines are needed in case of POST method, in your case, it is GET method.

Shashi
 
Bikash Paul
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have tried as per ur given guide but couldn't slove my problem.My login dialog is not connecting with my servlet.Can u plz tell me where i have done mistake in my code.In my servlet iam getting parameter by :-
String str = req.getParameter("name");
String str1 = req.getParameter("path");
I also tried like below in my loginDialog(swing)& servlet file but couldn't slove my problem:-
String content =userid1+password1;
printout.writeBytes(content);
printout.flush();
printout.close();
Servlet file:-
============
DataInputStream dos =new DataInputStream(req.getInputStream ());
String str = dos.readLine();
out.println(str);
Iam new to swing plz help me to slove my problem.
Regards
Bikash
 
reply
    Bookmark Topic Watch Topic
  • New Topic