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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


anil
java Big
1 Answer(s)      4 years and 5 months ago
Posted in : Java Beginners


Hi

pls observe the following coed:



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();
int n1=0,n3=0;
String n="",n2="",n4="";
JPanel p=new JPanel(new GridLayout(20,200));
setSize(700,500);
Container c=getContentPane(); //Objects add to Container
c.setLayout(null);
if(rs.next()) {
n1=rs.getInt(1);
n2=rs.getString(2);
n=rs.getString(3);
n3=rs.getInt(4);
n4=rs.getString(5);
}
p.add(new JLabel("Emp No: "+Integer.toString(n1)));
p.add(new JLabel("Name: "+n2));
p.add(new JLabel("Password: "+n));
p.add(new JLabel("Salary: "+Integer.toString(n3))) ;
p.add(new JLabel("Address: "+n4));
f.add(p);
f.setVisible(true);
f.pack();
}catch(Exception ae){
ae.printStackTrace();
}
}































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();
}

}






in this code the o/p is coming properly.
My problem is when we click on "reports" button the seprate frame(window) is coming , but the window is size is very very small . I want that a medium screen and the mattter inside the frame is middle the new window


pls help me.

Advertisement
View Answers

July 23, 2010 at 11:19 AM


Hi Friend,

Try the following code:

if(e.getSource()==b){
int sno=Integer.parseInt(t1.getText());
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:access");
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(100,50,100,30);
f.add(new JLabel(Integer.toString(n1))).setBounds(200,50,100,30);
f.add(new JLabel("Name:")).setBounds(100,100,100,30);
f.add(new JLabel(n2)).setBounds(200,100,100,30);
f.add(new JLabel("Password:")).setBounds(100,150,100,30);
f.add(new JLabel(n)).setBounds(200,150,100,30);
f.add(new JLabel("Salary:")).setBounds(100,200,100,30);
f.add(new JLabel(Integer.toString(n3))).setBounds(200,200,100,30) ;
f.add(new JLabel("Address:")).setBounds(100,250,100,30);
f.add(new JLabel(n4)).setBounds(200,250,100,30);
f.setVisible(true);
f.setSize(370,350);
}catch(Exception ae){

}
}

Thanks


Related Tutorials/Questions & Answers:
Reading big file in Java
Reading big file in Java  How to read a big text file in Java program?   Hi, Read the complete tutorial at How to read big file line by line in java? Thanks
java Big - Java Beginners
java Big  Hi pls observe the following coed: import mysql.DataAcc; // import package class for getting database connection import java.sql.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; class
Advertisements
The Big Competition - Java Beginners
The Big Competition  Let the Machine understand you ----------------------------- Each team is asked to implement an application that can execute at least 3 commands ? depend on the operating system that you are working
The Big Competition - Java Beginners
The Big Competition  Let the Machine understand you ----------------------------- Each team is asked to implement an application that can execute at least 3 commands ? depend on the operating system that you are working
The Big Competition - Java Beginners
The Big Competition  Let the Machine understand you ----------------------------- Each team is asked to implement an application that can execute at least 3 commands ? depend on the operating system that you are working
The Big Competition - Java Beginners
The Big Competition  Let the Machine understand you ----------------------------- Each team is asked to implement an application that can execute at least 3 commands ? depend on the operating system that you are working
java program_big digits multiplication..
java program_big digits multiplication..  i want program about big digits multiplication program using java..plz tel me answer
Java Big Problem - Java Beginners
Java Big Problem  Input the current meter reading and the previous meter reading and calculate the electic bill with the following conditions(all... on Java visit to : http://www.roseindia.net/java/ Thanks Vineet
Very Big Problem - Java Beginners
Very Big Problem  Write a 'for' loop to input the current meter reading and the previous meter reading and calculate the electic bill with the following conditions(all must be fulfilled in one class only): (i)if unit(current
Add two big numbers - Java Beginners
Add two big numbers - Java Beginners  Hi, I am beginner in Java and leaned basic concepts of Java. Now I am trying to find example code for adding big numbers in Java. I need basic Java Beginners example. It should easy
How to read big file line by line in java?
Learn how to write a program in java for reading big text file line by line... to read the big file in your java program. For example you have to process some... is very useful in reading big file line by line in Java. In this tutorial we
My big doubt on java prgmn.. need solution asap
My big doubt on java prgmn.. need solution asap  How do you write prgrm 4 dis : 3% discount is given if payment is made within 30days of purchase. date of purchase and payment entered by user
big doubt
;html> <body> <%@page language="java" import="java.sql.*"%> <%@page language="java" import="java.io.*"%> <
Reading a big file effeciently
Reading a big file effeciently  How to read a large text file quickly without memory error in Java? What is the best method to read a big file very efficiently? Thanks   Hi, Kindly check the program Java Read File
IBM Big data capabilities
IBM Big data capabilities  What are the capabilities of the IBM Big data System?   IBM Big Data Management system provides unlimited capabilities: Here is the brief of the IBM Big Data Management System: Data
JavaScript method big()
JavaScript method big()       This section illustrates you the use of JavaScript method big(). The big() method allows you to display the specified string in a big font. You can see
Add two big numbers
Add two big numbers       In this section, you will learn how to add two big numbers. For adding two numbers implement two big decimal numbers then apply the Sum() method
Why Big Data is important for Enterprises?
Why Enterprises are looking for Big Data? What are the importance of Big Data in enterprises? In this article we will understand the importance of Big Data and see the benefits of Big Data for enterprises. The Big Data software system
can i use big query in hibernate?
can i use big query in hibernate?  can i use big query in hibernate
What is Big Data?
The Big data is a term used for the massive data set which very difficult.... This article is discussing about the Big data. An Example of Big Data... structured and most of the cases it is incomplete. By many Big Data
Prepared Statement Set Big Decimal
Prepared Statement Set Big Decimal   ... the big decimal and how can be set it in the database table by using the PreparedStatement interface of java.sql package. But here arises a question, what is big
10 Unusual Technologies to Come in a Big Way
10 Unusual Technologies to Come in a Big Way To predict future, especially... in a big way in the time to come. From 3D printing to, controlling brain impulses... on the 10 unusual technologies to come in a big way. Telepresence Robot
LTO 6: Your Next Big Boost to Data Storage
of that. There are great array of reasons to call LTO 6 your next big boost to data... of the prominent aspects of LTO 6, your next big boost data storage. Bigger and smarter... for IT servers for number of reasons. Faster and smoother LTO 6, your next big
Basic Java programming for Beginners
Basic Java programming for Beginners helps them to learn the fundamentals of the language easily and quickly. Java is an Object Oriented Programming language... the world from small to big businesses. It would be safe to say that wherever
Custom Java Software Application Development Solutions
Custom Java Software Application Development Java Application Programming Services The utility of Java based custom software application development has received a big boost with increase in global computer technologies
Java Developers Desk-EJB 3.0
Java Developers Desk-EJB 3.0         Migrating to EJB 3.0 is a big step towards simplifying the process of developing EJBs, which reduces lots of complexities, time and cost
The Open Source World is a Big Part of PHP
of different forms of technology. The big reason for this comes from how PHP is an open... with others. The big benefit of this is that it is free to use.... It can also work with other types of client side scripts like the Java script
graphics - Java Beginners
graphics  In java-graphics.. I want to draw a rectangle and resize that rectangle(small,big) ..by using mouse cursors
Java
Java  I have a big problem i have to convert excel file into data base through java?? so please suggest me java code.   Please visit the following links: http://www.roseindia.net/tutorial/java/poi
Java
Java  I have a big problem i have to convert excel file into data base through java?? so please suggest me java code.   Please visit the following links: http://www.roseindia.net/tutorial/java/poi
Need to create a java applet
Need to create a java applet   Hi people i need to create a java applet for which there will be 2 buttons to indicate small and big. I need to make a circle. When i click small the circle should be small and when i click big
Advertisements
 

 

 

DMCA.com