Showing posts with label swings. Show all posts
Showing posts with label swings. Show all posts

Tuesday 4 December 2012

JComboBox in Swings

// siddhu vydyabhushana // 2 comments


jcombobox in swings

Hi ,this is siddhu vydyabhushana am going to explain about JComboBox in swings.It is one of the component in swings which gives you to select one from group but it was purely different from JRadioButton.It will provide dropdown for u ,we will take Items in string and put it into the JComboBox.

EventHandling
change in any state of object we known as event.
state changes will done by below function..........




JComboBox j;
j.addItemListener(new ItemListener()
{
public void ItemStateChanged(ItemEvent e)
{
//data what you want
}
});


jcombobox in swings

EXAMPLE:

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

//class name combo
public class combo
{

//constructor combo
public combo()
{

//we are accessing c1 from within inner layer so need to be declared as final
final JComboBox c1;

//frame
JFrame j=new JFrame();

//JButton
final JButton b=new JButton("what you select?");
String s[]={"javatyro","siddhu","vydyas"};

c1=new JComboBox(s);


c1.setBounds(10,10,150,30);
b.setBounds(10,50,150,30);
j.setSize(200,200);
j.setLayout(null);
j.setVisible(true);

j.add(b);
j.add(c1);
j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  

//Event Handling

b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String str=(String)c1.getSelectedItem();
JOptionPane.showMessageDialog(null,"You select : "+str);  
}
});
}
public static void main(String args[])
{
combo c=new combo();
}
}

OUTPUT SCREENS


jcombobox in swings
Read More

Saturday 1 December 2012

Insert Data into Database using Swings,Applets part-3

// siddhu vydyabhushana // 3 comments
this part-3 is followed by before 2 parts links are

PART-1

http://javatyro.blogspot.in/2012/12/insert-data-into-database-using.html

PART-2

http://javatyro.blogspot.in/2012/12/insert-data-into-database-using_1.html




DOWNLOAD FULL CODING
                                   download

DATABASE

DB




DATABASE CONNECTION WITHOUT DSN

try
{
String database="sample.mdb";//Here database exists in the current directory

//this connection is without DSN
String url="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + database + ";DriverID=22;READONLY=true";

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection(url);
PreparedStatement st=con.prepareStatement("insert into reg(username,password,gender,email) values(?,?,?,?)");
st.setString(1,name);
st.setString(2,pass);
st.setString(3,g);
st.setString(4,email);
st.executeUpdate();
JOptionPane.showMessageDialog(null,"Data is successfully inserted into database.");
}
catch( Exception ex){}
}
Read More

Insert Data into Database using Swings,Applets part-2

// siddhu vydyabhushana // 9 comments
Good evening guys just now i described all functions of java in part 1 .In part-2  am going to give u front end code and explaination..
follow below steps

 PART-1

http://javatyro.blogspot.in/2012/12/insert-data-into-database-using.html


SCREEN SHOT OF MY PROJECT



DOWNLOAD FULL CODING
                                   download



PACKAGES


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

JText Field component in swings used for input fileds

JTextField jt1=new JTextField(20);
JTextField jt2=new JTextField(20);
JTextField jt3=new JTextField(20);
JTextField jt4=new JTextField(20);

JLabel

JLabel jlb1=new JLabel("Username:");
JLabel jlb1=new JLabel("password:");
JLabel jlb1=new JLabel("confirm password:");
JLabel jlb1=new JLabel("email:");

JRadioButton



JRadioButton m, f;
ButtonGroup radio=new ButtonGroup();

 m=new JRadioButton("male");
radio.add(m);//adding item into JFrame

f=new JRadioButton("female");
radio.add(f);//adding item into JFrame

JButton


JButton button=new JButton("Submit");

Adjust  OBJECTS positions in JFrame

name.setBounds(int x,int y,int height,int width);

jlb1.setBounds(40,50,70,30);//adjust label to co-ordinates
jlb2.setBounds(40,90,70,30);//adjust label to co-ordinates
jlb3.setBounds(40,130,70,30);//adjust label to co-ordinates
jlb4.setBounds(40,170,70,30);//adjust label to co-ordinates

jt1.setBounds(130,50,100,30);//adjust JText Field to co-ordinates
jt2.setBounds(130,90,100,30);//adjust JText Field to co-ordinates
jt3.setBounds(130,130,100,30);//adjust JText Field to co-ordinates
jt4.setBounds(130,170,100,30);//adjust JText Field to co-ordinates

m.setBounds(40,210,100,30);//adjust JRadioButton to co-ordinates
f.setBounds(140,210,100,30);//adjust JRadioButton to co-ordinates

button.setBounds(80,250,100,30);//adjust JButton to co-ordinates

ADD OBJECTS TO JFrame

j.add(img1);
j.add(jlb1);
j.add(jt1);
j.add(jlb2);
j.add(jt2);
j.add(jlb3);
j.add(jt3);
j.add(jlb4);
j.add(jt4);
j.add(m);
j.add(f);
j.add(button);
j.add(text);

EVENT HANDLING

button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
//data here
}
});

VALIDATIONS

String name=jt1.getText();
String pass=jt2.getText();
String cpass=jt3.getText();
String email=jt4.getText();
String g=text.getText();

if((name.length()<6)||(name.length()>=15))
{
JOptionPane.showMessageDialog(null,"name field lessthan 15 and greaterthan 6 ");
jt1.setText("");
}
else if(!pass.equals(cpass))
{
JOptionPane.showMessageDialog(null,"password didn't matched");
}
else if(email.length()<10)
{
JOptionPane.showMessageDialog(null,"enter your correct id");
}
else if((m.isSelected()==false)&&(f.isSelected()==false)){
JOptionPane.showMessageDialog(null,"Please select radio button");
}
}

HOW TO POP UP DIALOG


JOptionPane.showMessageDialog(null,"Please select radio button");
Read More

Insert Data into Database using Swings,Applets part-1

// siddhu vydyabhushana // 14 comments
Hi guys this is siddhu vydybhushana. Already i have blog (MY BLOG )but this time i concentrated on java so i create another blog and named JAVATYRO ..!!!!

I used  below topics to complete project

1.Swings
2.AWT
3.JDBC
4.Event Handling

Swings
swing is a part of JFC(java foundation classes).It gives smooth interface than AWT but we need to entire program in java.

JFC
java foundation classes are set of GUI(graphical user interface) components which simplifies the development of desktop applications..

AWT
adstract window toolkit used to develop GUI apps in java we can convert this to web applications also.

WHY EVENT HANDLING?
if we observe any change in state of an object we call it as EVENT . for example button pressing,mouse dragging,dialog showing .........etc
These events are provided by java.awt.event package
it will provide many event classes and listeners




now it is time to discuss about JDBC connection
already in my last post i blogged it please refer the below link to know that

                types-of-jdbc-drivers...

in next part i will go through on coding dont miss it ..

PART-2































Read More