Skip to content

Instantly share code, notes, and snippets.

@pulkitnehra
Last active August 13, 2020 15:43
Show Gist options
  • Save pulkitnehra/bf2e5376d64359f874ab3107fe10ee8a to your computer and use it in GitHub Desktop.
Save pulkitnehra/bf2e5376d64359f874ab3107fe10ee8a to your computer and use it in GitHub Desktop.
A simple GUI application for JDBC
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Appv1 extends Conn implements ActionListener{
// all elements must be static for results to display correctly
static JFrame f,j2;
static JTextField t1, t2, t3, t4, t5, t6, t7;
static JLabel pubid, pubname, phno, add, city, state, zip;
static JButton insert, exit, fetch,clear, restart;
static JTable table;
public Driver()
{
// Initializing the elements
f = new JFrame("PUBLISHERS");
pubid = new JLabel("Publishers ID:");
t1 = new JTextField();
pubname = new JLabel("Publishers Name:");
t2 = new JTextField();
phno = new JLabel("Phone Number:");
t3 = new JTextField();
add = new JLabel("Address:");
t4 = new JTextField();
city = new JLabel("City:");
t5 = new JTextField();
state = new JLabel("State:");
t6 = new JTextField();
zip = new JLabel("Zip:");
t7 = new JTextField();
insert = new JButton("Insert");
exit = new JButton("Exit");
fetch = new JButton("Fetch Records");
clear = new JButton("Clear");
restart = new JButton("Restart");
// setting positions and adding background
pubid.setBounds(60, 20, 250, 200);
t1.setBounds(300,110,100,30);
pubname.setBounds(60, 85, 250, 200);
t2.setBounds(300,170,180,30);
phno.setBounds(60, 150, 250, 200);
t3.setBounds(300,230,150,30);
add.setBounds(60, 215, 250, 200);
t4.setBounds(300,300,180,30);
city.setBounds(60, 280, 250, 200);
t5.setBounds(300,370,150,30);
state.setBounds(60, 350, 250, 200);
t6.setBounds(300,440,150,30);
zip.setBounds(60, 420, 250, 200);
t7.setBounds(300,510,150,30);
insert.setBounds(20, 590, 120, 50 );
insert.setBackground(Color.BLACK);
insert.setForeground(Color.WHITE);
fetch.setBounds(170,590,120,50);
fetch.setBackground(Color.BLACK);
fetch.setForeground(Color.WHITE);
clear.setBounds(320, 590, 120, 50 );
clear.setBackground(Color.BLACK);
clear.setForeground(Color.WHITE);
exit.setBounds(460, 590, 120, 50 );
exit.setBackground(Color.BLACK);
exit.setForeground(Color.WHITE);
restart.setBounds(600, 590, 120, 50);
restart.setBackground(Color.BLACK);
restart.setForeground(Color.WHITE);
// Adding all the elemnts onto the frame
f.setBackground(Color.WHITE);
f.add(pubid);
f.add(t1);
f.add(pubname);
f.add(t2);
f.add(phno);
f.add(t3);
f.add(add);
f.add(t4);
f.add(city);
f.add(t5);
f.add(state);
f.add(t6);
f.add(zip);
f.add(t7);
f.add(insert);
f.add(fetch);
f.add(clear);
f.add(exit);
f.add(restart);
f.setBackground(Color.BLACK);
f.setLayout(null);
f.setVisible(true);
f.setSize(800, 800);
// Adding the onclick functionality
insert.addActionListener(this);
exit.addActionListener(this);
fetch.addActionListener(this);
clear.addActionListener(this);
restart.addActionListener(this);
}
// all the functionality events are added here
@Override
public void actionPerformed(ActionEvent e) {
}
public static void main(String[] args) {
// TODO code application logic here
Appv1 a = new Appv1();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment