Hi
i have created a jinternalframe using netbeans IDE but when i run the program it run without errors but the frame does not appear please help. this is my code.
package usiu;
/**
*
* @author kyalo
*/
import net.proteanit.sql.DbUtils;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.sql.*;
import java.sql.ResultSet;
import java.util.Calendar;
import javax.swing.*;
import javax.swing.JOptionPane;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Frontdesk1 extends javax.swing.JInternalFrame {
Connection cn;
Statement st;
ResultSet rs;
ResultSetMetaData rsmd;
PreparedStatement pst ;
private int Serial_No;
private int Item_name;
private int To;
private int From;
private int Category;
private int Names;
String Tag_No;
private void updatejtable() throws SQLException{
String sql = "select Tag_No, Item_Name, Name,ID_No,Category, Leaving, Heading, Time_out from movement";
try{
pst = cn.prepareStatement(sql);
rs = pst.executeQuery();
tbldata.setModel(DbUtils.resultSetToTableModel(rs) );
}
catch(Exception e) {
JOptionPane.showMessageDialog(null , e);
}
}
/** Creates new form Frontdesk1 */
public Frontdesk1() {
initComponents();
}
/** 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">
private void initComponents() {
jPopupMenu1 = new javax.swing.JPopupMenu();
txtid = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
txtname = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
cmbcategory = new javax.swing.JComboBox();
jLabel6 = new javax.swing.JLabel();
cmbfrom = new javax.swing.JComboBox();
jLabel7 = new javax.swing.JLabel();
txtto = new javax.swing.JTextField();
jLabel8 = new javax.swing.JLabel();
jScrollPane2 = new javax.swing.JScrollPane();
txtitem = new javax.swing.JTextArea();
txttag = new javax.swing.JTextField();
jLabel9 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
tbldata = new javax.swing.JTable();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
btnupdate = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jPopupMenu1.setName("jPopupMenu1"); // NOI18N
txtid.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
txtid.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.bor der.BevelBorder.LOWERED));
txtid.setName("txtid"); // NOI18N
jLabel3.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N
jLabel3.setForeground(new java.awt.Color(0, 0, 102));
jLabel3.setText("ID_No");
jLabel3.setName("jLabel3"); // NOI18N
jLabel4.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N
jLabel4.setForeground(new java.awt.Color(0, 0, 102));
jLabel4.setText("Names");
jLabel4.setName("jLabel4"); // NOI18N
txtname.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
txtname.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.bor der.BevelBorder.LOWERED));
txtname.setName("txtname"); // NOI18N
jLabel5.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N
jLabel5.setForeground(new java.awt.Color(0, 0, 102));
jLabel5.setText("Category");
jLabel5.setName("jLabel5"); // NOI18N
cmbcategory.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
cmbcategory.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Staff", "Student", "Intern", "Workstudy" }));
cmbcategory.setSelectedItem(null);
cmbcategory.setBorder(javax.swing.BorderFactory.cr eateCompoundBorder());
cmbcategory.setName("cmbcategory"); // NOI18N
jLabel6.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N
jLabel6.setForeground(new java.awt.Color(0, 0, 102));
jLabel6.setText("From");
jLabel6.setName("jLabel6"); // NOI18N
cmbfrom.setEditable(true);
cmbfrom.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
cmbfrom.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Ict center store", "Jounalism store" }));
cmbfrom.setSelectedItem(null);
cmbfrom.setBorder(javax.swing.BorderFactory.create BevelBorder(javax.swing.border.BevelBorder.RAISED) );
cmbfrom.setName("cmbfrom"); // NOI18N
jLabel7.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N
jLabel7.setForeground(new java.awt.Color(0, 0, 102));
jLabel7.setText("To");
jLabel7.setName("jLabel7"); // NOI18N
txtto.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
txtto.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.bor der.BevelBorder.LOWERED));
txtto.setName("txtto"); // NOI18N
jLabel8.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N
jLabel8.setForeground(new java.awt.Color(0, 0, 102));
jLabel8.setText("Tag_No");
jLabel8.setName("jLabel8"); // NOI18N
jScrollPane2.setName("jScrollPane2"); // NOI18N
txtitem.setColumns(20);
txtitem.setFont(new java.awt.Font("Verdana", 0, 13)); // NOI18N
txtitem.setRows(5);
txtitem.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.bor der.BevelBorder.LOWERED));
txtitem.setName("txtitem"); // NOI18N
jScrollPane2.setViewportView(txtitem);
txttag.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
txttag.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.bor der.BevelBorder.LOWERED));
txttag.setName("txttag"); // NOI18N
jLabel9.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N
jLabel9.setForeground(new java.awt.Color(0, 0, 102));
jLabel9.setText("Item_name");
jLabel9.setName("jLabel9"); // NOI18N
jScrollPane1.setName("jScrollPane1"); // NOI18N
tbldata.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 51, 102), 1, true));
tbldata.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N
tbldata.setForeground(new java.awt.Color(0, 0, 102));
tbldata.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null}
},
new String [] {
"Tag_No", "Item_name", "Names", "ID_No", "Category", "From", "To", "Time_out"
}
) {
Class[] types = new Class [] {
java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Object.class
};
boolean[] canEdit = new boolean [] {
false, false, false, false, false, false, false, false
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
tbldata.setName("tbldata"); // NOI18N
tbldata.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
tbldataMouseClicked(evt);
}
});
jScrollPane1.setViewportView(tbldata);
jButton1.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
jButton1.setForeground(new java.awt.Color(0, 0, 102));
jButton1.setText("Sigh out");
jButton1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
jButton1.setMaximumSize(new java.awt.Dimension(65, 23));
jButton1.setMinimumSize(new java.awt.Dimension(65, 23));
jButton1.setName("jButton1"); // NOI18N
jButton1.setPreferredSize(new java.awt.Dimension(65, 23));
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton1MouseClicked(evt);
}
});
jButton2.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
jButton2.setForeground(new java.awt.Color(0, 0, 102));
jButton2.setText("Sigh in");
jButton2.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
jButton2.setMaximumSize(new java.awt.Dimension(65, 23));
jButton2.setMinimumSize(new java.awt.Dimension(65, 23));
jButton2.setName("jButton2"); // NOI18N
jButton2.setPreferredSize(new java.awt.Dimension(65, 23));
btnupdate.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
btnupdate.setForeground(new java.awt.Color(0, 0, 102));
btnupdate.setText("Update");
btnupdate.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
btnupdate.setMaximumSize(new java.awt.Dimension(65, 23));
btnupdate.setMinimumSize(new java.awt.Dimension(65, 23));
btnupdate.setName("btnupdate"); // NOI18N
btnupdate.setPreferredSize(new java.awt.Dimension(65, 23));
btnupdate.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btnupdateMouseClicked(evt);
}
});
jButton4.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
jButton4.setForeground(new java.awt.Color(0, 0, 102));
jButton4.setText("Clear");
jButton4.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
jButton4.setName("jButton4"); // NOI18N
jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton4MouseClicked(evt);
}
});
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.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel3)
.addGap(18, 18, 18)
.addComponent(txtid, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel8)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.UNRELATED)
.addComponent(txttag, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel6)
.addGap(18, 18, 18)
.addComponent(cmbfrom, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)))
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(20, 20, 20)
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
.addComponent(txtname, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.UNRELATED)
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.UNRELATED)
.addComponent(cmbcategory, 0, 235, Short.MAX_VALUE)
.addGap(31, 31, 31))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(jLabel9))
.addGroup(layout.createSequentialGroup()
.addGap(31, 31, 31)
.addComponent(jLabel7)))
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(txtto, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(76, 76, 76)
.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE))
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(34, 34, 34)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.TRAILING)
.addComponent(jButton4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)
.addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addComponent(btnupdate, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)
.addGap(29, 29, 29))))
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 855, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(51, 51, 51)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(txtid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGap(45, 45, 45)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(txtname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5)
.addComponent(cmbcategory, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(55, 55, 55)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jLabel8)
.addComponent(txttag, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel9)))
.addGroup(layout.createSequentialGroup()
.addGap(25, 25, 25)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(32, 32, 32)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(txtto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6)
.addComponent(cmbfrom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnupdate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(28, 28, 28)
.addComponent(jButton4)
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void tbldataMouseClicked(java.awt.event.MouseEvent evt) {
//output the selected row value into the text fields
int row = tbldata.getSelectedRow();
txtid.setText(tbldata.getModel().getValueAt(row, 3).toString());
txtname.setText(tbldata.getModel().getValueAt(row, 2).toString());
cmbcategory.setSelectedItem(tbldata.getModel().get ValueAt(row, 4).toString());
cmbfrom.setSelectedItem(tbldata.getModel().getValu eAt(row, 5).toString());
txtto.setText(tbldata.getModel().getValueAt(row, 6).toString());
txttag.setText(tbldata.getModel().getValueAt(row, 0).toString());
txtitem.setText(tbldata.getModel().getValueAt(row, 1).toString());
// tbldata.getSelectedRow();
// JOptionPane.showMessageDialog(null, jPanel3);
// TODO add your handling code here:
}
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
try{
String tag = txttag.getText();
String id = txtid.getText();
String item = txtitem.getText();
String name = txtname.getText();
Object from = cmbfrom.getSelectedItem();
String to = txtto.getText();
Object cate = cmbcategory.getSelectedItem();
DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
Calendar cal = Calendar.getInstance();
//System.out.println(dateFormat.format(cal.getTime() ));
// Object time =dateFormat.format(cal.getTime());
/** String sql="INSERT INTO movement VALUES(' "+
* txttag.getText()+" ' , ' " +
*txtid.getText()+" ' , ' " +
* txtitem.getText()+" ' , ' " +
*txtname.getText()+"','"+
*cmbfrom.getSelectedItem()+" ' , ' " +
* txtto.getText()+"','"+
* cmbcategory.getSelectedItem()+"','"+
* tbldata.getColumnName(Category)+"')";*/
String tagid=txttag.getText();
String sql = "INSERT INTO movement (Tag_No, ID_No, Item_Name, Name, Leaving, Heading, Category) "
+ " VALUES ('" + tag + "', '" + id + "', '" + item + "', '" + name + "', '" + from + "', '"+to+"', '"+cate+"' )";
st.executeUpdate(sql);
JOptionPane.showMessageDialog(null, "Record Updated");
updatejtable();
} catch (Exception er) {
er.printStackTrace();
} // TOD // TODO add your handling code here:
}
private void btnupdateMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
String tag = txttag.getText();
try {
Statement st = cn.createStatement();
String sql = "DELETE FROM student WHERE Tag_No = '" + tag + "'";
st.executeUpdate(sql);
JOptionPane.showMessageDialog(rootPane, "Student Info Deleted Successfully");
txtid.setText(null);
txtitem.setText(null);
txtname.setText(null);
cmbfrom.setSelectedItem(null);
txtto.setText(null);
cmbcategory.setSelectedItem(null);
} catch (SQLException ex) {
Logger.getLogger(movement.class.getName()).log(Lev el.SEVERE, null, ex);
}
//do nothing
}
private void jButton4MouseClicked(java.awt.event.MouseEvent evt) {
txttag.setText(null);
txtid.setText(null);
txtitem.setText(null);
txtname.setText(null);
cmbfrom.setSelectedItem(null);
txtto.setText(null);
cmbcategory.setSelectedItem(null); // TODO add your handling code here:
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
Frontdesk1 frame = new Frontdesk1();
frame.setSize(250,300);
frame.setVisible(true);
}
});
}