13 Replies - 8212 Views - Last Post: 16 September 2011 - 08:14 AM Rate Topic: -----

#1 zahid.hstu.java   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-September 11

How to compile sample java code in NetBeans

Posted 16 September 2011 - 03:27 AM

I am new bie in java. learning the concepts theoretically. in the mean time i have downloaded sample java project source code.

Here is the code

https://skydrive.liv...036910FA46D!180

named student_record_information

after compiling it showing me error like


java.lang.NoClassDefFoundError: javaapplication1/Main
Caused by: java.lang.ClassNotFoundException: javaapplication1.Main
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: javaapplication1.Main.  Program will exit.
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)


advance thanks

Is This A Good Question/Topic? 0
  • +

Replies To: How to compile sample java code in NetBeans

#2 GregBrannon   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2250
  • View blog
  • Posts: 5,340
  • Joined: 10-September 10

Re: How to compile sample java code in NetBeans

Posted 16 September 2011 - 03:45 AM

Most beginners with any language start with a simple tutorial to create the almost obligatory "HelloWorld" program. I suggest you start there, using a tutorial that talks you through accomplishing that task in Netbeans, if you must use that as your beginning Java editor. Helping you run code you don't understand in an editor you don't know how to use isn't useful.
Was This Post Helpful? 1
  • +
  • -

#3 zahid.hstu.java   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-September 11

Re: How to compile sample java code in NetBeans

Posted 16 September 2011 - 03:56 AM

Dear,

With respect i would like to say "i must follow your guide." But for this case can you please spend little time for me.

I know it will not help me to learn, but just for mental satisfaction. I want to see it by compiling my self.

thanks
Was This Post Helpful? 0
  • +
  • -

#4 gokulforum   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 06-September 11

Re: How to compile sample java code in NetBeans

Posted 16 September 2011 - 04:36 AM

your error meaning is compiler does not get main class
solution
right click on project name - click on property & click on run option
now set main class - click brows button & select your main class
click ok & now run project
Was This Post Helpful? 1
  • +
  • -

#5 cfoley   User is offline

  • Cabbage
  • member icon

Reputation: 2388
  • View blog
  • Posts: 5,013
  • Joined: 11-December 07

Re: How to compile sample java code in NetBeans

Posted 16 September 2011 - 05:24 AM

Listen to GregBrannon's advice. You won't learn programming by reading a book. I've been programming for 20 years and I still can't learn a new language by reading a book. I know because I've tried it. I read the book, understood it all then sat down to write some code and didn't know where to start. The only way to learn a language is to write code, and tutorials are a very good guide.

For your specific error, it looks like your code compiles OK but when you try and run it, it can't find the main method. If gokulforum's advice doesn't work can you post your javaapplication1/Main.java file here please?

This post has been edited by cfoley: 16 September 2011 - 05:24 AM

Was This Post Helpful? 0
  • +
  • -

#6 zahid.hstu.java   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-September 11

Re: How to compile sample java code in NetBeans

Posted 16 September 2011 - 05:39 AM

Dear gokulforum,

it was good advice by you. still showing one error


java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: Uncompilable source code - cannot find symbol
  symbol:   class SemesterList
  location: class javaapplication1.ViewElements
        at javaapplication1.ViewElements.<clinit>(ViewElements.java:295)
Could not find the main class: javaapplication1.StudRec.  Program will exit.
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)




Dear cfoley,

code it too long to paste here. so i have uploaded it here

http://srishtiweb.com/StudRec.txt

Thanks....
Was This Post Helpful? 0
  • +
  • -

#7 cfoley   User is offline

  • Cabbage
  • member icon

Reputation: 2388
  • View blog
  • Posts: 5,013
  • Joined: 11-December 07

Re: How to compile sample java code in NetBeans

Posted 16 September 2011 - 05:58 AM

In future please post your code in the thread and use the code tags. It's OK even if it is hundreds of lines long!

You need to change the file's name to match the class name. Change the file name to StudRec.java, paying attention to the capitalisation.
Was This Post Helpful? 0
  • +
  • -

#8 zahid.hstu.java   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-September 11

Re: How to compile sample java code in NetBeans

Posted 16 September 2011 - 06:21 AM

Dear cfoley,

i have done it. and same error showing. i am giving the link of screen shoot so that you can check am i right or wrong.

http://srishtiweb.com/forum.png

Also i am uploading the code so it will help you spend 2 minute with it.

http://srishtiweb.co...information.zip

Thanks, hope we will reach to the solution soon.
Was This Post Helpful? 0
  • +
  • -

#9 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12315
  • View blog
  • Posts: 45,414
  • Joined: 27-December 08

Re: How to compile sample java code in NetBeans

Posted 16 September 2011 - 06:28 AM

Post your code here, using code tags. Please don't upload it to other sites.
Was This Post Helpful? 0
  • +
  • -

#10 cfoley   User is offline

  • Cabbage
  • member icon

Reputation: 2388
  • View blog
  • Posts: 5,013
  • Joined: 11-December 07

Re: How to compile sample java code in NetBeans

Posted 16 September 2011 - 06:30 AM

Please post your code in code tags on the forum. Most of us won't download zips.

OK, so the error message has changed. That means one problem is fixed and it is now telling you about another.

The message NetBeans is giving you tells you there is an error in your ViewElements class. Also, if you look at the scrollbar, you will see a red line. That is the location of another compiler error. You need to fix them to be able to run the program.

Sure you wouldn't like to work through a tutorial?
Was This Post Helpful? 0
  • +
  • -

#11 zahid.hstu.java   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-September 11

Re: How to compile sample java code in NetBeans

Posted 16 September 2011 - 06:54 AM

Sorry for my mistake.

it is the main class file. it is showing error in 185 no line


/**
 *@title Computer Studies Division Student Information System
 *@ver 1.2 (BETA)
 *@author Jeshurun Ray Flores
 *@since jdk 1.4, jdk 1.5
 */
package javaapplication1;

import java.io.*;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.table.*;
import javax.swing.event.*;

public class StudRec extends ViewElements
{
  //main
  public static void main(String[] args){
    System.out.println("Loading...");
    try {
      UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception e) {}//*/
    String title = "Computer Studies Division Academc and Student Information System (BETA)";
    JFrame main = new StudRec(title);
    Toolkit thKit = main.getToolkit();
    Dimension wndSze = thKit.getScreenSize();
    main.pack();
    int wd = main.getWidth();
    int ht = main.getHeight();
    int x = (int)((wndSze.getWidth()/2)-(wd/2));
    int y = (int)((wndSze.getHeight()/2)-(ht/2));
    main.setBounds(x,y,wd,ht);
    main.setVisible(true);
    main.setResizable(false);
    main.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
  }
  StudRec(String title){
    super(title);
    System.out.println("setting up user interface\ngathering resources.");
    Container cont = getContentPane();
    System.out.println("loading tables");
    setTabs();
    readFiles();    readMisc();
    setStudTable();
    setSbjTable();
    setEnrTable();
    setGrdTable();
    setLayouts();
    cont.add(tabs);
    addListeners();
    addWindowListener(new winListener());
  }
  //misc methods
  //sets all tabs
  private void setTabs(){
    String[] titles = {"Student Masterlist","All Classes",
                       "Enroll Students","Grades","Registrar Settings"};
    String[] ttips = {"Create new student.","View classes","Student registration",
                      "Edit/View Grades","Registrar Settings"};
    addTabComponents();
    
    tabs.addTab(titles[0],new ImageIcon("icons/clown.gif"),tab1,ttips[0]);
    tabs.addTab(titles[1],new ImageIcon("icons/notes.gif"),tab2,ttips[1]);
    tabs.addTab(titles[2],new ImageIcon("icons/files.gif"),tab3,ttips[2]);
    tabs.addTab(titles[3],new ImageIcon("icons/pencil.gif"),tab4,ttips[3]);
    tabs.addTab(titles[4],new ImageIcon("icons/lock.gif"),tab5,ttips[4]);
    
  }
  //adds all components to each tab
  private void addTabComponents(){
    //tab1
    tab1.add(lb1add);			tab1.add(lb1cm);
    tab1.add(lb1id);			tab1.add(tf1id);
    tab1.add(lb1nme);			tab1.add(tf1ln);
    tab1.add(tf1fn);			tab1.add(tf1mi);
    tab1.add(lb1mn);			tab1.add(tf1mn);
    tab1.add(bt1rst);			tab1.add(bt1ok);
    tab1.add(bt1edit);		tab1.add(bt1del);
    tab1.add(lb1fn);			tab1.add(lb1ln);
    tab1.add(lb1mi);
    tf1id.setEditable(false);
    tf1mi.setEditable(false);
    
    //tab2
    tab2.add(lb2sbj);			tab2.add(cb2maj);
    tab2.add(lb2cd);			tab2.add(tf2cd);
    tab2.add(lb2unt);			tab2.add(tf2unt);
    tab2.add(lb2desc);		tab2.add(tf2desc);
    tab2.add(bt2rst);			tab2.add(bt2ok);
    tab2.add(bt2del);			tab2.add(bt2edit);
    tab2.add(lb2msg);

    //tab3
    tab3.add(lb3sbj);			tab3.add(bt3add);
    tab3.add(bt3op);
    bt3op.setEnabled(false);
   
    //tab4
    tab4.add(lb4grd);			
    tab4.add(lb4id);			tab4.add(tf4id);
    tab4.add(lb4nme);			tab4.add(tf4ln);
    tab4.add(tf4fn);			tab4.add(tf4mi);
    tab4.add(lb4crs);			tab4.add(tf4crs);
    tab4.add(lb4yr);			tab4.add(tf4yr);
    tab4.add(bt4egrd);
    tf4id.setEditable(false);	tf4mi.setEditable(false);
    tf4ln.setEditable(false);	tf4crs.setEditable(false);
    tf4yr.setEditable(false); tf4fn.setEditable(false);
    
    //tab5
    tab5.add(lb5st);
    tab5.add(lb5sy);		tab5.add(sr5sy);
    tab5.add(lb5sem);		tab5.add(cb5sem);
    tab5.add(bt5ok);
    
    
  }
  //add listeners to all components in tabs
  private void addListeners(){
    //buttons
    bt1ok.addActionListener(new ButtonListener());
    bt1rst.addActionListener(new ButtonListener());
    bt1edit.addActionListener(new ButtonListener());
    bt1del.addActionListener(new ButtonListener());
    bt2ok.addActionListener(new ButtonListener());
    bt2rst.addActionListener(new ButtonListener());
    bt2edit.addActionListener(new ButtonListener());
    bt2del.addActionListener(new ButtonListener());
    bt3add.addActionListener(new ButtonListener());
    bt3op.addActionListener(new ButtonListener());
    bt4egrd.addActionListener(new ButtonListener());
    bt5ok.addActionListener(new ButtonListener());
    
    //tables
    ListSelectionModel tbModel = tb1stud.getSelectionModel();
    tbModel.addListSelectionListener(new StudTableListener());
    tbModel = tb2sbj.getSelectionModel();
    tbModel.addListSelectionListener(new SubjTableListener());
    tbModel = tb3stud.getSelectionModel();
    tbModel.addListSelectionListener(new EnrTableListener());
    tbModel = tb4grd.getSelectionModel();
    tbModel.addListSelectionListener(new GrdTableListener());
    
    //keylisteners
    tf1mn.addKeyListener(new KeyboardListener());
  }
  //file handling routines
  //read/write main files
  static void writeFiles(){
    try{
      FileOutputStream outStream;
      ObjectOutputStream ooStream;

      outStream = new FileOutputStream("StudentList.dat");
      ooStream = new ObjectOutputStream(outStream);
      
      ooStream.writeObject(StdList);
      ooStream.flush();
      outStream.close();
      
      
      outStream = new FileOutputStream("SemesterList.dat");
      ooStream = new ObjectOutputStream(outStream);
      
      ooStream.writeObject(SemList);
      ooStream.flush();
      outStream.close();
      System.out.println("files saved");
      
    }
    catch (IOException exc){System.out.println("Error writing file!");}
  }
  static void readFiles(){
    try{
      FileInputStream inStream;
      ObjectInputStream oiStream;
      
      try{
        inStream = new FileInputStream("SemesterList.dat");
        oiStream = new ObjectInputStream(inStream);
       
        SemList = (SemesterList)oiStream.readObject();
      }
      catch(FileNotFoundException exc){
        System.out.println("semlist not found.");
        sr5sy.setValue(new Integer(2005));
        cb5sem.setValue(new Integer(1));
        int sy = Integer.parseInt(""+sr5sy.getValue());
        int sem = Integer.parseInt(""+cb5sem.getValue());
        Semester temp = new Semester(sy,sem);
        currentSem = temp;
        SemList.put(currentSem.getSemCode(),currentSem);
      }
      
      inStream = new FileInputStream("StudentList.dat");
      oiStream = new ObjectInputStream(inStream);
      
      StdList = (StudentList)oiStream.readObject();
      
      System.out.println("files reloaded.");
    }
    catch (FileNotFoundException exc){
      System.out.println("File/s not found!");
      writeMisc();
    }
    catch(IOException exc){
      System.out.println("Error reading file! Creating new database.");
      sr5sy.setValue(new Integer(2005));
      cb5sem.setValue(new Integer(1));
      int sy = Integer.parseInt(""+sr5sy.getValue());
      int sem = Integer.parseInt(""+cb5sem.getValue());
      Semester temp = new Semester(sy,sem);
      currentSem = temp;
      SemList.put(currentSem.getSemCode(),currentSem);
      writeMisc();
    }
    catch(ClassNotFoundException exc){
      System.out.println("Class not found.");
    }
  }
  //read/write miscellaneous files
  static void writeMisc(){
    String settings = Student.getCount()+" ";
    String semset = currentSem.getSemCode()+" ";
    try{
      FileWriter outStream = new FileWriter("misc.inf");
      outStream.write(settings+"\n");
      outStream.write(semset);
      outStream.close();
      System.out.println("miscellaneous files saved.");
    }
    catch(IOException exc){System.out.println("error writing misc file.");}
  }
  static void readMisc(){
    try{
      BufferedReader inStream = new BufferedReader(new FileReader("misc.inf"));
      
      int setThis = Integer.parseInt(inStream.readLine().trim());
      Student.setInitialCount(setThis);
      
      String semCode = inStream.readLine().trim();
      currentSem = (Semester)SemList.get(semCode);
      sr5sy.setValue(new Integer(currentSem.getSchoolYear()));
      cb5sem.setValue(new Integer(currentSem.getSem()));
      System.out.println("miscellaneous files reloaded.");
    }
    catch(IOException exc){
      System.out.println("Error reading misc file");
      writeMisc();
    }
  }
  /********** model ***********/
  
  //table models for each table on tabs
  public void setStudTable(){
    tb1stud = new JTable(new StudModel());
    sp1stud = new JScrollPane(tb1stud);
    tab1.add(sp1stud);
    tb1stud.setPreferredScrollableViewportSize(new Dimension(600,200));
    tb1stud.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    bt1edit.setEnabled(false);
    bt1del.setEnabled(false);
    bt2edit.setEnabled(false);
    bt2del.setEnabled(false);
    bt4egrd.setEnabled(false);
  }
  public void setSbjTable(){
    tb2sbj = new JTable(new SbjModel());
    sp2sbj = new JScrollPane(tb2sbj);
    tab2.add(sp2sbj);
    tb2sbj.setPreferredScrollableViewportSize(new Dimension(600,220));
    tb2sbj.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  }
  public void setEnrTable(){
    tb3stud = new JTable(new EnrModel());
    sp3stud = new JScrollPane(tb3stud);
    tab3.add(sp3stud);
    tb3stud.setPreferredScrollableViewportSize(new Dimension(755,300));
    tb3stud.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  }
  public void setGrdTable(){
    tb4grd = new JTable(new EnrModel());
    sp4grd = new JScrollPane(tb4grd);
    tab4.add(sp4grd);
    tb4grd.setPreferredScrollableViewportSize(new Dimension(600,200));
    tb4grd.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  }
  static class StudModel extends AbstractTableModel {
    private String[] columnNames = {"ID NUMBER","FAMILY NAME","FIRST NAME"};
    private Object[][] data = storeObject();
    
    private Object[][] storeObject(){
      Vector vect = StdList.sort();
      Object[][] temp = new Object[vect.size()][3];
      
      for(int a=0;a<vect.size();a++){
        Student temp2 = (Student)vect.elementAt(a);
        temp[a][0] = temp2.getIdNumber();
        temp[a][1] = temp2.getLastName();
        temp[a][2] = temp2.getFirstName();
      }
      return temp;
    }
    public Object[][] getData(){
      return data;
    }
    public int getColumnCount() {
      return columnNames.length;
    }
    public int getRowCount() {
      return data.length;
    }
    public String getColumnName(int col) {
      return columnNames[col];
    }
    public Object getValueAt(int row, int col) {
      return data[row][col];
    }
    public boolean isCellEditable(int row, int col) {
      return false;
    }
  }
  static class SbjModel extends AbstractTableModel {
    private String[] columnNames = {"SUBJECT CODE","SUBJECT DESCRIPTION","UNITS","MAJOR?"};
    private Object[][] data = storeObject();
    
    private Object[][] storeObject(){
      Hashtable subjects = currentSem.getSubjectsOpen();
      Set sKeys = subjects.keySet();
      Vector keys = new Vector(sKeys);
      Collections.sort(keys);
      Object[][] temp = new Object[keys.size()][4];
      int a=0;
      for(Iterator i=keys.iterator();i.hasNext();a++){
        String thisKey = ""+i.next();
        Subject temp2 = (Subject)subjects.get(thisKey);
        
        temp[a][0] = temp2.getCode();
        temp[a][1] = temp2.getDescription();
        temp[a][2] = ""+temp2.getUnits();
        if(temp2.isMajor())
          temp[a][3] = "YES";
        else
          temp[a][3] = "NO";
      }
      return temp;
    }
    public int getColumnCount() {
      return columnNames.length;
    }
    public int getRowCount() {
      return data.length;
    }
    public String getColumnName(int col) {
      return columnNames[col];
    }
    public Object getValueAt(int row, int col) {
      return data[row][col];
    }
    public boolean isCellEditable(int row, int col) {
      return false;
    }
  }
  static class EnrModel extends AbstractTableModel {
    private String[] columnNames = {"ID NUMBER","STUDENT NAME","YEAR","COURSE"};
    private Object[][] data = storeObject();
        
    private Object[][] storeObject(){
      Hashtable students = currentSem.getStudentsEnrolled();
      Set sKeys = students.keySet();
      Vector keys = new Vector(sKeys);
      Collections.sort(keys);
      Object[][] temp = new Object[keys.size()][4];
      
      int a=0;
      for(Iterator i=keys.iterator();i.hasNext();a++){
        String thisKey = ""+i.next();
        Student temp2 = (Student)students.get(thisKey);
        Person temp3 = new Person(temp2.getFirstName(),
                                  temp2.getLastName(),
                                  temp2.getMiddleName());
        temp[a][0] = temp2.getIdNumber();
        temp[a][1] = temp3;
        temp[a][2] = ""+temp2.getYear();
        temp[a][3] = temp2.getCourse();
      }
      return temp;
    }
    public int getColumnCount() {
      return columnNames.length;
    }
    public int getRowCount() {
      return data.length;
    }
    public String getColumnName(int col) {
      return columnNames[col];
    }
    public Object getValueAt(int row, int col) {
      return data[row][col];
    }
    public boolean isCellEditable(int row, int col) {
      return false;
    }
  }
  /********** controller ***********/
  //component listeners
  private class ButtonListener implements ActionListener{
    public void actionPerformed(ActionEvent e){
      //tab1
      if(e.getSource()==bt1ok){
        String fn = tf1fn.getText().trim().toUpperCase();
        String ln = tf1ln.getText().trim().toUpperCase();
        String mn = tf1mn.getText().trim().toUpperCase();
        Student temp = new Student(fn,ln,mn);
        StdList.put(temp.getIdNumber(),temp);
        tf1id.setText(temp.getIdNumber());
        writeFiles();  readFiles();
        writeMisc();   readMisc();
        tb1stud.setModel(new StudModel());
        System.out.println("new student added to masterlist");
      }
      if(e.getSource()==bt1rst){
        tf1fn.setEditable(true);
        tf1ln.setEditable(true);
        tf1mn.setEditable(true);
        bt1ok.setEnabled(true);
        clearTab1();
      }
      if(e.getSource()==bt1edit){
        stddlg = new EditStudentDialog(fmestd,selectedStd);
        stddlg.show();
      }
      if(e.getSource()==bt1del){
        StdList.remove(selectedStd.getIdNumber());
        writeFiles();  readFiles();
        tb1stud.setModel(new StudModel());
        System.out.println("student deleted from masterlist.");
      }
      
      //tab2
      if(e.getSource()==bt2ok){
        lb2msg.setText("");
        try{
          String cd = tf2cd.getText().trim().toUpperCase();
          String desc = tf2desc.getText().trim().toUpperCase();
          int units = Integer.parseInt(tf2unt.getText().trim());
          if(units>0){
            Subject temp = new Subject(cd,desc);
            
            if(cb2maj.isSelected())
              temp.setAsMajor(true);
            else
              temp.setAsMajor(false);
            temp.setUnits(units);
            currentSem.openSubject(temp);
            SemList.put(currentSem.getSemCode(),currentSem);
            writeFiles();  readFiles();
            tb2sbj.setModel(new SbjModel());
            cb2maj.setEnabled(true);
            System.out.println("new subject opened");
            clearTab2();
          }
        }
        catch(NumberFormatException exc){
          lb2msg.setText("Please Enter Correct Number of Units.");
        }
      }
      if(e.getSource()==bt2rst){
        tb2sbj.clearSelection();
        tf2cd.setEditable(true);
        tf2desc.setEditable(true);
        bt2ok.setEnabled(true);
        cb2maj.setEnabled(true);
        cb2maj.setSelected(false);
        tf2unt.setEditable(true);
        clearTab2();
      }
      if(e.getSource()==bt2edit){
        sbjdlg = new EditSubjectDialog(fmesbj,selectedSbj);
        sbjdlg.show();
      }
      if(e.getSource()==bt2del){
        currentSem.closeSubject(selectedSbj.getCode());
        SemList.put(currentSem.getSemCode(),currentSem);
        writeFiles();  readFiles();
        tb2sbj.setModel(new SbjModel());
        System.out.println("subject deleted.");
      }
      
      //tab3
      if(e.getSource()==bt3add){
        enrdlg = new EnrollDialog(fmnenr);
        enrdlg.show();
      }
      if(e.getSource()==bt3op){
        regdlg = new RegistryDialog(fmrreg,selectedStd);
        regdlg.show();
      }
      
      //tab4
      if(e.getSource()==bt4egrd){
        grddlg = new GradesDialog(fmggrd,selectedStd);
        grddlg.show();
      }
      
      //tab5
      if(e.getSource()==bt5ok){
        writeFiles();	readFiles();
        int sy  = Integer.parseInt(""+sr5sy.getValue());
        int sem = Integer.parseInt(""+cb5sem.getValue());
        Semester temp = new Semester(sy,sem);
        System.out.println(SemList.containsKey(temp.getSemCode()));
        if(SemList.containsKey(temp.getSemCode())){
          System.out.println("changing semester");
          currentSem = (Semester)SemList.get(temp.getSemCode());
        }
        else{
          System.out.println("openning new semester");
          currentSem = temp;
          SemList.put(temp.getSemCode(),temp);
        }
        tb2sbj.setModel(new SbjModel());
        tb3stud.setModel(new EnrModel());
        tb4grd.setModel(new EnrModel());
        writeFiles();	readFiles();
        writeMisc();	readMisc();
        tabs.setSelectedIndex(2);
        System.out.println("semester updated");
      }
    }
  }
  private class StudTableListener implements ListSelectionListener {
    public void valueChanged(ListSelectionEvent e) {

     if(e.getValueIsAdjusting()) return;
     ListSelectionModel lsm = (ListSelectionModel)e.getSource();
     if(lsm.isSelectionEmpty()) {
       selectedStd=null;
       bt1edit.setEnabled(false);
       bt1del.setEnabled(false);
     }
     else {
       bt1edit.setEnabled(true);
       bt1del.setEnabled(true);
       int selectedRow = lsm.getMinSelectionIndex();
       StudModel tempMod = new StudModel();
       String id = ""+tempMod.getValueAt(selectedRow,0);
       selectedStd = (Student)StdList.get(id);
       tf1id.setText(id);
       tf1fn.setText(selectedStd.getFirstName());
       tf1ln.setText(selectedStd.getLastName());
       tf1mi.setText(selectedStd.getMiddleInitial());
       tf1mn.setText(selectedStd.getMiddleName());
       tf1fn.setEditable(false);
       tf1ln.setEditable(false);
       tf1mn.setEditable(false);
       bt1ok.setEnabled(false);
     }
    }
  }
  private class SubjTableListener implements ListSelectionListener {
    public void valueChanged(ListSelectionEvent e) {
     if(e.getValueIsAdjusting()) return;
     
     ListSelectionModel lsm = (ListSelectionModel)e.getSource();
     if(lsm.isSelectionEmpty()) {
       selectedSbj=null;
       clearTab2();
       bt2edit.setEnabled(false);
       bt2del.setEnabled(false);
       cb2maj.setEnabled(false);
       tf2unt.setEditable(false);
     }
     else {
       bt2edit.setEnabled(true);
       bt2del.setEnabled(true);
       cb2maj.setEnabled(true);
       tf2unt.setEditable(true);
       int selectedRow = lsm.getMinSelectionIndex();
       SbjModel tempMod = new SbjModel();
       String code = ""+tempMod.getValueAt(selectedRow,0);
       Hashtable SbjList = currentSem.getSubjectsOpen();
       selectedSbj = (Subject)SbjList.get(code);
       tf2cd.setText(code);
       tf2desc.setText(selectedSbj.getDescription());
       tf2unt.setText(""+selectedSbj.getUnits());
       if(selectedSbj.isMajor())
         cb2maj.setSelected(true);
       else
         cb2maj.setSelected(false);
       tf2cd.setEditable(false);
       tf2desc.setEditable(false);
       cb2maj.setEnabled(false);
       bt2ok.setEnabled(false);
       tf2unt.setEditable(false);
     }
    }
  }
  private class EnrTableListener implements ListSelectionListener {
    public void valueChanged(ListSelectionEvent e) {
      if(e.getValueIsAdjusting()) return;
     
      ListSelectionModel lsm = (ListSelectionModel)e.getSource();
      if(lsm.isSelectionEmpty()) {
        bt3op.setEnabled(false);
      }
      else {
        bt3op.setEnabled(true);
        int selectedRow = lsm.getMinSelectionIndex();
        EnrModel tempMod = new EnrModel();  
        String id = ""+tempMod.getValueAt(selectedRow,0);
        Hashtable StudList = currentSem.getStudentsEnrolled();
        Student temp = (Student)StudList.get(id);
        selectedStd = temp;
      }
    }
  }
  private class GrdTableListener implements ListSelectionListener {
    public void valueChanged(ListSelectionEvent e) {
      if(e.getValueIsAdjusting()) return;
     
      ListSelectionModel lsm = (ListSelectionModel)e.getSource();
      if(lsm.isSelectionEmpty()) {
        bt4egrd.setEnabled(false);
        clearTab4();
      }
      else {
        bt4egrd.setEnabled(true);
        int selectedRow = lsm.getMinSelectionIndex();
        EnrModel tempMod = new EnrModel();
        String id = ""+tempMod.getValueAt(selectedRow,0);
        Hashtable ht = currentSem.getStudentsEnrolled();
        Student stud = (Student)ht.get(id);
        tf4id.setText(stud.getIdNumber());
        tf4ln.setText(stud.getLastName());
        tf4fn.setText(stud.getFirstName());
        tf4mi.setText(stud.getMiddleInitial());
        tf4crs.setText(stud.getCourse());
        tf4yr.setText(""+stud.getYear());
        selectedStd = stud;
      }
    }
  }
  private class winListener extends WindowAdapter {
    public void windowClosing(WindowEvent we) {
      Object[] options = { "YES", "NO" };
      int option = JOptionPane.showOptionDialog(null, "Are you sure you want to exit?","EXIT",
                   JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,
                   null, options, options[0]);
      if (option == JOptionPane.OK_OPTION){
        System.out.println("Thank You For Using Me.. :D/>");
        System.exit(0);
      }
    }
  }
  private class KeyboardListener implements KeyListener{
    public void keyTyped(KeyEvent e){
    }
    public void keyReleased(KeyEvent e){
      try{
        String temp = tf1mn.getText();
        String temp2 = ""+temp.toUpperCase().charAt(0)+".";
        tf1mi.setText(temp2);
      }
      catch(StringIndexOutOfBoundsException exc){
        tf1mi.setText("");
      }
    }
    public void keyPressed(KeyEvent e){
    }
  }
}



and it is the ViewElements.java file, it is shwing an error in 295 no line

package javaapplication1;

import java.io.*;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.table.*;

public class ViewElements extends JFrame
{
	
  ViewElements(String title){
	  super(title);
	  setLookFontsAndColors();
	}
  //misc methods
  //resets/clears tab1
  public void clearTab1(){
    tf1id.setText("");
    tf1ln.setText("");
    tf1fn.setText("");
    tf1mi.setText("");
    tf1mn.setText("");
  }
  //resets/clears tab2
  public void clearTab2(){
    tf2cd.setText("");
    tf2desc.setText("");
    tf2unt.setText("");
    cb2maj.setSelected(false);
  }
  //resets/clears tab4
  public void clearTab4(){
    tf4id.setText("");
    tf4ln.setText("");
    tf4fn.setText("");
    tf4mi.setText("");
    tf4crs.setText("");
    tf4yr.setText("");
  }
  

  EasierGridLayout layout = new EasierGridLayout();
  
  //set layout of all components
  public void setLayouts(){
    tab1.setLayout(layout);
    tab2.setLayout(layout);
    tab3.setLayout(layout);
    tab4.setLayout(layout);
    tab5.setLayout(layout);

    //tab1
    layout.setConstraints(lb1ln,4,2,1,1);
    layout.setConstraints(lb1fn,4,4,1,1);
    layout.setConstraints(lb1mi,4,5,1,1);
    
    layout.setConstraints(sp1stud,6,1,7,1);
    layout.setConstraints(lb1nme,3,1,1,1);
    layout.setConstraints(lb1mn,5,1,1,1);
    layout.setConstraints(tf1mn,5,2,1,1);
    layout.setConstraints(bt1rst,5,6,1,1);
    layout.setConstraints(bt1ok,5,7,1,1);
    layout.setConstraints(bt1del,8,7,1,1);
    layout.setConstraints(bt1edit,8,6,1,1);
    layout.defineOwnConstraints(tf1ln, 3,2,1,1, 0,0, 1,17, 3,3,3,3);
    layout.defineOwnConstraints(tf1fn, 3,4,1,1, 0,0, 1,17, 3,3,3,3);
    layout.defineOwnConstraints(tf1mi, 3,5,1,1, 0,0, 1,17, 3,3,3,3);
    layout.defineOwnConstraints(lb1cm, 3,4,1,1, 0,0, 0,17, 0,0,0,5);
    layout.defineOwnConstraints(lb1id, 2,1,1,1, 0,0, 0,17, 5,3,5,22);
    layout.defineOwnConstraints(lb1add, 1,1,7,1, 0,0, 0,10, 10,0,0,10);
    layout.defineOwnConstraints(tf1id, 2,2,1,1, 0,0, 0,17, 3,3,5,20);
   
    //tab2
    layout.setConstraints(sp2sbj,7,1,7,1);
    layout.setConstraints(lb2desc,4,1,6,1);
    layout.setConstraints(bt2edit,8,6,1,1);
    layout.setConstraints(bt2del,8,7,1,1);
    layout.setConstraints(lb2unt,3,3,1,1);
    layout.setConstraints(tf2unt,3,4,1,1);
    layout.setConstraints(lb2msg,6,1,4,1);
    layout.defineOwnConstraints(cb2maj, 3,5,1,1, 0,0, 0,15, 0,0,40,0);
    layout.defineOwnConstraints(lb2cd, 3,1,1,1, 0,0, 0,17, 0,3,0,0);
    layout.defineOwnConstraints(tf2cd, 3,2,1,1, 50,0, 0,17, 0,5,0,0);
    layout.defineOwnConstraints(lb2sbj, 1,1,8,1, 0,0, 0,15, 10,0,0,10);
    layout.defineOwnConstraints(bt2rst, 6,6,1,1, 0,0, 0,10, 5,10,10,10);
    layout.defineOwnConstraints(bt2ok, 6,7,1,1, 0,0, 0,10, 5,10,10,10);
    layout.defineOwnConstraints(tf2desc, 5,1,7,1, 0,0, 0,10, 0,0,20,0);
    
    //tab3
    layout.setConstraints(sp3stud,3,1,2,1);
    layout.defineOwnConstraints(lb3sbj,1,1,2,1, 0,0, 0,10, 10,0,0,10);
    layout.defineOwnConstraints(bt3add,2,2,1,1, 0,0, 0,13, 3,0,5,0);
    layout.defineOwnConstraints(bt3op,4,1,2,1, 0,0, 0,13, 0,0,3,5);
    
    //tab4
    layout.setConstraints(lb4id,2,1,1,1);
    layout.setConstraints(tf4id,2,2,1,1);
    layout.setConstraints(lb4nme,3,1,1,1);
    layout.setConstraints(lb4crs,4,1,1,1);
    layout.setConstraints(tf4crs,4,2,1,1);
    layout.setConstraints(lb4yr,5,1,1,1);
    layout.setConstraints(tf4yr,5,2,1,1);
    layout.setConstraints(sp4grd,6,1,6,1);
    layout.setConstraints(bt4egrd,7,6,1,1);
    layout.defineOwnConstraints(tf4ln,3,2,1,1, 0,0, 1,17, 0,3,2,0);
    layout.defineOwnConstraints(tf4fn,3,3,1,1, 0,0, 1,17, 0,2,2,0);
    layout.defineOwnConstraints(tf4mi,3,4,1,1, 0,0, 0,17, 0,2,2,0);
    layout.defineOwnConstraints(lb4grd,1,1,6,1, 0,0, 0,10, 10,0,0,10);
    
    //tab5
    layout.defineOwnConstraints(lb5st,1,1,2,1, 0,0, 0,10, 10,0,0,0);
    layout.defineOwnConstraints(lb5sy,2,1,1,1, 0,0, 0,13, 3,0,0,30);
    layout.defineOwnConstraints(lb5sem,3,1,1,1, 0,0, 0,13, 0,0,0,3);
    layout.defineOwnConstraints(sr5sy,2,2,1,1, 0,0, 2,15, 3,10,0,30);
    layout.defineOwnConstraints(cb5sem,3,2,1,1, 0,0, 2,15, 0,10,0,3);
    layout.defineOwnConstraints(bt5ok,4,1,2,1, 0,0, 1,10, 80,0,0,10);
    
    System.out.println("layouts loaded.");
  }
  //set font and colors
  public void setLookFontsAndColors(){
    //headers
    Font fhdr = new Font("Book Antiqua",Font.BOLD,22);
    Color fclr = new Color(95,95,50);
    lb1add.setFont(fhdr);
    lb2sbj.setFont(fhdr);
    lb3sbj.setFont(fhdr);
    lb4grd.setFont(fhdr);
    lb5st.setFont(fhdr);
    
    lb1add.setForeground(fclr);
    lb2sbj.setForeground(fclr);
    lb3sbj.setForeground(fclr);
    lb4grd.setForeground(fclr);
    lb5st.setForeground(fclr);
    
    //labels
    Font flbl = new Font("Century Gothic", 1, 12);
    lb1id.setFont(flbl);
    lb1nme.setFont(flbl);
    lb1mn.setFont(flbl);
    lb1fn.setFont(flbl);
    lb1ln.setFont(flbl);
    lb1mi.setFont(flbl);
    lb1cm.setFont(flbl);
    
    lb2cd.setFont(flbl);
    lb2unt.setFont(flbl);
    lb2desc.setFont(flbl);
    
    lb4id.setFont(flbl);
    lb4nme.setFont(flbl);
    lb4crs.setFont(flbl);
    lb4yr.setFont(flbl);

    lb5sy.setFont(flbl);
    lb5sem.setFont(flbl);


    //text fields
    tf1id.setFont(flbl);
    tf4id.setFont(flbl);
    
    Font ftf = new Font("Century Gothic",0,12);
    
    tf1id.setFont(ftf);
    tf1ln.setFont(ftf);
    tf1fn.setFont(ftf);
    tf1mi.setFont(ftf);
    tf1mn.setFont(ftf);

    tf2cd.setFont(ftf);
    tf2unt.setFont(ftf);
    tf2desc.setFont(ftf);
    
    tf4id.setFont(flbl);
    tf4ln.setFont(ftf);
    tf4fn.setFont(ftf);
    tf4mi.setFont(ftf);
    tf4crs.setFont(ftf);
    tf4yr.setFont(ftf);
    
    lb2msg.setFont(new Font("Century Gothic",3,12));
    lb2msg.setForeground(new Color(190,0,0));
  }

  //main
  JTabbedPane tabs = new JTabbedPane();
  JPanel mainPanel = new JPanel();

  static Student selectedStd;
  static Subject selectedSbj;
  static Semester currentSem;

  //tab1
  static JTable  tb1stud;
  JScrollPane    sp1stud;
  JPanel         tab1     = new JPanel();
  JLabel         lb1add   = new JLabel("CREATE NEW STUDENT REGISTRATION",JLabel.CENTER);
  JLabel         lb1id    = new JLabel("ID Number:");
  JTextField     tf1id    = new JTextField(5);
  JLabel         lb1nme   = new JLabel("Student Name ");
  JTextField     tf1ln    = new JTextField(3);
  JLabel         lb1cm    = new JLabel(",",JLabel.LEFT);
  JTextField     tf1fn    = new JTextField(25);
  JTextField     tf1mi    = new JTextField(2);
  JLabel         lb1mn    = new JLabel("Middle Name:");
  JTextField     tf1mn    = new JTextField(13);
  JButton        bt1ok    = new JButton("SAVE");
  JButton        bt1rst   = new JButton("NEW");
  JButton        bt1del   = new JButton("DELETE");
  JButton        bt1edit  = new JButton("EDIT");
  JLabel         lb1fn    = new JLabel("First Name");
  JLabel         lb1ln    = new JLabel("Last Name");
  JLabel         lb1mi    = new JLabel("MI");

  //edit student
  EditStudentDialog stddlg;
  JFrame         fmestd   = new JFrame("Edit Student");

  //tab2
  static JTable  tb2sbj;
  JScrollPane    sp2sbj;
  JPanel         tab2     = new JPanel();
  JLabel         lb2sbj   = new JLabel("OPEN NEW SUBJECTS");
  JLabel         lb2cd    = new JLabel("SUBJECT CODE:");
  JTextField     tf2cd    = new JTextField(10);
  JLabel         lb2unt   = new JLabel("UNITS:");
  JTextField     tf2unt   = new JTextField(2);
  JCheckBox      cb2maj   = new JCheckBox("Set as Major?");
  JLabel         lb2desc  = new JLabel("SUBJECT DESCRIPTION:");
  JTextField     tf2desc  = new JTextField(45);
  JButton        bt2ok    = new JButton("SAVE");
  JButton        bt2rst   = new JButton("NEW");
  JButton        bt2del   = new JButton("DELETE");
  JButton        bt2edit  = new JButton("EDIT");
  JLabel         lb2msg   = new JLabel();
  
  //edit subject
  EditSubjectDialog sbjdlg;
  JFrame            fmesbj   = new JFrame("Edit Subject");
  
  //tab3
  static JTable  tb3stud;
  JScrollPane    sp3stud;
  JPanel         tab3     = new JPanel();
  JLabel         lb3sbj   = new JLabel("ENROLLMENT AND RESERVATIONS",JLabel.CENTER);
  JButton        bt3add   = new JButton("Add new enrollee");
  JButton        bt3op    = new JButton("Open Student Registration");
  
  //enroll student
  EnrollDialog   enrdlg;
  JFrame         fmnenr   = new JFrame("Student Enrollment");
  
  //student registry
  RegistryDialog regdlg;
  JFrame         fmrreg   = new JFrame();
  
  //tab4
  static JTable  tb4grd;
  JScrollPane    sp4grd;
  JPanel         tab4     = new JPanel();
  JLabel         lb4grd   = new JLabel("STUDENT REGISTRY",JLabel.CENTER);
  JLabel         lb4id    = new JLabel("ID Number");
  JTextField     tf4id    = new JTextField(15);
  JLabel         lb4nme   = new JLabel("Full Name");
  JTextField     tf4ln    = new JTextField(3);
  JTextField     tf4fn    = new JTextField(25);
  JTextField     tf4mi    = new JTextField(3);
  JLabel         lb4crs   = new JLabel("Course");
  JTextField     tf4crs   = new JTextField(10);
  JLabel         lb4yr    = new JLabel("Year");
  JTextField     tf4yr    = new JTextField(2);
  JButton        bt4egrd  = new JButton("EDIT/VIEW GRADES");
  
  //grades
  GradesDialog   grddlg;
  JFrame         fmggrd   = new JFrame();
  
  //tab5
  JPanel         tab5     = new JPanel();
  JLabel         lb5st    = new JLabel("REGISTRAR SETTINGS");
  JLabel         lb5sy    = new JLabel("School Year");
  JLabel         lb5sem   = new JLabel("Semester");
  JButton        bt5ok    = new JButton("UPDATE");

  static JSpinner     sr5sy  = new JSpinner();
  static SpinnerModel mod1   = new SpinnerNumberModel(1,1,3,1);
  static JSpinner     cb5sem = new JSpinner(mod1);

  //models and lists
  static StudentList StdList = new StudentList();
  static SemesterList SemList = new SemesterList();
}


Was This Post Helpful? 0
  • +
  • -

#12 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12315
  • View blog
  • Posts: 45,414
  • Joined: 27-December 08

Re: How to compile sample java code in NetBeans

Posted 16 September 2011 - 07:25 AM

So what exactly are the errors? Post them exactly from your compiler.

Also, it isn't good practice to use static for your JComponents or data. You should really separate the program state and data from the GUI. Create a Singleton StateManager class to manage the state and data, and have the GUI get/set the appropriate elements. In ViewElements, why do you extend JFrame and have a JFrame in there? Your code could be refactored to be more OO.
Was This Post Helpful? 0
  • +
  • -

#13 zahid.hstu.java   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-September 11

Re: How to compile sample java code in NetBeans

Posted 16 September 2011 - 07:59 AM

so many thanks for your time and finally got resolved myself.

i am so happy with your urgent, and great valuable response ....
Was This Post Helpful? 0
  • +
  • -

#14 cfoley   User is offline

  • Cabbage
  • member icon

Reputation: 2388
  • View blog
  • Posts: 5,013
  • Joined: 11-December 07

Re: How to compile sample java code in NetBeans

Posted 16 September 2011 - 08:14 AM

OK. Glad yo fixed it. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1