Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2010
    Posts
    1
    Rep Power
    0

    Default JFrame(window) not displaying at all

    import java.sql.*;
    import java.awt.event.*;

    public class NewJPanel extends javax.swing.JFrame implements ActionListener {
    // Variables declaration - do not modify


    private InventoryConn conn;
    // End of variables declaration
    Statement stmt;

    /** Creates new form NewJPanel */
    public NewJPanel() {
    super("Our Application");
    initComponents();
    add.addActionListener(this);
    conn = new InventoryConn();
    }

    /** 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() {

    add = new javax.swing.JButton();
    close = new javax.swing.JButton();
    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    txtCategoryID = new javax.swing.JTextField();
    txtCategoryName = new javax.swing.JTextField();

    setName("Form"); // NOI18N

    org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(i nventory.InventoryApp.class).getContext().getResou rceMap(NewJPanel.class);
    add.setText(resourceMap.getString("add.text")); // NOI18N
    add.setName("add"); // NOI18N

    close.setText(resourceMap.getString("close.text")) ; // NOI18N
    close.setName("close"); // NOI18N

    jLabel1.setText(resourceMap.getString("jLabel1.tex t")); // NOI18N
    jLabel1.setName("jLabel1"); // NOI18N

    jLabel2.setText(resourceMap.getString("jLabel2.tex t")); // NOI18N
    jLabel2.setName("jLabel2"); // NOI18N

    txtCategoryID.setText(resourceMap.getString("txtCa tegoryID.text")); // NOI18N
    txtCategoryID.setName("txtCategoryID"); // NOI18N

    txtCategoryName.setText(resourceMap.getString("txt CategoryName.text")); // NOI18N
    txtCategoryName.setName("txtCategoryName"); // NOI18N

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(95, 95, 95)
    .addComponent(add)
    .addGap(72, 72, 72)
    .addComponent(close))
    .addGroup(layout.createSequentialGroup()
    .addGap(82, 82, 82)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addComponent(jLabel1)
    .addComponent(jLabel2))
    .addGap(41, 41, 41)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING, false)
    .addComponent(txtCategoryName)
    .addComponent(txtCategoryID, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE))))
    .addContainerGap(87, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, layout.createSequentialGroup()
    .addGap(34, 34, 34)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(jLabel1)
    .addComponent(txtCategoryID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGap(37, 37, 37)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(jLabel2)
    .addComponent(txtCategoryName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, 85, Short.MAX_VALUE)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(add)
    .addComponent(close))
    .addGap(81, 81, 81))
    );
    }// </editor-fold>


    // Variables declaration - do not modify
    private javax.swing.JButton add;
    private javax.swing.JButton close;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField txtCategoryID;
    private javax.swing.JTextField txtCategoryName;
    // End of variables declaration

    public static void main(String args[]) {

    NewJPanel panel = new NewJPanel();
    panel.initComponents();

    }

    public void actionPerformed(ActionEvent e) {
    // throw new UnsupportedOperationException("Not supported yet.");
    if (e.getSource() == add) {
    try {
    stmt = conn.con.createStatement();
    stmt.executeUpdate("INSERT INTO category "
    + "VALUES (1001, 'Simpson')");

    } catch (Exception ee) {
    }

    }

    }
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,453
    Blog Entries
    7
    Rep Power
    20

    Default

    I don't know if it matters much but why is initComponents() called twice? Once in the constructor and once in the main( ... ) method of the class ...

    kind regards,

    Jos

    ps. Better tag your code with [code] ... [/code] tags; this is unreadable.

Similar Threads

  1. How do i open JFrame in the same active window
    By Jkiller295 in forum AWT / Swing
    Replies: 35
    Last Post: 06-02-2010, 04:50 PM
  2. Replies: 0
    Last Post: 11-28-2009, 03:37 AM
  3. JFrame window doesnt change background color
    By Addez in forum New To Java
    Replies: 7
    Last Post: 11-07-2009, 09:38 PM
  4. Replies: 3
    Last Post: 10-12-2009, 02:03 PM
  5. How to close an open JFrame window from a jsp page?
    By kasisaiganesh in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 05-27-2008, 06:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •