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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


santosh satnami
java Layout
1 Answer(s)      3 years and 10 months ago
Posted in : Java Beginners


sir i want a program of all the layout of java which have two or three button and a database connectivity


Advertisement
View Answers

January 6, 2011 at 11:57 AM


Hi Friend,

Try the following code:

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

class LayoutExample extends JFrame{
    JPanel panel,panel1,panel2;
    JLabel lab1,lab2;
    JTextField text1,text2;
    JButton b1,b2,b3;

    LayoutExample(){
        panel=new JPanel();
        panel1=new JPanel(new GridLayout(2,2));
        panel2=new JPanel(new FlowLayout());

        lab1=new JLabel("Name");
        lab2=new JLabel("Address");

        text1=new JTextField(20);
        text2=new JTextField(20);

        b1=new JButton("Add");
        b2=new JButton("View");
        b3=new JButton("Delete");

        panel1.add(lab1);
        panel1.add(text1);
        panel1.add(lab2);
        panel1.add(text2);

        panel2.add(b1);
        panel2.add(b2);
        panel2.add(b3);

        panel.add(panel1,BorderLayout.NORTH);
        panel.add(panel2,BorderLayout.SOUTH);

        add(panel);
        setVisible(true);
        setSize(500,150);

        b1.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
            String v1=text1.getText();
            String v2=text2.getText();
            try{
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
            Statement st=con.createStatement();
            int i=st.executeUpdate("insert into data(name,address) values('"+v1+"','"+v2+"')");
            JOptionPane.showMessageDialog(null,"Data is inserted successfully");
            }
            catch(Exception ex){
            }
            }
        });

        b2.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
            String v1=text1.getText();
            String v2=text2.getText();
            JFrame f=new JFrame();
            JLabel l1=new JLabel("Your Name is      : "+v1);
            JLabel l2=new JLabel("Your Address is : "+v2);
            l1.setBounds(20,20,200,20);
            l2.setBounds(20,50,200,20);
            f.setLayout(null);
            f.add(l1);
            f.add(l2);
            f.setVisible(true);
            f.setSize(300,200);
            }
        });

        b3.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
            String v1=text1.getText();
            String v2=text2.getText();
            try{
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
            Statement st=con.createStatement();
            int i=st.executeUpdate("delete from data where name='"+v1+"' and address='"+v2+"'");
            JOptionPane.showMessageDialog(null,"Data is deleted successfully");
            }
            catch(Exception ex){
            }
            }
        });
    }
    public static void main(String[] args) 
    {
        new LayoutExample();
    }
}

Thanks



Related Tutorials/Questions & Answers:
java layout
java layout  What is a layout manager
java layout
java layout  What method is used to specify a container?s layout
Advertisements
java Layout
java Layout  sir i want a program of all the layout of java which have two or three button and a database connectivity
Java layout manager
Java layout manager  Which containers use a FlowLayout as their default layout
Java layout manager
Java layout manager  What advantage do Java's layout managers provide over traditional windowing systems
Java Layout
Java Layout       In java a layout manager class implements the LayoutManager interface. It is used.... Components can provide size and alignment hints, still the container's layout manager has
Layout problem - Java Beginners
Layout problem  How can i place the component without mentioning the layout ?  Use SetBounds for the components and set the layout as null
Java Swing Card Layout
Java Swing Card Layout Java technology uses Layout Managers to define... types of Layout Managers which implements the LayoutManager interface... layout manager. Multiple components on card can be added but at a time only one
layout manager
layout manager  how to use Absolute Layout manager in java form
Create Layout Components in a Grid in Java
Create Layout Components in a Grid in Java   ... layout components with the help of grid in Java Swing. The grid layout provides... layout arranges components by dividing areas into rows and columns. This program
viewing the ms word in print layout from jsp - Java Beginners
viewing the ms word in print layout from jsp  Hi all, I am trying to export ms word from jsp in print layout format.I used the code for converting into ms word but it is opening in web layout. My requirement
Border Layout
Border Layout  which containers use a border Layout as their default layout
tables for layout
tables for layout  Are there any problems with using tables for layout
tables for layout
tables for layout  Are there any problems with using tables for layout
Layout Manager
Layout Manager  for compile file "Javac SApplet.java" (working fine) but, java SApplet (not compile) error message: Exception in thread "main" java.lang.NoSuchMethodError:main Please follow the program import
general layout HTML documents
general layout HTML documents  Explain the general layout HTML documents
HTML Layout
HTML Layout       A Web Page Layout is likey to be the layout of the pages... columns are created by using tables to design the layout. This can be done
Layout manager in flex
Layout manager in flex  Hi.... What is Layout Manager and explain the Properties and Methods? Now let's know how we will use these properties and methods........ Thanks
HTML table layout
HTML table layout  i have table layout in that i have menu in td...(column) ,plz give me code and give me useful layout examples,because my requirement is layout using table
Struts Layout Examples - Struts
Struts Layout Examples  Hi, Iam trying to create tabbed pages using the struts layout tag. I see the tab names on the page but they cannot be clicked on. Im not able to find simple examples/explanation on it. Any help
VDividedBox layout container
VDividedBox layout container       VDividedBox Layout Container is similar to VBox Layout Container. The difference is, it adds a divider between its child components which can be used
DividedBox layout container
DividedBox layout container       DividedBox Layout Container is similar to Box Layout Container. The difference is, it adds a divider between its child components which can be used
HDividedBox layout container
HDividedBox layout container       HDividedBox Layout Container is similar to HBox Layout Container. The difference is, it adds a divider between its child components which can be used
Struts-Layout
Struts-Layout       Struts-Layout is a tag library for Apache Struts which provides easy and fast interface creation. This is achieved by powerful tags which display panels, input fields
Visibal Certical scrollbar with struts collection layout.
Visibal Certical scrollbar with struts collection layout.  how to Visibal Vertical scroll bar with struts collection layout
Form Layout Container in Flex4
Form Layout Container in Flex4: The Form Layout container is a MX container. There is no Spark equivalent. Flex uses the Form Layout container for making a Form. The Form container controls the layout of form, required field option
VBox Layout Container
VBox Layout Container       VBox layout container is just like Box container with vertical direction..." layout="absolute"> <mx:VBox width="104
HBox Layout Container
HBox Layout Container       HBox layout container behaves like Box container with horizontal direction.../2006/mxml" layout="absolute"> <mx:HBox width="
Canvas Layout Container in Flex4
Canvas Layout Container in Flex4: The Canvas layout Container is used... or controls. The Canvas layout Container is a MX component. There is no spark component. You can use absolute layout of position of child components. The tag
opening node in treeview struts layout - Struts
opening node in treeview struts layout  Example of opening node in treeview struts layoutopening node in treeview struts layout Hello every one, i am new to this group , i am having the same problem , Struts Layout tree view
Advertisements
 

 

 

DMCA.com