By GokiSoft.com| 21:23 21/11/2020|
Java Web + EJB (EAD)

[Share Code] EJB-EAD- Overview chương trình quản lý sách SessionBean + TMS



Project: gom 2 phan > EJB + TMS
I. Phat trien phan EJB - SessionBean
B1. tao project EJB (SessionBean)
	- Tai thu vien jdbc mysql driver -> copy folder trong project
	(Su dung thu vien da download san)
	- Tao database
		- Start phpmyadmin
		- Tao bang
	- Generate tables.
	- Tao SessionBean: gom cac chuc nang
		- lay danh sach book
		- them
		- sua
		- xoa
		- tim kiem
	- Tao Wrapper -> trao doi du lieu giau EJB & Java Client
		- AuthorWrap
		- BookWrap
	- Sua persistence
	- Build project
	- Test java swing
	- fake data
B2. tao project lib (Share code giua EJB & Java Swing)
B3. tao project java swing
	- Tao Swing Form
	- Lay danh sach quan sach
		- Khi load form => hieenr thi danh sach book
		- Them => update table
	- Them sach 
	- Sua sach
		- Luu lai thong tin danh sach book
		- Bat dc su kien khi nguoi dung click item trong jtable



create table author (
	authorName varchar(50),
	birthday date,
	address varchar(200),
	nickname varchar(50) primary key
);

create table book (
	id int primary key auto_increment, 
	bookName varchar(50), 
	price float, 
	deliveredDate date,
	nickname varchar(50),
	factory varchar(200)
);

alter table book
add constraint fk_nickname foreign key (nickname) references author (nickname);



LIB



#AuthorWrap.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package wrap;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;

/**
 *
 * @author student
 */
public class AuthorWrap implements Serializable{
    private String authorName;
    private Date birthday;
    private String address;
    private String nickname;
    private Collection<BookWrap> bookCollection;

    public AuthorWrap() {
    }

    public AuthorWrap(String authorName, Date birthday, String address, String nickname) {
        this.authorName = authorName;
        this.birthday = birthday;
        this.address = address;
        this.nickname = nickname;
    }

    public String getAuthorName() {
        return authorName;
    }

    public void setAuthorName(String authorName) {
        this.authorName = authorName;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public Collection<BookWrap> getBookCollection() {
        return bookCollection;
    }

    public void setBookCollection(Collection<BookWrap> bookCollection) {
        this.bookCollection = bookCollection;
    }

    @Override
    public String toString() {
        return "AuthorWrap{" + "authorName=" + authorName + ", birthday=" + birthday + ", address=" + address + ", nickname=" + nickname + ", bookCollection=" + bookCollection + '}';
    }
}


#BookWrap.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package wrap;

import java.io.Serializable;
import java.util.Date;

/**
 *
 * @author student
 */
public class BookWrap implements Serializable{
    private Integer id;
    private String bookName;
    private Float price;
    private Date deliveredDate;
    private String factory;
    private AuthorWrap nickname;

    public BookWrap() {
    }

    public BookWrap(Integer id, String bookName, Float price, Date deliveredDate, String factory, AuthorWrap nickname) {
        this.id = id;
        this.bookName = bookName;
        this.price = price;
        this.deliveredDate = deliveredDate;
        this.factory = factory;
        this.nickname = nickname;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public Float getPrice() {
        return price;
    }

    public void setPrice(Float price) {
        this.price = price;
    }

    public Date getDeliveredDate() {
        return deliveredDate;
    }

    public void setDeliveredDate(Date deliveredDate) {
        this.deliveredDate = deliveredDate;
    }

    public String getFactory() {
        return factory;
    }

    public void setFactory(String factory) {
        this.factory = factory;
    }

    public AuthorWrap getNickname() {
        return nickname;
    }

    public void setNickname(AuthorWrap nickname) {
        this.nickname = nickname;
    }

    @Override
    public String toString() {
        return "AuthorWrap{" + "id=" + id + ", bookName=" + bookName + ", price=" + price + ", deliveredDate=" + deliveredDate + ", factory=" + factory + ", nickname=" + nickname + '}';
    }
}


#BookSessionBeanRemote.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package session;

import java.util.List;
import javax.ejb.Remote;
import wrap.BookWrap;

/**
 *
 * @author student
 */
@Remote
public interface BookSessionBeanRemote {
    List<BookWrap> getBookList();
    
    void save(BookWrap bookWrap);
    
    void delete(int id);
    
    BookWrap find(int id);
}

EJB


#persistence.xml


<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="BT1025-ejbPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>entity.Author</class>
    <class>entity.Book</class>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/quanlysach?serverTimezone=UTC"/>
      <property name="javax.persistence.jdbc.user" value="root"/>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
      <property name="javax.persistence.jdbc.password" value=""/>
    </properties>
  </persistence-unit>
</persistence>


#BookSessionBean.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package session;

import entity.Author;
import entity.Book;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
import wrap.AuthorWrap;
import wrap.BookWrap;

/**
 *
 * @author student
 */
@Stateless
public class BookSessionBean implements BookSessionBeanRemote {

    @Override
    public List<BookWrap> getBookList() {
        //Mo ket noi toi database
        EntityManagerFactory factory = Persistence.createEntityManagerFactory("BT1025-ejbPU");
        EntityManager em = factory.createEntityManager();
        
        //Query
        Query q = em.createNamedQuery("Book.findAll", Book.class);
        List<Book> bookList = q.getResultList();
        
        //convert bookList sang bookWrapList
        List<BookWrap> bookWrapList = new ArrayList<>();
        for (Book book : bookList) {
            AuthorWrap authorWrap = new AuthorWrap(book.getNickname().getAuthorName(), 
                    book.getNickname().getBirthday(), 
                    book.getNickname().getAddress(), 
                    book.getNickname().getNickname());
            BookWrap bookWrap = new BookWrap(book.getId(), 
                    book.getBookName(), 
                    book.getPrice(), 
                    book.getDeliveredDate(), 
                    book.getFactory(), authorWrap);
            bookWrapList.add(bookWrap);
        }
        
        return bookWrapList;
    }

    @Override
    public void save(BookWrap bookWrap) {
        //Mo ket noi toi database
        EntityManagerFactory factory = Persistence.createEntityManagerFactory("BT1025-ejbPU");
        EntityManager em = factory.createEntityManager();
        
        Book find = em.find(Book.class, bookWrap.getId());
        if(find != null) {
            //update
            em.getTransaction().begin();
            
            find.setBookName(bookWrap.getBookName());
            find.setDeliveredDate(bookWrap.getDeliveredDate());
            find.setFactory(bookWrap.getFactory());
            find.setPrice(bookWrap.getPrice());
            //sua nickname
            Author author = em.find(Author.class, bookWrap.getNickname().getNickname());
            find.setNickname(author);
            
            em.getTransaction().commit();
        } else {
            //insert
            Book book = new Book();
            
            Author author = em.find(Author.class, bookWrap.getNickname().getNickname());
            book.setNickname(author);
            
            book.setBookName(bookWrap.getBookName());
            book.setDeliveredDate(bookWrap.getDeliveredDate());
            book.setFactory(bookWrap.getFactory());
            book.setPrice(bookWrap.getPrice());
            
            em.getTransaction().begin();
            em.persist(book);
            em.getTransaction().commit();
        }
    }

    @Override
    public void delete(int id) {
        //Mo ket noi toi database
        EntityManagerFactory factory = Persistence.createEntityManagerFactory("BT1025-ejbPU");
        EntityManager em = factory.createEntityManager();
        
        Book find = em.find(Book.class, id);
        if(find != null) {
            em.getTransaction().begin();
            em.remove(find);
            em.getTransaction().commit();
        }
    }

    @Override
    public BookWrap find(int id) {
        //Mo ket noi toi database
        EntityManagerFactory factory = Persistence.createEntityManagerFactory("BT1025-ejbPU");
        EntityManager em = factory.createEntityManager();
        
        //Query
        Book book = em.find(Book.class, id);
        
        //convert bookList sang bookWrapList
        AuthorWrap authorWrap = new AuthorWrap(book.getNickname().getAuthorName(), 
                book.getNickname().getBirthday(), 
                book.getNickname().getAddress(), 
                book.getNickname().getNickname());
        BookWrap bookWrap = new BookWrap(book.getId(), 
                book.getBookName(), 
                book.getPrice(), 
                book.getDeliveredDate(), 
                book.getFactory(), authorWrap);
        
        return bookWrap;
    }
}

CLIENT


#BookFrame.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package aptech;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import session.BookSessionBeanRemote;
import wrap.AuthorWrap;
import wrap.BookWrap;

/**
 *
 * @author student
 */
public class BookFrame extends javax.swing.JFrame {

    @EJB
    private static BookSessionBeanRemote bookSessionBean;
    DefaultTableModel tableModel;
    List<BookWrap> bookWraps = new ArrayList<>();
    int currentIndex = -1;
    
    /**
     * Creates new form BookFrame
     */
    public BookFrame() {
        initComponents();
        
        tableModel = (DefaultTableModel) jTable1.getModel();
        
        btnShowAllActionPerformed(null);
        
        jTable1.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent me) {
                currentIndex = jTable1.getSelectedRow();
                //update input
                txtNickname.setText(bookWraps.get(currentIndex).getNickname().getNickname());
                txtBookname.setText(bookWraps.get(currentIndex).getBookName());
                txtPrice.setText(bookWraps.get(currentIndex).getPrice().toString());
                txtFactory.setText(bookWraps.get(currentIndex).getFactory());
            }

            @Override
            public void mousePressed(MouseEvent me) {
            }

            @Override
            public void mouseReleased(MouseEvent me) {
            }

            @Override
            public void mouseEntered(MouseEvent me) {
            }

            @Override
            public void mouseExited(MouseEvent me) {
            }
        });
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton4 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtNickname = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtBookname = new javax.swing.JTextField();
        txtPrice = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtFactory = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        btnSave = new javax.swing.JButton();
        btnDelete = new javax.swing.JButton();
        btnAdd = new javax.swing.JButton();
        btnShowAll = new javax.swing.JButton();
        btnSend = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        jButton4.setText("jButton1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("NHAP THONG TIN SACH"));

        jLabel1.setText("Ten tac gia: ");

        jLabel2.setText("Ten sach:");

        jLabel3.setText("Gia tien:");

        jLabel4.setText("Nha Xuat Ban:");

        btnSave.setText("Luu");
        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveActionPerformed(evt);
            }
        });

        btnDelete.setText("Xoa");
        btnDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteActionPerformed(evt);
            }
        });

        btnAdd.setText("Then Tac Gia");

        btnShowAll.setText("Hien Thi Tat Ca");
        btnShowAll.setToolTipText("");
        btnShowAll.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnShowAllActionPerformed(evt);
            }
        });

        btnSend.setText("Gui");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtPrice, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(txtBookname, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(btnSend))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(txtNickname, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(btnAdd))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(btnSave)
                                .addGap(18, 18, 18)
                                .addComponent(btnDelete)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(btnShowAll))
                            .addComponent(txtFactory, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(15, 15, 15)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtNickname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnAdd))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtBookname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnSend))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtFactory, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSave)
                    .addComponent(btnDelete)
                    .addComponent(btnShowAll))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "STT", "Ten Sach", "Ten Tac Gia", "But Danh", "Nha Xuat Ban"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnShowAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnShowAllActionPerformed
        // TODO add your handling code here:
        bookWraps = bookSessionBean.getBookList();
        
        tableModel.setRowCount(0);
        
        for (BookWrap bookWrap : bookWraps) {
            tableModel.addRow(new Object[] {
                tableModel.getRowCount() + 1,
                bookWrap.getBookName(),
                bookWrap.getNickname().getAuthorName(),
                bookWrap.getNickname().getNickname(),
                bookWrap.getFactory()
            });
        }
    }//GEN-LAST:event_btnShowAllActionPerformed

    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
        // TODO add your handling code here:
        String nickname = txtNickname.getText();
        String bookName = txtBookname.getText();
        float price = Float.parseFloat(txtPrice.getText());
        String factory = txtFactory.getText();
        
        AuthorWrap authorWrap = new AuthorWrap();
        authorWrap.setNickname(nickname);
        
        BookWrap bookWrap = null;
        
        if(currentIndex >= 0) {
            bookWrap = bookWraps.get(currentIndex);
            bookWrap.setBookName(bookName);
            bookWrap.setPrice(price);
            bookWrap.setFactory(factory);
            bookWrap.setNickname(authorWrap);
        } else {
            bookWrap = new BookWrap(0, bookName, price, new Date(), factory, authorWrap);
        }
        bookSessionBean.save(bookWrap);
        
        //reset data
        txtNickname.setText("");
        txtBookname.setText("");
        txtPrice.setText("");
        txtFactory.setText("");
        currentIndex = -1;
        
        btnShowAllActionPerformed(null);
    }//GEN-LAST:event_btnSaveActionPerformed

    private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed
        // TODO add your handling code here:
        if(currentIndex == -1) {
            JOptionPane.showMessageDialog(this, "Khong co quan sach nao dc chon");
            return;
        }
        int option = JOptionPane.showConfirmDialog(this, "Ban co muon xoa quan sach nay khong?");
        System.out.println("option: " + option);
        int id = bookWraps.get(currentIndex).getId();
        
        bookSessionBean.delete(id);
        
        btnShowAllActionPerformed(null);
    }//GEN-LAST:event_btnDeleteActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(BookFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(BookFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(BookFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(BookFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new BookFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnDelete;
    private javax.swing.JButton btnSave;
    private javax.swing.JButton btnSend;
    private javax.swing.JButton btnShowAll;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField txtBookname;
    private javax.swing.JTextField txtFactory;
    private javax.swing.JTextField txtNickname;
    private javax.swing.JTextField txtPrice;
    // End of variables declaration//GEN-END:variables
}


Tags:



Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)

Đăng nhập để làm bài kiểm tra

Chưa có kết quả nào trước đó