0% found this document useful (0 votes)
24 views12 pages

Click Nbfs

document

Uploaded by

Vinh Phung
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views12 pages

Click Nbfs

document

Uploaded by

Vinh Phung
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

/*

* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license

* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template

*/

package View;

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.Dimension;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import javax.swing.BorderFactory;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JMenuItem;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JPopupMenu;

import javax.swing.JScrollPane;

/**

* @author vinhp

*/

public class Home_Form extends javax.swing.JFrame {

/**

* Creates new form Produuct


*/

public Home_Form() {

initComponents();

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

productPanel.setLayout(new GridLayout(0, 4, 10, 10));

displayProductData();

setLocationRelativeTo(null);

pack();

private void displayProductData() {

// Simulated product data

String[] products = {"Product 1", "Product 2", "Product 3", "Product 4", "Product 5", "Product 6",
"Product 7", "Product 8", "Product 9"};

for (String product : products) {

JPanel itemPanel = createProductItem(product);

productPanel.add(itemPanel);

// private JPanel createProductItem(String productName) {

// JPanel itemPanel = new JPanel();

// itemPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));

// itemPanel.setPreferredSize(new Dimension(100, 100)); // Fixed size for each item

//

// JLabel nameLabel = new JLabel(productName);

// itemPanel.add(nameLabel);

//

//

//

// // Add click listener


// itemPanel.addMouseListener(new MouseAdapter() {

// public void mouseClicked(MouseEvent evt) {

// showProductDetail(productName);

// }

// });

//

// return itemPanel;

// }

private JPanel createProductItem(String productName) {

JPanel itemPanel = new JPanel();

itemPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));

itemPanel.setPreferredSize(new Dimension(100, 100)); // Kích thước cố định cho mỗi mục

JLabel nameLabel = new JLabel(productName);

itemPanel.add(nameLabel);

// Thêm MouseListener để bắt sự kiện click chuột phải

itemPanel.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent evt) {

// Click chuột phải

showProductOptionsPopup(evt, productName);

});

return itemPanel;

private void showProductOptionsPopup(MouseEvent evt, String productName) {


JPopupMenu popupMenu = new JPopupMenu();

// Tạo các tùy chọn

JMenuItem viewRoomInfoItem = new JMenuItem("Xem thông tin phòng");

JMenuItem createContractItem = new JMenuItem("Tạo hợp đồng");

// Thêm ActionListener cho mỗi tùy chọn

viewRoomInfoItem.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// Thực hiện hành động khi chọn "Xem thông tin phòng"

JOptionPane.showMessageDialog(null, "Đang xem thông tin phòng cho sản phẩm: " +
productName);

});

createContractItem.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// Thực hiện hành động khi chọn "Tạo hợp đồng"

JOptionPane.showMessageDialog(null, "Đang tạo hợp đồng cho sản phẩm: " + productName);

});

// Thêm các tùy chọn vào JPopupMenu

popupMenu.add(viewRoomInfoItem);

popupMenu.add(createContractItem);

// Hiển thị JPopupMenu tại vị trí chuột được click

popupMenu.show(evt.getComponent(), evt.getX(), evt.getY());

}
@SuppressWarnings("unchecked")

// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

productPanel = new javax.swing.JPanel();

jPanel1 = new javax.swing.JPanel();

jLabel1 = new javax.swing.JLabel();

jLabel2 = new javax.swing.JLabel();

jLabel3 = new javax.swing.JLabel();

jLabel4 = new javax.swing.JLabel();

jTextField2 = new javax.swing.JTextField();

jTextField4 = new javax.swing.JTextField();

jComboBox1 = new javax.swing.JComboBox<>();

jComboBox2 = new javax.swing.JComboBox<>();

jLabel5 = new javax.swing.JLabel();

jComboBox3 = new javax.swing.JComboBox<>();

jPanel2 = new javax.swing.JPanel();

jRadioButton1 = new javax.swing.JRadioButton();

jRadioButton2 = new javax.swing.JRadioButton();

jMenuBar1 = new javax.swing.JMenuBar();

jMenu1 = new javax.swing.JMenu();

jMenu2 = new javax.swing.JMenu();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

productPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Danh sách phòng"));

productPanel.setLayout(new java.awt.GridLayout(10, 0, 3, 10));

jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Thêm phòng"));

jLabel1.setText("Loại phòng");
jLabel2.setText("Tầng");

jLabel3.setText("Số lượng");

jLabel4.setText("Mô tả");

jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Nhỏ",


"Lớn" }));

jComboBox2.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "1", "2", "3",


"4" }));

jLabel5.setText("Trạng thái");

jComboBox3.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Đang sử


dụng", "Trống", "Đang sửa" }));

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.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG, false)

.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 37,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 37,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jLabel5))

.addGap(18, 18, 18)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)

.addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG, false)

.addComponent(jTextField2)

.addComponent(jTextField4)

.addComponent(jComboBox1, 0, 128, Short.MAX_VALUE))

.addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addContainerGap(12, Short.MAX_VALUE))

);

jPanel1Layout.setVerticalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(11, 11, 11)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELIN
E)

.addComponent(jLabel1)

.addComponent(jComboBox1, 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.BASELIN
E)

.addComponent(jLabel2)

.addComponent(jComboBox2, 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.BASELIN
E)

.addComponent(jLabel3)

.addComponent(jTextField2, 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.BASELIN
E)

.addComponent(jLabel4)

.addComponent(jTextField4, 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.TRAILING
)

.addComponent(jLabel5)

.addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addContainerGap(149, Short.MAX_VALUE))

);

jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Lọc"));

jRadioButton1.setText("Phòng Trống");

jRadioButton2.setText("Đã Thuê");

javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);

jPanel2.setLayout(jPanel2Layout);

jPanel2Layout.setHorizontalGroup(

jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel2Layout.createSequentialGroup()

.addContainerGap()

.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)

.addComponent(jRadioButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 98,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jRadioButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 98,


javax.swing.GroupLayout.PREFERRED_SIZE))

.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

);
jPanel2Layout.setVerticalGroup(

jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel2Layout.createSequentialGroup()

.addContainerGap()

.addComponent(jRadioButton1)

.addGap(18, 18, 18)

.addComponent(jRadioButton2)

.addContainerGap(96, Short.MAX_VALUE))

);

jMenu1.setText("File");

jMenuBar1.add(jMenu1);

jMenu2.setText("Edit");

jMenuBar1.add(jMenu2);

setJMenuBar(jMenuBar1);

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()

.addComponent(productPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 588,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

.addContainerGap())
);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addContainerGap()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(productPanel, javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()

.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addContainerGap())))

);

pack();

}// </editor-fold>

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(Home_Form.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);

} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(Home_Form.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);

} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(Home_Form.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(Home_Form.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);

//</editor-fold>

//</editor-fold>

//</editor-fold>

//</editor-fold>

/* Create and display the form */

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new Home_Form().setVisible(true);

});

// Variables declaration - do not modify

private javax.swing.JComboBox<String> jComboBox1;

private javax.swing.JComboBox<String> jComboBox2;

private javax.swing.JComboBox<String> jComboBox3;

private javax.swing.JLabel jLabel1;


private javax.swing.JLabel jLabel2;

private javax.swing.JLabel jLabel3;

private javax.swing.JLabel jLabel4;

private javax.swing.JLabel jLabel5;

private javax.swing.JMenu jMenu1;

private javax.swing.JMenu jMenu2;

private javax.swing.JMenuBar jMenuBar1;

private javax.swing.JPanel jPanel1;

private javax.swing.JPanel jPanel2;

private javax.swing.JRadioButton jRadioButton1;

private javax.swing.JRadioButton jRadioButton2;

private javax.swing.JTextField jTextField2;

private javax.swing.JTextField jTextField4;

private javax.swing.JPanel productPanel;

// End of variables declaration

You might also like