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

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

Ads









Related Tutorials/Questions & Answers:
java layout
java layout  What is a layout manager
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
Advertisements
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
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
Maven dependency for com.imsweb - layout version 3.2 is released. Learn to use layout version 3.2 in Maven based Java projects
- layout version 3.2 ) in their Java project if it is based on Maven and Gradle...; com.imsweb - layout version 3.2 in Java projects. Follow the step by step...; com.imsweb - layout version 3.2 java library in your project. Now you can
Maven dependency for com.imsweb - layout version 3.3 is released. Learn to use layout version 3.3 in Maven based Java projects
- layout version 3.3 ) in their Java project if it is based on Maven and Gradle...; com.imsweb - layout version 3.3 in Java projects. Follow the step by step...; com.imsweb - layout version 3.3 java library in your project. Now you can
Maven dependency for com.imsweb - layout version 3.4 is released. Learn to use layout version 3.4 in Maven based Java projects
- layout version 3.4 ) in their Java project if it is based on Maven and Gradle...; com.imsweb - layout version 3.4 in Java projects. Follow the step by step...; com.imsweb - layout version 3.4 java library in your project. Now you can
Maven dependency for com.imsweb - layout version 2.0 is released. Learn to use layout version 2.0 in Maven based Java projects
- layout version 2.0 ) in their Java project if it is based on Maven and Gradle...; com.imsweb - layout version 2.0 in Java projects. Follow the step by step...; com.imsweb - layout version 2.0 java library in your project. Now you can
Maven dependency for com.imsweb - layout version 2.1 is released. Learn to use layout version 2.1 in Maven based Java projects
- layout version 2.1 ) in their Java project if it is based on Maven and Gradle...; com.imsweb - layout version 2.1 in Java projects. Follow the step by step...; com.imsweb - layout version 2.1 java library in your project. Now you can
Maven dependency for com.imsweb - layout version 3.1 is released. Learn to use layout version 3.1 in Maven based Java projects
- layout version 3.1 ) in their Java project if it is based on Maven and Gradle...; com.imsweb - layout version 3.1 in Java projects. Follow the step by step...; com.imsweb - layout version 3.1 java library in your project. Now you can
Maven dependency for com.imsweb - layout version 4.1 is released. Learn to use layout version 4.1 in Maven based Java projects
- layout version 4.1 ) in their Java project if it is based on Maven and Gradle...; com.imsweb - layout version 4.1 in Java projects. Follow the step by step...; com.imsweb - layout version 4.1 java library in your project. Now you can
Maven dependency for com.imsweb - layout version 4.2 is released. Learn to use layout version 4.2 in Maven based Java projects
- layout version 4.2 ) in their Java project if it is based on Maven and Gradle...; com.imsweb - layout version 4.2 in Java projects. Follow the step by step...; com.imsweb - layout version 4.2 java library in your project. Now you can
Maven dependency for com.imsweb - layout version 4.4 is released. Learn to use layout version 4.4 in Maven based Java projects
- layout version 4.4 ) in their Java project if it is based on Maven and Gradle...; com.imsweb - layout version 4.4 in Java projects. Follow the step by step...; com.imsweb - layout version 4.4 java library in your project. Now you can
Maven dependency for com.imsweb - layout version 4.5 is released. Learn to use layout version 4.5 in Maven based Java projects
- layout version 4.5 ) in their Java project if it is based on Maven and Gradle...; com.imsweb - layout version 4.5 in Java projects. Follow the step by step...; com.imsweb - layout version 4.5 java library in your project. Now you can
Maven dependency for com.imsweb - layout version 4.7 is released. Learn to use layout version 4.7 in Maven based Java projects
- layout version 4.7 ) in their Java project if it is based on Maven and Gradle...; com.imsweb - layout version 4.7 in Java projects. Follow the step by step...; com.imsweb - layout version 4.7 java library in your project. Now you can
Maven dependency for com.imsweb - layout version 4.8 is released. Learn to use layout version 4.8 in Maven based Java projects
- layout version 4.8 ) in their Java project if it is based on Maven and Gradle...; com.imsweb - layout version 4.8 in Java projects. Follow the step by step...; com.imsweb - layout version 4.8 java library in your project. Now you can
Maven dependency for com.imsweb - layout version 1.3.3 is released. Learn to use layout version 1.3.3 in Maven based Java projects
- layout version 1.3.3 ) in their Java project if it is based on Maven... to use  com.imsweb - layout version 1.3.3 in Java projects. Follow the step... and includes  com.imsweb - layout version 1.3.3 java library in your project
Maven dependency for com.imsweb - layout version 1.25 is released. Learn to use layout version 1.25 in Maven based Java projects
- layout version 1.25 ) in their Java project if it is based on Maven and Gradle...; com.imsweb - layout version 1.25 in Java projects. Follow the step by step... and includes  com.imsweb - layout version 1.25 java library in your project. Now
Maven dependency for com.imsweb - layout version 3.0 is released. Learn to use layout version 3.0 in Maven based Java projects
- layout version 3.0 ) in their Java project if it is based on Maven and Gradle...; com.imsweb - layout version 3.0 in Java projects. Follow the step by step...; com.imsweb - layout version 3.0 java library in your project. Now you can
Maven dependency for com.imsweb - layout version 4.3 is released. Learn to use layout version 4.3 in Maven based Java projects
- layout version 4.3 ) in their Java project if it is based on Maven and Gradle...; com.imsweb - layout version 4.3 in Java projects. Follow the step by step...; com.imsweb - layout version 4.3 java library in your project. Now you can
Maven dependency for com.imsweb - layout version 4.6 is released. Learn to use layout version 4.6 in Maven based Java projects
- layout version 4.6 ) in their Java project if it is based on Maven and Gradle...; com.imsweb - layout version 4.6 in Java projects. Follow the step by step...; com.imsweb - layout version 4.6 java library in your project. Now you can
Maven dependency for com.alexvasilkov - foldable-layout version 0.1 is released. Learn to use foldable-layout version 0.1 in Maven based Java projects
; com.alexvasilkov - foldable-layout version 0.1 in Java projects. Follow the step... - foldable-layout version 0.1 java library in your project. Now you can save...-layout released The developers of   com.alexvasilkov - foldable-layout
Maven dependency for com.alexvasilkov - foldable-layout version 1.0.1 is released. Learn to use foldable-layout version 1.0.1 in Maven based Java projects
; com.alexvasilkov - foldable-layout version 1.0.1 in Java projects. Follow...; com.alexvasilkov - foldable-layout version 1.0.1 java library in your project...-layout released The developers of   com.alexvasilkov - foldable
Maven dependency for com.alexvasilkov - foldable-layout version 1.0.2 is released. Learn to use foldable-layout version 1.0.2 in Maven based Java projects
; com.alexvasilkov - foldable-layout version 1.0.2 in Java projects. Follow...; com.alexvasilkov - foldable-layout version 1.0.2 java library in your project...-layout released The developers of   com.alexvasilkov - foldable
Maven dependency for com.alexvasilkov - foldable-layout version 1.0.3 is released. Learn to use foldable-layout version 1.0.3 in Maven based Java projects
; com.alexvasilkov - foldable-layout version 1.0.3 in Java projects. Follow...; com.alexvasilkov - foldable-layout version 1.0.3 java library in your project...-layout released The developers of   com.alexvasilkov - foldable
Maven dependency for com.alexvasilkov - foldable-layout version 1.1.0 is released. Learn to use foldable-layout version 1.1.0 in Maven based Java projects
; com.alexvasilkov - foldable-layout version 1.1.0 in Java projects. Follow...; com.alexvasilkov - foldable-layout version 1.1.0 java library in your project...-layout released The developers of   com.alexvasilkov - foldable
Maven dependency for com.alexvasilkov - foldable-layout version 1.2.0 is released. Learn to use foldable-layout version 1.2.0 in Maven based Java projects
; com.alexvasilkov - foldable-layout version 1.2.0 in Java projects. Follow...; com.alexvasilkov - foldable-layout version 1.2.0 java library in your project...-layout released The developers of   com.alexvasilkov - foldable
Maven dependency for com.alexvasilkov - foldable-layout version 1.2.1 is released. Learn to use foldable-layout version 1.2.1 in Maven based Java projects
; com.alexvasilkov - foldable-layout version 1.2.1 in Java projects. Follow...; com.alexvasilkov - foldable-layout version 1.2.1 java library in your project...-layout released The developers of   com.alexvasilkov - foldable
Maven dependency for com.prolificinteractive - swipe-action-layout version 0.0.1 is released. Learn to use swipe-action-layout version 0.0.1 in Maven based Java projects
( com.prolificinteractive - swipe-action-layout version 0.0.1 ) in their Java project... - swipe-action-layout version 0.0.1 in Java projects. Follow the step by step... of swipe-action-layout released The developers of  
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
Maven dependency for com.vaadin - vaadin-ordered-layout-flow version 14.5.0 is released. Learn to use vaadin-ordered-layout-flow version 14.5.0 in Maven based Java projects
-layout-flow version 14.5.0 ) in their Java project if it is based on Maven...-layout-flow released The developers of   com.vaadin - vaadin-ordered-layout-flow project have released the latest version of this library on 22 Mar

Ads