我已经为NetBeans中的下面的代码创建了.jar,但是当我双击.jar时没有任何反应,尽管NetBeans的一切正常:请帮忙
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* NewJFrame.java
*
* Created on Dec 2, 2013, 3:17:19 PM
*/
package codereview;
import java.io.IOException;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
//import javax.swing.JOptionPane;
/**
*
* @author sony
*/
public class NewJFrame extends javax.swing.JFrame {
//Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = null;
ResultSet rs = null;
Statement st = null;
PreparedStatement pst =null;
public NewJFrame() throws SQLException, ClassNotFoundException {
initComponents();
//setIcon();
reset.setEnabled(false);
submit.setEnabled(false);
//fillCombo();
}
/** 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() {
jPanel1 = new javax.swing.JPanel();
submit = new javax.swing.JButton();
instruction = new javax.swing.JLabel();
entitytype = new javax.swing.JComboBox();
username = new javax.swing.JTextField();
psswd = new javax.swing.JTextField();
sid = new javax.swing.JTextField();
destination = new javax.swing.JTextField();
install = new javax.swing.JButton();
foldername = new javax.swing.JComboBox();
reset = new javax.swing.JButton();
check = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
data = new javax.swing.JTable();
add = new javax.swing.JButton();
nameentity = new javax.swing.JComboBox();
remove = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
refresh = new javax.swing.JButton();
jPanel3 = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Eccella Code Review Tool");
setAlwaysOnTop(true);
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
submit.setText("Generate Report");
submit.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
submitMouseClicked(evt);
submitMouseClicked1(evt);
}
});
submit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
submitActionPerformed(evt);
submitActionPerformed1(evt);
}
});
jPanel1.add(submit, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 400, 200, 37));
instruction.setBackground(new java.awt.Color(204, 255, 204));
instruction.setFont(new java.awt.Font("Tahoma", 1, 14));
instruction.setText(" Enter The Details One-by-One and Submit:");
instruction.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jPanel1.add(instruction, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 10, 341, 30));
entitytype.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Folder", "Mapping", "Workflow" }));
entitytype.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
}
public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
entitytypePopupMenuWillBecomeInvisible(evt);
}
public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
}
});
entitytype.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
entitytypeItemStateChanged(evt);
}
});
entitytype.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
entitytypeActionPerformed(evt);
}
private void entitytypeActionPerformed(java.awt.event.ActionEvent evt) {
}
private void setItem() throws ClassNotFoundException, SQLException
{
String folder= (String) foldername.getSelectedItem();
String type = (String) entitytype.getSelectedItem();
String i =username.getText();
String j =psswd.getText();
String k = sid.getText();
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection( "jdbc:oracle:thin:@"+k,i,j);
st = con.createStatement();
rs =st.executeQuery("SELECT PARENT_MAPPING_NAME FROM REP_ALL_MAPPING");
while(rs.next())
{
nameentity.addItem(rs.getString("PARENT_MAPPING_NAME"));
System.out.println("New object added to combo box");
}
rs.close();
con.close();
}
private void submitActionPerformed(java.awt.event.ActionEvent evt) {
}
private void submitMouseClicked(java.awt.event.MouseEvent evt) {
//String i =foldername.getText();
//String j =entityname.getText();
//tring k = (String)entitytype.getSelectedItem();
//result.setText("<html>"+i+"<br>"+j+"<br>"+k+"</html>");
}
private void submitMouseClicked1(java.awt.event.MouseEvent evt) {
}
private void submitActionPerformed1(java.awt.event.ActionEvent evt) {
Object message = null;
// try {
// String i =username.getText();
// String j =psswd.getText();
// String k = sid.getText();
// String folder= (String) foldername.getSelectedItem();
// String name = entityname.getText();
// String type = (String) entitytype.getSelectedItem();
//
// Class<?> forName = Class.forName("oracle.jdbc.driver.OracleDriver");
// con=DriverManager.getConnection( "jdbc:oracle:thin:@"+k,i,j);
// CallableStatement csmt = con.prepareCall("{call CODE_REVIEW.PRC_WRAPPER_REVIEW(?,?,?,?)}");
// csmt.setString(1,name);
// csmt.setString(2,type);
// csmt.setString(3,folder);
// csmt.registerOutParameter(4,java.sql.Types.VARCHAR);
// csmt.execute();
// String message =csmt.getString(4);
// //JOptionPane.showMessageDialog(null, message);
// } catch (ClassNotFoundException | SQLException ex) {
// Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
// }
try {
String i =username.getText();
String j =psswd.getText();
String k = sid.getText();
Class<?> forName = Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection( "jdbc:oracle:thin:@"+k,i,j);
DefaultTableModel model = (DefaultTableModel) data.getModel();
for (int count = 0; count < model.getRowCount(); count++)
{
CallableStatement csmt = con.prepareCall("{call CODE_REVIEW.PRC_WRAPPER_REVIEW(?,?,?,?)}");
String folder=model.getValueAt(count, 0).toString();
String type=model.getValueAt(count, 1).toString();
String name=model.getValueAt(count, 2).toString();
csmt.setString(1,name);
csmt.setString(2,type);
csmt.setString(3,folder);
csmt.registerOutParameter(4,java.sql.Types.VARCHAR);
csmt.execute();
String messege =csmt.getString(4);
}
JOptionPane optionPane = new JOptionPane("Reports are Generated");
JDialog dialog = optionPane.createDialog("Success!");
dialog.setAlwaysOnTop(this.isAlwaysOnTopSupported());
dialog.setVisible(true);
} catch (ClassNotFoundException | SQLException ex) {
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void fillCombo() throws ClassNotFoundException, SQLException
{
check.setText("");
String i =username.getText();
String j =psswd.getText();
String k = sid.getText();
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection( "jdbc:oracle:thin:@"+k,i,j);
if(con != null)
{
install.setEnabled(false);
reset.setEnabled(true);
}
st = con.createStatement();
rs =st.executeQuery("SELECT DISTINCT SUBJECT_AREA FROM REP_SUBJECT");
while(rs.next())
{
foldername.addItem(rs.getString("SUBJECT_AREA"));
System.out.println("New object added to combo box");
}
rs.close();
con.close();
}
private Object makeObj(final String item) {
return new Object() {@Override
public String toString() { return item; } };
}
private void usernameActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void psswdActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void sidActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void destinationActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void installMouseClicked(java.awt.event.MouseEvent evt) {
try {
// TODO add your handling code here:
fillCombo();
} catch (ClassNotFoundException | SQLException ex) {
//check.setText("Please Enter Correct Details");
JOptionPane.showMessageDialog(this,"Please Enter Correct Details","Message",JOptionPane.ERROR_MESSAGE);
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
int r = 2 ;
String i =username.getText();
String j =psswd.getText();
String k =sid.getText();
int index =k.lastIndexOf(":");
String m =k.substring(index+1);
String l=destination.getText();
Runtime run = Runtime.getRuntime();
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection( "jdbc:oracle:thin:@"+k,i,j);
pst=con.prepareStatement("SELECT OBJECT_NAME FROM USER_OBJECTS WHERE OBJECT_TYPE = ? AND OBJECT_NAME =? ");
pst.setString(1,"PACKAGE BODY");
pst.setString(2,"CODE_REVIEW");
rs =pst.executeQuery();
System.out.println("Executed query");
String obj = new String();
while (rs.next())
{
obj = rs.getString("OBJECT_NAME");
}
if ("CODE_REVIEW".equals(obj))
{
// JOptionPane optionPane = new JOptionPane("You Have Already Done Installation, Please Go Ahead With Report Generation");
// JDialog dialog = optionPane.createDialog("Alert!");
// dialog.setAlwaysOnTop(this.isAlwaysOnTopSupported());
// dialog.setVisible(true);
r = JOptionPane.showConfirmDialog(this,"Already Installed, Do You Want to Install Anyway","Message",JOptionPane.YES_NO_OPTION);
}
if ("".equals(obj) || r == 0)
{
System.out.println("Start Running the batch file");
Process p = run.exec(new String[]{"cmd.exe","/c","install.bat",i,j,m,l});
System.out.println(" Batch Executed");
}
rs.close();
con.close();
}
catch ( ClassNotFoundException | SQLException | IOException e)
{
}
}
private void destinationFocusGained(java.awt.event.FocusEvent evt) {
if (destination.getText().equals("Enter Path For Report"))
{
destination.setText("");// TODO add your handling code here:
}
}
private void destinationFocusLost(java.awt.event.FocusEvent evt) {
if (destination.getText().equals(""))
{
destination.setText("Enter Path For Report");// TODO add your handling code here:
}
}
private void sidFocusGained(java.awt.event.FocusEvent evt) {
if (sid.getText().equals("Enter DB connect string/TNS name"))
{
sid.setText("");// TODO add your handling code here:
}
}
private void sidFocusLost(java.awt.event.FocusEvent evt) {
if (sid.getText().equals(""))
{
sid.setText("Enter DB connect string/TNS name");// TODO add your handling code here:
}
}
private void psswdFocusGained(java.awt.event.FocusEvent evt) {
if (psswd.getText().equals("Enter DB Password"))
{
psswd.setText("");// TODO add your handling code here:
}
}
private void psswdFocusLost(java.awt.event.FocusEvent evt) {
if (psswd.getText().equals(""))
{
psswd.setText("Enter DB Password");// TODO add your handling code here:
}
}
private void usernameFocusGained(java.awt.event.FocusEvent evt) {
if (username.getText().equals("Enter DB UserName"))
{
username.setText("");// TODO add your handling code here:
}
}
private void usernameFocusLost(java.awt.event.FocusEvent evt) {
if (username.getText().equals(""))
{
username.setText("Enter DB UserName");// TODO add your handling code here:
}
}
private void resetMouseClicked(java.awt.event.MouseEvent evt) {
install.setEnabled(true);
reset.setEnabled(false);
}
private void installActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void addMouseClicked(java.awt.event.MouseEvent evt) {
submit.setEnabled(true);
String folder= (String) foldername.getSelectedItem();
String name = (String) nameentity.getSelectedItem();
String type = (String) entitytype.getSelectedItem();
addRow(folder,type,name);
}
private void entitytypeItemStateChanged(java.awt.event.ItemEvent evt) {
}
private void entitytypePopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
refreshComboBox();
// nameentity.removeAllItems();
// String tmp =(String) entitytype.getSelectedItem();
// String folder= (String) foldername.getSelectedItem();
// String i =username.getText();
// String j =psswd.getText();
// String k = sid.getText();
//try
//{
// Class<?> forName = Class.forName("oracle.jdbc.driver.OracleDriver");
// con=DriverManager.getConnection( "jdbc:oracle:thin:@"+k,i,j);
// if ("Mapping".equals(tmp)) {
// String sql ="SELECT m.PARENT_MAPPING_NAME FROM REP_ALL_MAPPINGS m,REP_SUBJECT s WHERE s.SUBJECT_ID = m.SUBJECT_ID AND s.SUBJECT_AREA =?";
// pst=con.prepareStatement(sql);
// pst.setString(1, folder );
// rs=pst.executeQuery();
// while(rs.next())
// {
// nameentity.addItem(rs.getString("PARENT_MAPPING_NAME"));
// System.out.println("New object added to combo box");
// }
// }
// if ("Workflow".equals(tmp)) {
// String sql ="SELECT w.WORKFLOW_NAME FROM REP_WORKFLOWS w,REP_SUBJECT s WHERE w.SUBJECT_ID = s.SUBJECT_ID AND w.SUBJECT_AREA =?";
// pst=con.prepareStatement(sql);
// pst.setString(1, folder );
// rs=pst.executeQuery();
// while(rs.next())
// {
// nameentity.addItem(rs.getString("WORKFLOW_NAME"));
// System.out.println("New object added to combo box");
// }
// }
// if ("Folder".equals(tmp)) {
// String sql ="SELECT DISTINCT SUBJECT_AREA FROM REP_SUBJECT WHERE SUBJECT_AREA=?";
// pst=con.prepareStatement(sql);
// pst.setString(1, folder );
// rs=pst.executeQuery();
// while(rs.next())
// {
// nameentity.addItem(rs.getString("SUBJECT_AREA"));
// System.out.println("New object added to combo box");
// }
// }
// rs.close();
// con.close();
//
//}
//catch ( ClassNotFoundException | SQLException e)
//{
// // JOptionPane.showMessageDialog(null, e);
//}
}
private void refreshComboBox()
{
nameentity.removeAllItems();
String tmp =(String) entitytype.getSelectedItem();
String folder= (String) foldername.getSelectedItem();
String i =username.getText();
String j =psswd.getText();
String k = sid.getText();
try
{
Class<?> forName = Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection( "jdbc:oracle:thin:@"+k,i,j);
if ("Mapping".equals(tmp)) {
String sql ="SELECT m.PARENT_MAPPING_NAME FROM REP_ALL_MAPPINGS m,REP_SUBJECT s WHERE s.SUBJECT_ID = m.SUBJECT_ID AND s.SUBJECT_AREA =?";
pst=con.prepareStatement(sql);
pst.setString(1, folder );
rs=pst.executeQuery();
while(rs.next())
{
nameentity.addItem(rs.getString("PARENT_MAPPING_NAME"));
System.out.println("New object added to combo box");
}
}
if ("Workflow".equals(tmp)) {
String sql ="SELECT w.WORKFLOW_NAME FROM REP_WORKFLOWS w,REP_SUBJECT s WHERE w.SUBJECT_ID = s.SUBJECT_ID AND w.SUBJECT_AREA =?";
pst=con.prepareStatement(sql);
pst.setString(1, folder );
rs=pst.executeQuery();
while(rs.next())
{
nameentity.addItem(rs.getString("WORKFLOW_NAME"));
System.out.println("New object added to combo box");
}
}
if ("Folder".equals(tmp)) {
String sql ="SELECT DISTINCT SUBJECT_AREA FROM REP_SUBJECT WHERE SUBJECT_AREA=?";
pst=con.prepareStatement(sql);
pst.setString(1, folder );
rs=pst.executeQuery();
while(rs.next())
{
nameentity.addItem(rs.getString("SUBJECT_AREA"));
System.out.println("New object added to combo box");
}
}
rs.close();
con.close();
}
catch ( ClassNotFoundException | SQLException e)
{
// JOptionPane.showMessageDialog(null, e);
}
}
private void removeActionPerformed(java.awt.event.ActionEvent evt) {
DefaultTableModel model = (DefaultTableModel) data.getModel();
int i = data.getSelectedRow();
model.removeRow(i);
JOptionPane optionPane = new JOptionPane("Record Deleted!");
JDialog dialog = optionPane.createDialog("Success!");
dialog.setAlwaysOnTop(this.isAlwaysOnTopSupported());
dialog.setVisible(true);
}
private void refreshActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
// TODO add your handling code here:
nameentity.removeAllItems();
foldername.removeAllItems();
fillCombo();
} catch (ClassNotFoundException | SQLException ex) {
check.setText("Please Enter Correct Details");
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void foldernamePopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
// TODO add your handling code here:
refreshComboBox();
}
public void addRow(String foldername, String entitytype, String entityname)
{
DefaultTableModel model = (DefaultTableModel) data.getModel();
Object [] row = new Object [3];
row[0] = foldername;
row[1] = entitytype;
row[2] = entityname;
model.addRow(row);
} /**
* @param args the command line arguments
*/
@SuppressWarnings("unchecked")
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 ("Windows".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
new NewJFrame().setVisible(true);
} catch ( SQLException | ClassNotFoundException ex) {
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton add;
private javax.swing.JLabel check;
private javax.swing.JTable data;
private javax.swing.JTextField destination;
private javax.swing.JComboBox entitytype;
private javax.swing.JComboBox foldername;
private javax.swing.JButton install;
private javax.swing.JLabel instruction;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JComboBox nameentity;
private javax.swing.JTextField psswd;
private javax.swing.JButton refresh;
private javax.swing.JButton remove;
private javax.swing.JButton reset;
private javax.swing.JTextField sid;
private javax.swing.JButton submit;
private javax.swing.JTextField username;
// End of variables declaration
}
请注意我已从上述代码中删除了不必要的代码......
答案 0 :(得分:0)
右键单击netbeans中的yoru projet并选择Set Configuration&gt;然后自定义&gt;在出现的窗口中,通过单击浏览按钮或手动编写并再次清理并生成
来提供主类主要类必须像我上面告诉你的那样指定
答案 1 :(得分:0)
有时JDK版本是使用最新JDK版本的原因。你添加了一个主题吗?当我设置一个外观和感觉时,我也遇到了问题..也没有解决我的问题。没有teme它运行良好..所以没有设置任何主题尝试。
答案 2 :(得分:0)
我上面发布的错误就像是:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/netbeans/lib/awtextra/AbsoluteLayout at codereview.NewJFrame.initComponents(NewJFrame.java:77) at codereview.NewJFrame.<init>(NewJFrame.java:34) .....37 more
所以我将我的JPanel的布局改为GridBagLayout,它现在开始工作了,不知道原因,但我很高兴并感谢所有帮助我的人让我继续解决这个问题,否则我会放弃。干杯