Hello I am running into an error after creating the jar file. I get a message stating that the main class to my program could not be found when in fact there is a main class.
If someone could give me a hand and lead me in the right direction on how to tackle this problem, it will be greatly appreciated.
Thanks.
This is my main program file:
public class MainProgram{
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(Frame_Layout.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Frame_Layout.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Frame_Layout.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Frame_Layout.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/*
* Create and display the form
*/
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Frame_Layout().setVisible(true);
}
});
}
}
This is my frame layout class:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
/**
*
* @author Rodrigo Tellez
*/
@SuppressWarnings("serial")
public class Frame_Layout extends javax.swing.JFrame {
/**
* Creates new form Frame_Layout
*/
private int statusNum=0;
private int nSubClicks=0;
private List<String> gradeList = new ArrayList<String>();
private List<String> unitList = new ArrayList<String>();
public Frame_Layout() {
initComponents();
jTextArea1.setEditable(false);
}
/**
* 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", "rawtypes" })
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
menuBar1 = new java.awt.MenuBar();
menu1 = new java.awt.Menu();
menu2 = new java.awt.Menu();
menuBar2 = new java.awt.MenuBar();
menu3 = new java.awt.Menu();
menu4 = new java.awt.Menu();
menuBar3 = new java.awt.MenuBar();
menu5 = new java.awt.Menu();
menu6 = new java.awt.Menu();
popupMenu1 = new java.awt.PopupMenu();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jComboBox1 = new javax.swing.JComboBox();
jCheckBox1 = new javax.swing.JCheckBox();
jLabel4 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jTextField4 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jList1 = new javax.swing.JList();
jScrollPane2 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jLabel5 = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jSeparator3 = new javax.swing.JPopupMenu.Separator();
jMenuItem4 = new javax.swing.JMenuItem();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem3 = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
jSeparator2 = new javax.swing.JPopupMenu.Separator();
jMenuItem2 = new javax.swing.JMenuItem();
menu1.setLabel("File");
menuBar1.add(menu1);
menu2.setLabel("Edit");
menuBar1.add(menu2);
menu3.setLabel("File");
menuBar2.add(menu3);
menu4.setLabel("Edit");
menuBar2.add(menu4);
menu5.setLabel("File");
menuBar3.add(menu5);
menu6.setLabel("Edit");
menuBar3.add(menu6);
popupMenu1.setLabel("popupMenu1");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("SJDC GPA Calculator");
jLabel1.setText("Class Name:");
jLabel2.setText("Grade:");
jLabel3.setText("Units:");
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Semester 1", "Semester 2", "Semester 3", "Semester 4", "Semester 5", "Semester 6", "Semester 7" }));
jCheckBox1.setText("Summer:");
jLabel4.setText("Year:");
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
jTextField2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jTextField2MouseClicked(evt);
}
});
jButton1.setText("Submit:");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton1MouseClicked(evt);
}
});
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jList1.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
});
jScrollPane1.setViewportView(jList1);
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane2.setViewportView(jTextArea1);
jButton2.setText("Clear Input:");
jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton2MouseClicked(evt);
}
});
jButton3.setText("Change Semester");
jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton3MouseClicked(evt);
}
});
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jLabel5.setText("Developed by: Rodrigo Tellez");
jMenu1.setText("File");
jMenu1.add(jSeparator3);
jMenuItem4.setText("Open");
jMenu1.add(jMenuItem4);
jMenuItem1.setText("Save");
jMenu1.add(jMenuItem1);
jMenuItem3.setText("Close");
jMenu1.add(jMenuItem3);
jMenuBar1.add(jMenu1);
jMenu2.setText("Edit");
jMenu2.add(jSeparator2);
jMenuItem2.setText("Clear");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem2);
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()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jComboBox1, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(24, 24, 24)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jCheckBox1)
.addComponent(jTextField1)
.addComponent(jTextField2)
.addComponent(jTextField3)
.addComponent(jTextField4))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 376, Short.MAX_VALUE)
.addComponent(jButton2))
.addComponent(jScrollPane2)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel5)
.addGap(205, 205, 205)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton2)
.addComponent(jButton3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel5))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jCheckBox1))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jButton1)
.addGap(76, 76, 76))))
);
pack();
}// </editor-fold>
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//jTextField1.setText(null);
jTextField2.setText(null);
jTextField3.setText(null);
jTextField4.setText(null);
//jCheckBox1.setSelected(false);
}
//submit button
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
//this is the submit button
if( statusNum==0 &&
(jTextField1.getText()!=null && !"".equals(jTextField1.getText())) &&
(jTextField2.getText()!=null && !"".equals(jTextField2.getText())) &&
(jTextField3.getText()!=null && !"".equals(jTextField3.getText())) &&
(jTextField4.getText()!=null && !"".equals(jTextField4.getText()))
){
String year = jTextField1.getText();
String className = jTextField2.getText();
String grade = jTextField3.getText();
String units = jTextField4.getText();
String semester = (String)jComboBox1.getSelectedItem();
String summer = (jCheckBox1.isSelected()==true)?"true":"false";
jTextArea1.append("Year: "+year+"\t"+semester+"\t"+"Summer = "+summer +
"\nClass Name:\tGrade:\tUnits:"+
"\n"+className+"\t"+grade+"\t"+units+"\n");
jTextField1.setEditable(false);
jComboBox1.setEnabled(false);
jCheckBox1.setEnabled(false);
jMenuItem2.doClick();
gradeList.add(grade);
unitList.add(units);
statusNum+=1;
nSubClicks+=1;
}
else if( statusNum>0 &&
(jTextField1.getText()!=null && !"".equals(jTextField1.getText())) &&
(jTextField2.getText()!=null && !"".equals(jTextField2.getText())) &&
(jTextField3.getText()!=null && !"".equals(jTextField3.getText())) &&
(jTextField4.getText()!=null && !"".equals(jTextField4.getText()))
){
//jTextField1.setEditable(false);
String className = jTextField2.getText();
String grade = jTextField3.getText();
String units = jTextField4.getText();
//jComboBox1.setEditable(false);
jTextArea1.append(className+"\t"+grade+"\t"+units+"\n");
jMenuItem2.doClick();
gradeList.add(grade);
unitList.add(units);
statusNum+=1;
nSubClicks+=1;
}
else{
JOptionPane.showMessageDialog(null,"All fields must be filled:");
}
}
//clear input button
private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {
jTextArea1.setText(null);
jMenuItem2.doClick();
jTextField1.setText(null);
jTextField2.setText(null);
jTextField1.setEditable(true);
jComboBox1.setEnabled(true);
jCheckBox1.setEnabled(true);
statusNum=0;
nSubClicks=0;
gradeList.clear();
unitList.clear();
}
private void jTextField2MouseClicked(java.awt.event.MouseEvent evt) {
}
//change semester button
private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {
jMenuItem2.doClick();
jTextField1.setText(null);
jTextField2.setText(null);
jTextField1.setEditable(true);
jComboBox1.setEnabled(true);
jCheckBox1.setEnabled(true);
statusNum = 0;
nSubClicks = 0;
showGPA();
gradeList.clear();
unitList.clear();
//set all fields editable
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
//Custom Methods - Start
////////////////////////
public void showGPA(){
double gtoN[] = new double[gradeList.size()];
double u[] = new double[unitList.size()];
String intermediate[] = unitList.toArray(new String[unitList.size()]);
DecimalFormat f = new DecimalFormat("#.00");
for(int i = 0;i<gradeList.size();i++){
if(gradeList.get(i).equalsIgnoreCase("a"))
gtoN[i] = 4;
else if(gradeList.get(i).equalsIgnoreCase("b"))
gtoN[i] = 3;
else if(gradeList.get(i).equalsIgnoreCase("c"))
gtoN[i] = 2;
else if(gradeList.get(i).equalsIgnoreCase("d"))
gtoN[i] = 1;
else if(gradeList.get(i).equalsIgnoreCase("e"))
gtoN[i] = 0;
}
for(int j = 0;j<unitList.size();j++){
u[j] = Double.parseDouble(intermediate[j]);
}
jTextArea1.append("\n\n\tGPA: "+f.format(calcGPA(gtoN,u,gtoN.length))+"\n");
}
public double calcGPA(double g[],double u[],int size){
double totalU=0.0,TOTAL=0.0;
double totalP[] = new double[size];
for(int i=0;i<size;i++){
totalP[i] = (g[i]*u[i]);
}
for(double x:u)
totalU+=x;
for(double y: totalP)
TOTAL+=y;
return TOTAL/totalU;
}
////////////////////////
//End
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JCheckBox jCheckBox1;
@SuppressWarnings("rawtypes")
private javax.swing.JComboBox jComboBox1;
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;
@SuppressWarnings("rawtypes")
private javax.swing.JList jList1;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JMenuItem jMenuItem4;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JPopupMenu.Separator jSeparator2;
private javax.swing.JPopupMenu.Separator jSeparator3;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private java.awt.Menu menu1;
private java.awt.Menu menu2;
private java.awt.Menu menu3;
private java.awt.Menu menu4;
private java.awt.Menu menu5;
private java.awt.Menu menu6;
private java.awt.MenuBar menuBar1;
private java.awt.MenuBar menuBar2;
private java.awt.MenuBar menuBar3;
private java.awt.PopupMenu popupMenu1;
// End of variables declaration
}