HarithaAdapa
java desktop
0 Answer(s)      2 years and 10 months ago
Posted in : Java Beginners

Hi,

Iam created a desktop login application using swings.
pls observe the following code:


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;

class LoginDemo{
JButton SUBMIT;
JFrame f;
JLabel label1,label2;
final JTextField text1;
final JPasswordField text2;
LoginDemo(){
f=new JFrame();
f.getContentPane().setLayout(null);
label1 = new JLabel();
label1.setText("UserName:");
label1.setBounds(400,50,100,20);
text1 = new JTextField(25);
text1.setBounds(500,50,100,20);
label2 = new JLabel();
label2.setText("Password:");
label2.setBounds(400,80,100,20);
text2 = new JPasswordField(25);
text2.setBounds(500,80,100,20);
SUBMIT=new JButton("Login");
SUBMIT.setBounds(500,110,100,20);

f.add(label1);
f.add(text1);
f.add(label2);
f.add(text2);
f.add(SUBMIT);
f.setSize(1024,768);
f.setVisible(true);
SUBMIT.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
String value1=text1.getText();
String value2=text2.getText();
String user1="";
String pass1="";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection con = DriverManager.getConnection("jdbc:odbc:msdesktop");
Statement st = con.createStatement();
ResultSet res = st.executeQuery("SELECT * FROM test where Empname='"+value1+"' and Emppassword='"+value2+"'");
while (res.next()) {
user1 = res.getString("Empname");
pass1 = res.getString("Emppassword");
}
if(!value1.equals(user1) && !value2.equals(pass1)) {
JOptionPane.showMessageDialog(null,"Incorrect login or password","Error",JOptionPane.ERROR_MESSAGE);
text1.setText("");
text2.setText("");
}
else if(value1.equals("")){
JOptionPane.showMessageDialog(null,"Please Enter Username");
}
else if(value2.equals("")){
JOptionPane.showMessageDialog(null,"Please Enter Password");
}
else{
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:odbc:msdesktop");
PreparedStatement pstmt = conn.prepareStatement("insert into logininformation(username,logindate,logintime) values(?,?,?)");
pstmt.setString(1, value1);
java.sql.Date sqlDate = new java.sql.Date(new java.util.Date().getTime());
pstmt.setDate(2, sqlDate);
java.sql.Time sqlTime = new java.sql.Time(new java.util.Date().getTime());
pstmt.setTime(3,sqlTime);
/*java.sql.Timestamp sqlDate = new java.sql.Timestamp(new java.util.Date().getTime());
pstmt.setTimestamp(2, sqlDate);*/
pstmt.executeUpdate();
pstmt.close();
conn.close();
JOptionPane.showMessageDialog(null,"Login Successful");
}
catch(Exception ex){}
}
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
});
}
public static void main(String arg[]) {
LoginDemo frame=new LoginDemo();
}
}



and




import mysql.DataAcc;
// import package class for getting database connection
import java.sql.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class D1 extends JFrame implements ActionListener{
//instance variable
String str="";
/* Swing classess */
JLabel l,l1,l2,l3,l4,title,l5,l6;
JTextField t,t1,t2,t3,t4;
JButton b,b1,b2,b3,b4,b5,exit;
JTextArea ta,ta1;
//create new instance of class D1
D1() {
setSize(700,500); //set Frame Size
Container c=getContentPane(); //Objects add to Container
c.setLayout(null);
ta=new JTextArea(30,30);
title=new JLabel("Employee Information");
l1=new JLabel("Employee Number");
l2=new JLabel("Employee Name");
l=new JLabel("Employee Password");
l3=new JLabel("Employee Salary");
l4=new JLabel("Employee Address");
l5=new JLabel("Database Operation's ");
t1=new JTextField(10);
t2=new JTextField(10);
t =new JTextField(10);
t3=new JTextField(10);
t4=new JTextField(10);
b=new JButton("Reports");
b1=new JButton("Insert");
b2=new JButton("Delete");
b3=new JButton("Update");
b4=new JButton("Single");
b5=new JButton("View");
exit=new JButton("Exit");
//set bounds() palce components in a givel dimesions in the Frame
title.setBounds(200,10,150,100);
//components add to Continer
c.add(title);
l1.setBounds(100,40,150,100);
c.add(l1);
l2.setBounds(100,70,150,100);
c.add(l2);
l.setBounds(100,100,150,100);
c.add(l);
l3.setBounds(100,130,150,100);
c.add(l3);
l4.setBounds(100,160,150,100);
c.add(l4);
l5.setBounds(200,230,250,100);
c.add(l5);
t1.setBounds(250,80,150,20);
c.add(t1);
t2.setBounds(250,110,150,20);
c.add(t2);
t.setBounds(250,140,150,20);
c.add(t);
t3.setBounds(250,170,150,20);
c.add(t3);
t4.setBounds(250,210,150,20);
c.add(t4);
//add buttons to the ActionListener Interface
b .addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
exit.addActionListener(this);
b .setBounds(10,240,80,20);
c.add(b);
b1.setBounds(100,240,80,20);
c.add(b1);
b2.setBounds(190,240,80,20);
c.add(b2);
b3.setBounds(280,240,80,20);
c.add(b3);
b4.setBounds(370,240,80,20);
c.add(b4);
b5.setBounds(460,240,80,20);
c.add(b5);
exit.setBounds(550,240,80,20);
c.add(exit);
ta.setBounds(200,300,270,100);
c.add(ta);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
Connection con=null;
DataAcc d=new DataAcc();
if(e.getSource()==b1) {
ta.setText(str);
/*get values from textfields*/
int sno=Integer.parseInt(t1.getText());
String sname=t2.getText();
String spwd =t.getText();
double sal=Double.parseDouble(t3.getText());
String address=t4.getText();
try {
con=d.getConnect();
PreparedStatement pst=con.prepareStatement("insert into test values(?,?,?,?,?)");
pst.setInt(1,sno);
pst.setString(2,sname);
pst.setString(3,spwd);
pst.setDouble(4,sal);
pst.setString(5,address);
int i=pst.executeUpdate();
if(i>0)
l5.setText("Insertion Operation Performed");
else
l5.setText("Insertion Operation Failed");
pst.clearParameters();
/*text field values clear after insertion performed*/
t1.setText("");
t2.setText("");
t.setText("");
t3.setText("");
t4.setText("");
}catch(Exception ae){
ae.printStackTrace();
}
}//Buuton B1 if




if(e.getSource()==b){
int sno=Integer.parseInt(t1.getText());
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:msdesktop");
PreparedStatement pst=con.prepareStatement("select * from test where Empnumber="+sno);
ResultSet rs=pst.executeQuery();
JFrame f=new JFrame();
f.getContentPane().setLayout(null);
int n1=0,n3=0;
String n="",n2="",n4="";
if(rs.next()) {
n1=rs.getInt(1);
n2=rs.getString(2);
n=rs.getString(3);
n3=rs.getInt(4);
n4=rs.getString(5);
}
f.add(new JLabel("Emp No:")).setBounds(400,50,100,30);
f.add(new JLabel(Integer.toString(n1))).setBounds(500,50,100,30);
f.add(new JLabel("Name:")).setBounds(400,100,100,30);
f.add(new JLabel(n2)).setBounds(500,100,100,30);
f.add(new JLabel("Password:")).setBounds(400,150,100,30);
f.add(new JLabel(n)).setBounds(500,150,100,30);
f.add(new JLabel("Salary:")).setBounds(400,200,100,30);
f.add(new JLabel(Integer.toString(n3))).setBounds(500,200,100,30) ;
f.add(new JLabel("Address:")).setBounds(400,250,100,30);
f.add(new JLabel(n4)).setBounds(500,250,100,30);
f.setVisible(true);
f.setSize(1000,1000);
}catch(Exception ae){
ae.printStackTrace();
}
}//Buuton B1 if





if(e.getSource()==b5) {
ta.setText(str);
try {
con=d.getConnect();
PreparedStatement pst=con.prepareStatement("select * from test");
ResultSet rs=pst.executeQuery();
while(rs.next()) {
int n1=rs.getInt(1);
String n2=rs.getString(2);
String n=rs.getString(3);
double n3=rs.getDouble(4);
String n4=rs.getString(5);
/*append all values to the text area by ta.append()*/
ta.append(""+n1+"\t"+n2+"\t"+n+"\t"+n3+"\t"+n4+"\n");
//JOptionPane.showMessageDialog(null,n1+"\n"+n2+"\n"+n3+"\n"+n4);
l5.setText("View test Table Data");
}
}catch(Exception ae){
ae.printStackTrace();
}
}//Button b5 if
if(e.getSource()==b2) {
ta.setText(str);
int sno=Integer.parseInt(t1.getText());
try {
con=d.getConnect();
PreparedStatement pst=con.prepareStatement("delete from test where Empnumber="+sno);
int i=pst.executeUpdate();
if(i>0)
l5.setText("Deletion Operation Performed");
else
l5.setText("Deletion Operation Failed");
pst.clearParameters();
t1.setText("");
t2.setText("");
t.setText("");
t3.setText("");
t4.setText("");
}catch(Exception ae){
ae.printStackTrace();
}
}//Button b2 if
if(e.getSource()==b3) {
ta.setText(str);
int sno=Integer.parseInt(t1.getText());
String sname=t2.getText();
String spwd=t.getText();
double sal=Double.parseDouble(t3.getText());
String address=t4.getText();
try {
con=d.getConnect();
//PreparedStatement pst=con.prepareStatement("update test set sname=?,spwd=?,sal=?,address=? where sno=?");
PreparedStatement pst=con.prepareStatement("update test set Empname=?,Emppassword=?,Empsal=?,Empadd=? where Empnumber=?");
pst.setString(1,sname);
pst.setString(2,spwd);
pst.setDouble(3,sal);
pst.setString(4,address);
pst.setInt(5,sno);
int i=pst.executeUpdate();
if(i>0)
l5.setText("Update Operation Performed");
else
l5.setText("Update Operation Failed");
pst.clearParameters();
t1.setText("");
t2.setText("");
t.setText("");
t3.setText("");
t4.setText("");
}catch(Exception ae){
ae.printStackTrace();
}
}//button b3 if
if(e.getSource()==b4) {
ta.setText(str);
int sno=Integer.parseInt(t1.getText());
try {
con=d.getConnect();
PreparedStatement pst=con.prepareStatement("select * from test where Empnumber="+sno);
ResultSet rs=pst.executeQuery();
if(rs.next()) {
t1.setText(""+rs.getInt(1));
t2.setText(rs.getString(2));
t.setText(rs.getString(3));
t3.setText(""+rs.getDouble(4));
t4.setText(rs.getString(5));
ta.append(t1.getText()+"\n"+t2.getText()+"\n"+t.getText()+"\n"+t3.getText()+"\n"+t4.getText());
l5.setText("Record Avilable with Serial Number : "+sno);
}
else {
l5.setText("No Record Avilable with Serial Number : "+sno);
pst.clearParameters();
t1.setText("");
t2.setText("");
t.setText("");
t3.setText("");
t4.setText("");
}
}catch(Exception ae){
ae.printStackTrace();
}
}//Button b5 if
if(e.getSource()==exit)
System.exit(0);

}
}
class Database {
public static void main(String[] args) {
D1 d=new D1();
}

}




and




package mysql;
import java.sql.*;
import java.io.*;

public class DataAcc
{
public Connection con=null;
public Connection getConnect()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:msdesktop");
System.out.println("Connected");
}
catch(Exception e)
{
System.out.println(e);
}
return con;
}//getConnection

}//class




the o/p is coming properly.
when the valid user in login the name,date,time are stored in the database.

my doubt is if the valid user is login moretimes a day then minimum time among them will be stored into the database remaining will be not stored into the database and also if the valid user is logout moretimes a day then maximum time among them will be stored into the database remaining will be not stored into the database.


pls help me.
View Answers









Related Pages:
java--desktop appilication - JDBC
java--desktop appilication  when class.forName() is called ,,,a class is loaded...once after the class is loaded ..if we call class.forName, it will call the class which is already present.......what to do if we want to load
java desktop - Java Beginners
java desktop  Hi, Iam created a desktop login application using swings. pls observe the following code: import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.sql.*; class LoginDemo{ JButton
java desktop - Java Beginners
java desktop  Hi, Iam created a desktop login application using swings. pls observe the following code: import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.sql.*; class LoginDemo{ JButton
Java Spring Desktop application
Java Spring Desktop application  Hi i am developing a desktop java spring application..It has many Jframes forms and classes...How to close one Jframe from another..Please tell... First jframe package desktopapplication2
DESKTOP SHARING USING JAVA
DESKTOP SHARING USING JAVA  Sir i have the following code for scren capturing it is capturing in png format but when i am sending it over other m/c it is taking delay of around 16 seconds..i think it is because this line of code
Simple Java Desktop Upload application
Simple Java Desktop Upload application  I try do simple example for upload applicationtake file from c:\ put to d:\ :) PLEASE HELP
EasyEclipse Desktop Java
EasyEclipse Desktop Java       EasyEclipse Desktop Java For development of Desktop... - Shared platform services from Eclipse - Getting started. Java JDK
Remote mobile desktop - MobileApplications
Remote mobile desktop  I am doing my research to implement a java mobile application to access another remote mobile phone with the authentication.This application will have to use the service provider's network and a server
Works when run from desktop but....
Works when run from desktop but....  I used the code provided here for a pie chart using swing in Java, and when I saved it to my desktop, it ran fine, and worked as explained, but then I tried to add the same code to NetBeans
Java program to get the desktop Path
Java program to get the desktop Path  ... the desktop path of the system. In the java environment we can get the desktop path also with the system's property. For getting the desktop path we have to add
Create a Desktop Pane Container in Java
Create a Desktop Pane Container in Java   ... pane container in Java. The desktop pane container is a container, which has... under the desktop pane. Following figure shows the JDesktopPane component of Java
path setting for tomcat to java for Desktop PC - JDBC
path setting for tomcat to java for Desktop PC  Hi sir, I want to connect my java programms to Database which of either sql,oracle,mysql... or configuration about the Tomcat Server in Java. Kindly visit them . We hope
Java Spring Desktop application with multiple classes and jframe
Java Spring Desktop application with multiple classes and jframe  Hi i am developing a desktop java spring application..It has many Jframes forms and classes...How to close one Jframe from another..Please tell... First jframe
Google Desktop Search
Google Desktop Search     ... capabilities, this plug-in uses the Google Desktop Search Engine instead. Usage The search can be started from either the Search menu or the Google Desktop
Using the Desktop class to launch a URL
Using the Desktop class to launch a URL with default browser...; Using the Desktop class to launch a URL with default browser in Java  This article describes the new Desktop API
linux desktop on windows without using vn or any other ? - Java Magazine
linux desktop on windows without using vn or any other ?  linux desktop on windows without using vn or any other ?. I have a linux pc and windows xp pc but i am not able to connect the linux pc on windows .why? .windows
desktop application
desktop application  how to transfer data swing text field to browser text field to their corresponding label/caption. please reply as soon as possible. thanks vijay
How can I open my Java desktop app by clicking on its file?
How can I open my Java desktop app by clicking on its file?  How can I open my Java desktop app by clicking on the file it creates? This app creates files when selecting its "Save as" option with an extension specificaly defined
How to launch my web application from my desktop without opening Netbeans IDE everytime i run the application?
How to launch my web application from my desktop without opening Netbeans IDE... is i want to create a shortcut for my webapplication in desktop so... dont want all these steps, so i knw that java application can be launched using
Remote desktop access - JSP-Servlet
Remote desktop access  Hello everyone Thank a lot for all the reply given before i have my 4th question which is about Remote desktop accessing inside the network and also accessing the computer inside domain ...so please
Remote Desktop Services
Remote Desktop Services Formerly known as Terminal Services in Windows Server 2008, the Remote Desktop Services in Windows Server 2008 R2 is Microsoft... computer over a network with the help of Remote Desktop Protocol (RDP
ssl comunication between a desktop application and a web application
ssl comunication between a desktop application and a web application  Hi Lusiano, I am trying to implement a ssl comunication between a desktop application and a web application. can you please share code with me. Please
Java
Java Java is one the programming language suited for the construction of many type of applications. It can be used to develop: Desktop applications... applications Applications for the embedded devices The Java programming language
Remote Desktop Setting in Windows 8
the network by enabling the Remote Desktop Connection in your PC. 1. To configure 'Remote Desktop Connection' on your Windows 8 installed PC, first of all... running Remote Desktop with Network Level Authentication (recommended
The JDBC API to access a desktop database like Microsoft Access over the network.
The JDBC API to access a desktop database like Microsoft Access over the network.  How can I use the JDBC API to access a desktop database like Microsoft Access over the network
Java Update
for desktop Java applications. Java 1.4.2 Update 2 also includes all... Java Update       In this section, you will learn java updates.  Java Update 1.4.2 Java 1.4.2
Foresight Desktop Linux 0.9.4 Pre 1 has been released now
Foresight Desktop Linux 0.9.4 Pre 1 has been released now I am please to announce another release of Foresight Desktop Linux. I am also quite proud to say we..... About the Foresight Desktop Linux Forsight Linux is a distribution based
Problem in setting IP address for a JFrame Class Desktop Application
Problem in setting IP address for a JFrame Class Desktop Application  I have designed a browser for our final year project, it is working well. But when we put it in a system which has a proxy setting for internet connection
User-friendly Desktop Internet GIS (UDIG)
User-friendly Desktop Internet GIS (UDIG)       The User-friendly Desktop Internet GIS (uDig) is both a GeoSpatial application and a platform through which
FoX Desktop 1.0 Professional has been released
FoX Desktop 1.0 Professional has been released Desktop enhancements... Desktop FoX Linux is a single-CD desktop-oriented Linux distribution based on Fedora Core, with KDE as its preferred desktop, main components recompiled
Others Frameworks
(XIOS/3) The initial Beta launch of XIOS/3 consists of the OS, a user desktop... because it is technology agnostic it can be encapsulated in Java/JSP/JSF.  ... PHP, ASP, dotNET and Java.   
i want to create an icon on my desktop... with this i want to open my web application
i want to create an icon on my desktop... with this i want to open my web application  i want to create an icon on my desktop... with this i want to open my web application(automatically run my server... )how
AWT basics
, graphics, and user-interface for the desktop application using Java technology
Rich Internet Application
of traditional desktop applications, it means Rich Internet Applications are a cross between web applications and traditional desktop applications that shift some... system without using unified client-side solution. Ajax, the advance tool of Java
java
java  hi all i have a problem ,i want to sotre form data in table with foreign key in java ,please help me  Hi,Are you developing desktop or JSP application?Thanks
Cross-platform programming with Java technology and the IBM Web Services Toolkit for Mobile Devices
;   When you?re writing a Java application for the server or desktop, you can be reasonably sure that the Java platform...Cross-platform programming with Java technology and the IBM Web
Hardware Requirement for Linux.
Hardware Requirement for Linux. For Installing Linux Server/ Desktop Operating System, it need a specific configuration of hardware platform. The hardware... including Java, Apache, Eclipse and Java Applications software. At least 5
eLaunch
, Java VM, and plugin sets. This leads to clutter on the desktop and makes... a number of desktop icons for running various copies of Eclipse using different.... Drag and drop import of existing Eclipse desktop shortcuts. Export
java
java  hi..i have developed a desktop application and i want it to run in other computers also which are connected through LAN.is it possible to do so??all the database must be in master computer only and all other computer must
The Ultima Linux 8 has been released
desktop or an industrial-strength server. It packs in over 350 unique packages, including the famous KDE desktop, Enlightenment window manager, Firefox... your favorite apps and an eye-catching new desktop right out of the box
The Ultima Linux 8 has been released
desktop or an industrial-strength server. It packs in over 350 unique packages, including the famous KDE desktop, Enlightenment window manager, Firefox... your favorite apps and an eye-catching new desktop right out of the box
Java Remote Machines - Java Beginners
Java Remote Machines  How to get the Physical path of virtual Directories created in IIS using the Java Desktop Applications? Any one please help... Machine using Java Desktop Applications
java
language. VB6 was only considered good for desktop windows application. In VB.NET, you
java swing and CSS
java swing and CSS  can css be used in java swing desktop application in different forms for better styles?plzz help
Purefect
is a free Web Desktop (a.k.a WebOS). In order to use Purefect, you have to login to your web-based desktop first. Then you can choose and run applications the same way you run applications on your desktop. Read full Description
RIA Development Company
desktop applications with enhanced user interface. RIAs are very much different... are developed using PHP, AJAX, JAVA, JavaScript, MS ActiveX Control, Curl and Google... and Java. Our developed products offer extensive solutions to your business
single frame coding in java
single frame coding in java  sir, i am a beginner in java.i want to do a desktop application in java in which a single frame satisfies all needs.but... in a desktop application is quite boaring
Applications of Java
Applications of Java  Hi, What are the Applications of Java in development of enterprise applications? Thanks   Hi, You can use java to develop various kinds of Java applications for: a) Desktop b) Websites c
java coding
java coding  i am using netbean to my project and it is Desktop Application.i want my textfield to accept only numbers or only alphabets .........plez plez plez do help me..........i am just beginner to java codes

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.