NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package java69;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.DefaultTableModel;

public class MainPage extends JFrame{
JFrame frame = new JFrame();
JLabel label = new JLabel("");

MainPage(String name){
label.setBounds(0,0,198,42);
label.setText("Welcome " + name);
label.setFont(new Font("Times New Roman", Font.PLAIN,26));
frame.add(label);

frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setBounds(400,400,550,500);
frame.setLayout(null);
frame.setVisible(true);

JScrollPane sp = new JScrollPane();
sp.setBounds(10,64,366,107);
frame.add(sp);

JTextField username = new JTextField();
username.setBounds(0,196,198,28);
frame.add(username);

JTextField emaile = new JTextField();
emaile.setBounds(0,226,198,28);
frame.add(emaile);

JTextField ide = new JTextField();
ide.setBounds(0,256,198,28);
frame.add(ide);

try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection
("jdbc:mysql://localhost:3306/cs2a","root","");
Statement stmt = con.createStatement();
String sql = "SELECT * FROM users";
ResultSet rs = stmt.executeQuery(sql);

String[] fcolumn = {"ID","Username","Email"};
DefaultTableModel tableModel = new DefaultTableModel(fcolumn,0);

while(rs.next()) {
String id=String.valueOf(rs.getInt("id"));
String uname = rs.getString("username");
String email = rs.getString("email");
String[] data = {id, uname, email };
tableModel.addRow(data);
}
JTable jt = new JTable(tableModel);
sp.setViewportView(jt);

jt.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent me) {
int row = jt.getSelectedRow();
if(row<0) {
System.out.print("test");
}else {
try {

Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection
("jdbc:mysql://localhost:3306/cs2a","root","");
Statement stmt = con.createStatement();
String id = jt.getValueAt(row, 0).toString();
String sql = "SELECT * FROM users WHERE id=' "+id+" ' ";
ResultSet rs = stmt.executeQuery(sql);
if(rs.next()) {
username.setText(rs.getString("username"));
emaile.setText(rs.getString("email"));
ide.setText(rs.getString("id"));
}
}catch(Exception ex) {System.out.print(ex);}}}});

con.close();

}catch(Exception ex) {System.out.print(ex);}

JLabel lblLoginPage = new JLabel("Book");
lblLoginPage.setHorizontalAlignment(SwingConstants.LEFT);
lblLoginPage.setFont
(new Font("Times New Roman", Font.PLAIN, 26));
lblLoginPage.setBounds(0,275,366,77);
frame.add(lblLoginPage);

JScrollPane dta = new JScrollPane();
dta.setBounds(10,330,366,77);
frame.add(dta);

try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection
("jdbc:mysql://localhost:3306/cs2a","root","");
Statement stmt = con.createStatement();
String sql = "SELECT * FROM selected_view";
ResultSet rs = stmt.executeQuery(sql);

String[] fcolumn = {"StudentID","BookName"};
DefaultTableModel tableModel = new DefaultTableModel(fcolumn,0);

while(rs.next()) {
int sid = rs.getInt("student_id");
String sd=String.valueOf(sid);
String bname = rs.getString("name");
String[] data = {sd, bname};
tableModel.addRow(data);
}
JTable jt = new JTable(tableModel);
dta.setViewportView(jt);
jt.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent me) {
int row = jt.getSelectedRow();
if(row<0) {
System.out.print("test");
}else {
try {

Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection
("jdbc:mysql://localhost:3306/cs2a","root","");
Statement stmt = con.createStatement();
String id = jt.getValueAt(row, 0).toString();
String sql = "SELECT * FROM users WHERE id=' "+id+" ' ";
ResultSet rs = stmt.executeQuery(sql);
if(rs.next()) {
username.setText(rs.getString("username"));
emaile.setText(rs.getString("email"));
ide.setText(rs.getString("id"));
}
}catch(Exception ex) {System.out.print(ex);}}}});
con.close();

}catch(Exception ex) {System.out.print(ex);}


JButton btnbook = new JButton("Books");
btnbook.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
BookTable rgs = new BookTable();
}

});
btnbook.setBounds(80,171,89,23);
frame.add(btnbook);
JButton btnStudent = new JButton("Student");
btnStudent.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
StudentTable stb = new StudentTable();
}

});
btnStudent.setBounds(190,171,89,23);
frame.add(btnStudent);

JButton btnUpdate = new JButton("Update");
btnUpdate.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection
("jdbc:mysql://localhost:3306/cs2a","root","");
Statement stmt = con.createStatement();
String sql = "UPDATE users SET "
+ "username= '"+username.getText()+"' ,email= '"+emaile.getText()+"' WHERE id= "+ide.getText()+"";
stmt.execute(sql);

String ref = "SELECT * FROM users";
ResultSet rs = stmt.executeQuery(ref);

String[] fcolumn = {"ID","Username","Email"};
DefaultTableModel tableModel = new DefaultTableModel(fcolumn,0);

while(rs.next()) {
String id=String.valueOf(rs.getInt("id"));
String uname = rs.getString("username");
String email = rs.getString("email");
String[] data = {id, uname, email };
tableModel.addRow(data);
}
JTable jt = new JTable(tableModel);
sp.setViewportView(jt);

jt.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent me) {
int row = jt.getSelectedRow();
if(row<0) {
System.out.print("test");
}else {
try {

Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection
("jdbc:mysql://localhost:3306/cs2a","root","");
Statement stmt = con.createStatement();
String id = jt.getValueAt(row, 0).toString();
String sql = "SELECT * FROM users WHERE id=' "+id+" ' ";
ResultSet rs = stmt.executeQuery(sql);
if(rs.next()) {
username.setText(rs.getString("username"));
emaile.setText(rs.getString("email"));
ide.setText(rs.getString("id"));
}
}catch(Exception ex) {System.out.print(ex);}}}});
con.close();
}catch(Exception ex) {System.out.print(ex);}
}
});
btnUpdate.setBounds(220,220,89,23);
frame.add(btnUpdate);


JButton btnDelete = new JButton("Delete");
btnDelete.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection
("jdbc:mysql://localhost:3306/cs2a","root","");
Statement stmt = con.createStatement();
String sql = "DELETE FROM users "
+ "WHERE id= "+ide.getText()+"";
stmt.execute(sql);

String ref = "SELECT * FROM users";
ResultSet rs = stmt.executeQuery(ref);

String[] fcolumn = {"ID","Username","Email"};
DefaultTableModel tableModel = new DefaultTableModel(fcolumn,0);

while(rs.next()) {
String id=String.valueOf(rs.getInt("id"));
String uname = rs.getString("username");
String email = rs.getString("email");
String[] data = {id, uname, email };
tableModel.addRow(data);
}
JTable jt = new JTable(tableModel);
sp.setViewportView(jt);

jt.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent me) {
int row = jt.getSelectedRow();
if(row<0) {
System.out.print("test");
}else {
try {

Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection
("jdbc:mysql://localhost:3306/cs2a","root","");
Statement stmt = con.createStatement();
String id = jt.getValueAt(row, 0).toString();
String sql = "SELECT * FROM users WHERE id=' "+id+" ' ";
ResultSet rs = stmt.executeQuery(sql);
if(rs.next()) {
username.setText(rs.getString("username"));
emaile.setText(rs.getString("email"));
ide.setText(rs.getString("id"));
}
}catch(Exception ex) {System.out.print(ex);}}}});
con.close();
}catch(Exception ex) {System.out.print(ex);}
}
});

btnDelete.setBounds(220,250,89,23);
frame.add(btnDelete);


btnStudent.setBounds(190,171,89,23);
frame.add(btnStudent);
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.