Click Nbfs
Click Nbfs
Click Nbfs
*/
package lab05;
import java.util.ArrayList;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
/**
* @author HP
*/
DefaultTableModel dtm;
MangSinhVien a;
/**
*/
public GUI() {
initComponents();
tblHienThi.setModel( dtm);
a= new MangSinhVien();
/**
* 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
*/
@SuppressWarnings("unchecked")
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
lblNganh.setText("Nganh");
lblMaSV.setText("Ma SV");
lblTen.setText("Ten");
lblGioiTinh.setText("Gioi Tinh");
lblMon1.setText(" java");
lblMon2.setText("css");
lblMon3.setText("html");
buttonGroup1.add(rbtCNTT);
rbtCNTT.setSelected(true);
rbtCNTT.setText("CNTT");
rbtCNTT.setAutoscrolls(true);
rbtCNTT.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rbtCNTTActionPerformed(evt);
});
buttonGroup1.add(rbtKinhTe);
rbtKinhTe.setText("Kinh te");
rbtKinhTe.addActionListener(new java.awt.event.ActionListener() {
rbtKinhTeActionPerformed(evt);
});
txtMa.addActionListener(new java.awt.event.ActionListener() {
txtMaActionPerformed(evt);
});
txtTen.addActionListener(new java.awt.event.ActionListener() {
txtTenActionPerformed(evt);
});
buttonGroup2.add(rbtNam);
rbtNam.setSelected(true);
rbtNam.setText("Nam");
rbtNam.setAutoscrolls(true);
buttonGroup2.add(rbtNu);
rbtNu.setText("Nu");
tblHienThi.setModel(new javax.swing.table.DefaultTableModel(
},
new String [] {
));
tblHienThi.addMouseListener(new java.awt.event.MouseAdapter() {
tblHienThiMouseClicked(evt);
});
jScrollPane1.setViewportView(tblHienThi);
btnDocFile.setText("Doc File");
btnDocFile.addActionListener(new java.awt.event.ActionListener() {
btnDocFileActionPerformed(evt);
});
btnThem.setText("Them");
btnThem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnThemActionPerformed(evt);
});
btnUpdate.setText("Update");
btnUpdate.addActionListener(new java.awt.event.ActionListener() {
btnUpdateActionPerformed(evt);
});
Delete.setText("Delete");
Delete.setActionCommand("Delete");
Delete.addActionListener(new java.awt.event.ActionListener() {
jButtonDeleteActionPerformed(evt);
});
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(6, 6, 6)
.addComponent(btnDocFile, javax.swing.GroupLayout.PREFERRED_SIZE, 93,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnThem)
.addComponent(btnUpdate)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblNganh)
.addComponent(lblMaSV)
.addComponent(lblTen)
.addComponent(lblGioiTinh)
.addComponent(lblMon2)
.addComponent(lblMon3))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addComponent(rbtCNTT)
.addComponent(rbtNam))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addComponent(rbtNu)
.addComponent(rbtKinhTe)))
.addComponent(txtMa)
.addComponent(txtTen)
.addComponent(txtMon1)
.addComponent(txtMon2)
.addComponent(txtMon3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblNganh)
.addComponent(rbtCNTT)
.addComponent(rbtKinhTe))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblMaSV)
.addComponent(txtMa, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblTen)
.addComponent(txtTen, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblGioiTinh)
.addComponent(rbtNam)
.addComponent(rbtNu))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblMon1)
.addComponent(txtMon1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblMon2)
.addComponent(txtMon2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblMon3)
.addComponent(txtMon3, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0,
Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnDocFile)
.addComponent(btnThem)
.addComponent(btnUpdate))
.addComponent(Delete, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(42, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void rbtCNTTActionPerformed(java.awt.event.ActionEvent evt) {
lblMon1.setText("Java");
lblMon2.setText("Css");
lblMon3.setVisible(true);
txtMon3.setVisible(true);
fc.showOpenDialog(null);
String tenFile=fc.getSelectedFile().getPath();
a.docFile(tenFile);
loadData(a.getA());
int i = tblHienThi.getSelectedRow();
ArrayList<SinhVien> b = a.getA();
SinhVien y = b.get(i);
rbtCNTT.setSelected(true);
txtMon1.setText(""+((CNTT) y).getJava());
txtMon2.setText(""+((CNTT) y).getCss());
txtMon3.setText(""+((CNTT) y).getHtml());
lblMon3.setVisible(true);
txtMon3.setVisible(true);
else{
rbtKinhTe.setSelected(true);
txtMon1.setText(""+((KinhTe) y).getNlkt());
txtMon2.setText(""+((KinhTe) y).getMarketing());
lblMon3.setVisible(false);
txtMon3.setVisible(false);
txtMa.setText(y.getMa());
txtTen.setText(y.getHoTen());
if(y.isGioiTinh())
rbtNam.setSelected(true);
else rbtNu.setSelected(true);
}
private void btnThemActionPerformed(java.awt.event.ActionEvent evt) {
boolean gt = rbtNam.isSelected();
double html=0;
try{
html = Double.parseDouble(txtMon3.getText());
SinhVien y;
if(a.them(y))
loadData(a.getA());
lblMon1.setText("NLKT");
lblMon2.setText("Marketing");
lblMon3.setVisible(false);
txtMon3.setVisible(false);
/**
*/
//<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.
*/
try {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
new GUI().setVisible(true);
});
while(dtm.getRowCount()>0) dtm.removeRow(0);
for(SinhVien x:a){
dtm.addRow(new Object[]{"CNTT",x.getMa(),x.getHoTen(),x.isGioiTinh(),((CNTT)
x).getJava(), ((CNTT) x).getCss(), ((CNTT) x).getHtml(), x.getDiemTB(), x.xepLoai()});
dtm.addRow(new Object[]{"KinhTe",x.getMa(),x.getHoTen(),x.isGioiTinh(),((KinhTe)
x).getNlkt(), ((KinhTe) x).getMarketing()," ", x.getDiemTB(), x.xepLoai()});