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









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
layout manager
layout manager  how to use Absolute Layout manager in java form
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
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
Border Layout
Border Layout  which containers use a border Layout as their default layout
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... that downloads and includes  com.imsweb - layout version 1.3.3 java library
Maven dependency for com.imsweb - layout version 5.0 is released. Learn to use layout version 5.0 in Maven based Java projects
- layout version 5.0 ) in their Java project if it is based on Maven and Gradle...; com.imsweb - layout version 5.0 in Java projects. Follow the step by step... and includes  com.imsweb - layout version 5.0 java library in your project
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... and includes  com.imsweb - layout version 4.8 java library in your project
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... and includes  com.imsweb - layout version 4.7 java library in your project
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... and includes  com.imsweb - layout version 4.6 java library in your project
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... and includes  com.imsweb - layout version 4.2 java library in your project
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... and includes  com.imsweb - layout version 3.0 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... that downloads and includes  com.imsweb - layout version 1.25 java library in your
Maven dependency for com.imsweb - layout version 4.0 is released. Learn to use layout version 4.0 in Maven based Java projects
- layout version 4.0 ) in their Java project if it is based on Maven and Gradle...; com.imsweb - layout version 4.0 in Java projects. Follow the step by step... and includes  com.imsweb - layout version 4.0 java library in your project
Maven dependency for com.imsweb - layout version 1.18 is released. Learn to use layout version 1.18 in Maven based Java projects
( com.imsweb - layout version 1.18 ) in their Java project if it is based on Maven... to use  com.imsweb - layout version 1.18 in Java projects. Follow the step...Maven dependency for  com.imsweb  - Version 1.18 of layout released
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 4.9 is released. Learn to use layout version 4.9 in Maven based Java projects
- layout version 4.9 ) in their Java project if it is based on Maven and Gradle...; com.imsweb - layout version 4.9 in Java projects. Follow the step by step... and includes  com.imsweb - layout version 4.9 java library in your project
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... and includes  com.imsweb - layout version 4.5 java library in your project
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... and includes  com.imsweb - layout version 4.4 java library in your project
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... and includes  com.imsweb - layout version 4.3 java library in your project
Maven dependency for com.imsweb - layout version 4.10 is released. Learn to use layout version 4.10 in Maven based Java projects
- layout version 4.10 ) in their Java project if it is based on Maven and Gradle...; com.imsweb - layout version 4.10 in Java projects. Follow the step by step... that downloads and includes  com.imsweb - layout version 4.10 java library in your
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... and includes  com.imsweb - layout version 4.1 java library in your project
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... and includes  com.imsweb - layout version 3.1 java library in your project
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... and includes  com.imsweb - layout version 2.1 java library in your project
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... and includes  com.imsweb - layout version 2.0 java library in your project
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
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
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... and includes  com.alexvasilkov - foldable-layout version 1.2.1 java library...-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... and includes  com.alexvasilkov - foldable-layout version 1.0.3 java library...-layout released The developers of   com.alexvasilkov - foldable
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...; com.alexvasilkov - foldable-layout version 0.1 java library in your project. ADS...-layout released The developers of   com.alexvasilkov - foldable-layout
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... and includes  com.alexvasilkov - foldable-layout version 1.2.0 java library...-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... and includes  com.alexvasilkov - foldable-layout version 1.1.0 java library...-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... and includes  com.alexvasilkov - foldable-layout version 1.0.2 java library...-layout released The developers of   com.alexvasilkov - foldable
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... and includes  com.alexvasilkov - foldable-layout version 1.0.1 java library...-layout released The developers of   com.alexvasilkov - foldable
Maven dependency for com.cleveroad - bubbleanimation-layout version 1.0.0 is released. Learn to use bubbleanimation-layout version 1.0.0 in Maven based Java projects
-layout version 1.0.0 ) in their Java project if it is based on Maven and Gradle...-layout version 1.0.0 java library in your project. ADS_TO_REPLACE_2 Now you can... of bubbleanimation-layout released The developers of   com.cleveroad
Maven dependency for com.cleveroad - fan-layout-manager version 1.0.4 is released. Learn to use fan-layout-manager version 1.0.4 in Maven based Java projects
; com.cleveroad - fan-layout-manager version 1.0.4 in Java projects. Follow... and includes  com.cleveroad - fan-layout-manager version 1.0.4 java library in your...Maven dependency for  com.cleveroad  - Version 1.0.4 of fan-layout
Maven dependency for com.cleveroad - fan-layout-manager version 1.0.1 is released. Learn to use fan-layout-manager version 1.0.1 in Maven based Java projects
; com.cleveroad - fan-layout-manager version 1.0.1 in Java projects. Follow... and includes  com.cleveroad - fan-layout-manager version 1.0.1 java library in your...Maven dependency for  com.cleveroad  - Version 1.0.1 of fan-layout
Maven dependency for com.cleveroad - fan-layout-manager version 1.0.5 is released. Learn to use fan-layout-manager version 1.0.5 in Maven based Java projects
; com.cleveroad - fan-layout-manager version 1.0.5 in Java projects. Follow... and includes  com.cleveroad - fan-layout-manager version 1.0.5 java library in your...Maven dependency for  com.cleveroad  - Version 1.0.5 of fan-layout
Maven dependency for com.cleveroad - fan-layout-manager version 1.0.3 is released. Learn to use fan-layout-manager version 1.0.3 in Maven based Java projects
; com.cleveroad - fan-layout-manager version 1.0.3 in Java projects. Follow... and includes  com.cleveroad - fan-layout-manager version 1.0.3 java library in your...Maven dependency for  com.cleveroad  - Version 1.0.3 of fan-layout
Maven dependency for com.cleveroad - fan-layout-manager version 1.0.2 is released. Learn to use fan-layout-manager version 1.0.2 in Maven based Java projects
; com.cleveroad - fan-layout-manager version 1.0.2 in Java projects. Follow... and includes  com.cleveroad - fan-layout-manager version 1.0.2 java library in your...Maven dependency for  com.cleveroad  - Version 1.0.2 of fan-layout
Maven dependency for com.cleveroad - fan-layout-manager version 1.0.0 is released. Learn to use fan-layout-manager version 1.0.0 in Maven based Java projects
; com.cleveroad - fan-layout-manager version 1.0.0 in Java projects. Follow... and includes  com.cleveroad - fan-layout-manager version 1.0.0 java library in your...Maven dependency for  com.cleveroad  - Version 1.0.0 of fan-layout

Ads