Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
284 views
in Technique[技术] by (71.8m points)

swing - Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Not supported yet

I'm trying to input some details about student to the program. when i press the save button its giving an exception error like this,

"Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Not supported yet."


public static ArrayList<Student> arrayStudent = new ArrayList<Student>();

public static void Student(Student student){
    try{
        BufferedWriter buffer = new BufferedWriter(new FileWriter("Students.txt", true));

        buffer.write("Name : "+student.getFirstName()+" "+student.getSurname()+"
NIC No : "+student.getNICNo()+" "+"
Batch Code : "+student.getBatchCode()+" "+"
Student No : "+student.getStudentNo()+" "+"
Telephone No : "+student.getTelNo());
        buffer.newLine();
        buffer.close();
    }
    catch(IOException ex){
        Logger.getLogger(Arraylists.class.getName()).log(Level.SEVERE, null, ex);
}


 public class addStudent extends JFrame {

public addStudent() {
    initComponents();
    setTitle("Add Student");
    setBounds(0, 0, 410, 550);
    setIcon();
    getContentPane().setBackground(Color.BLACK);
    jTextField1.setText("");
    jTextField2.setText("");
    jTextField4.setText("");
    jTextField5.setText("");
    jTextField6.setText("");
    jTextField7.setText("");
}

public void addStudent(){
    Student newStudent= new Student();

    newStudent.setFirstName(jTextField1.getText());
    newStudent.setSurname(jTextField2.getText());
    newStudent.setNICNo(jTextField4.getText());
    newStudent.setBatchCode(jTextField5.getText());
    newStudent.setStudentNo(jTextField6.getText());
    newStudent.setTelNo(jTextField7.getText());
}

public boolean checkEmpty(){
    boolean checkEmpty = false;
    if(jTextField1.getText().isEmpty()||jTextField1.getText().isEmpty()||jTextField2.getText().isEmpty()||jTextField4.getText().isEmpty()||jTextField5.getText().isEmpty()||jTextField6.getText().isEmpty()||jTextField7.getText().isEmpty())
    {
        checkEmpty = true;
    }
    return checkEmpty;
}                     

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    Student newStudent = new Student();

    newStudent.setFirstName(jTextField1.getText());
    newStudent.setSurname(jTextField2.getText());
    newStudent.setNICNo(jTextField4.getText());
    newStudent.setBatchCode(jTextField5.getText());
    newStudent.setStudentNo(jTextField6.getText());
    newStudent.setTelNo(jTextField7.getText());

    if(checkEmpty()){
        JPanel msg = new JPanel();
        JOptionPane.showMessageDialog(msg, "Please Fill all the Fields!", "Error", JOptionPane.ERROR_MESSAGE);
    }

    else{
        addStudent();
        Arraylists.arrayStudent.add(newStudent);

        JPanel msg = new JPanel();
        JOptionPane.showMessageDialog(msg, "Student Added Successfully!", "Success", JOptionPane.INFORMATION_MESSAGE);

        newStudent = null;
        this.setVisible(false);
        addStudent studentAdded = new addStudent();
        studentAdded.setVisible(true);
    }

} 

public class Student {
private String firstName;
private String surName;
private String NICNo;
private String batchCode;
private String studentNo;
private String telephoneNo;

public Student(String fName, String sName, String nicNo, String batCode, String studNo, String telNo){
    this.firstName = fName;
    this.surName = sName;
    this.NICNo = nicNo;
    this.batchCode = batCode;
    this.studentNo = studNo;
    this.telephoneNo = telNo;
}

public Student() {
    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

public void setFirstName(String fName){
    this.firstName = fName;
}

public String getFirstName(){
    return firstName;
}

public void setSurname(String sName){
    this.surName = sName;
}

public String getSurname(){
    return surName;
}

public void setNICNo(String nicNo){
    this.NICNo = nicNo;
}

public String getNICNo(){
    return NICNo;
}

public void setBatchCode(String batCode){
    this.batchCode = batCode;
}

public String getBatchCode(){
    return batchCode;
}

public void setStudentNo(String studNo){
    this.studentNo = studNo;
}

public String getStudentNo(){
    return studentNo;
}

public void setTelNo(String telNo){
    this.telephoneNo = telNo;
}

public String getTelNo(){
    return telephoneNo;
}

}


 public class addStudent extends JFrame {

public addStudent() {
    initComponents();
    setTitle("Add Student");
    setBounds(0, 0, 410, 550);
    setIcon();
    getContentPane().setBackground(Color.BLACK);
    jTextField1.setText("");
    jTextField2.setText("");
    jTextField4.setText("");
    jTextField5.setText("");
    jTextField6.setText("");
    jTextField7.setText("");
}

public void addStudent(){
    Student newStudent= new Student();

    newStudent.setFirstName(jTextField1.getText());
    newStudent.setSurname(jTextField2.getText());
    newStudent.setNICNo(jTextField4.getText());
    newStudent.setBatchCode(jTextField5.getText());
    newStudent.setStudentNo(jTextField6.getText());
    newStudent.setTelNo(jTextField7.getText());
}

public boolean checkEmpty(){
    boolean checkEmpty = false;
    if(jTextField1.getText().isEmpty()||jTextField1.getText().isEmpty()||jTextField2.getText().isEmpty()||jTextField4.getText().isEmpty()||jTextField5.getText().isEmpty()||jTextField6.getText().isEmpty()||jTextField7.getText().isEmpty())
    {
        checkEmpty = true;
    }
    return checkEmpty;
}

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">                          
private void initComponents() {

    jPanel1 = new javax.swing.JPanel();
    jPanel3 = new javax.swing.JPanel();
    jPanel2 = new javax.swing.JPanel();
    jLabel7 = new javax.swing.JLabel();
    jTextField1 = new javax.swing.JTextField();
    jTextField2 = new javax.swing.JTextField();
    jTextField4 = new javax.swing.JTextField();
    jTextField5 = new javax.swing.JTextField();
    jLabel1 = new javax.swing.JLabel();
    jTextField6 = new javax.swing.JTextField();
    jLabel2 = new javax.swing.JLabel();
    jTextField7 = new javax.swing.JTextField();
    jLabel3 = new javax.swing.JLabel();
    jComboBox1 = new javax.swing.JComboBox();
    jLabel4 = new javax.swing.JLabel();
    jButton1 = new javax.swing.JButton();
    jLabel5 = new javax.swing.JLabel();
    jButton2 = new javax.swing.JButton();
    jLabel6 = new javax.swing.JLabel();
    jLabel8 = new javax.swing.JLabel();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    jPanel1.setBackground(new java.awt.Color(0, 0, 0));

    jPanel3.setBackground(new java.awt.Color(0, 0, 0));
    jPanel3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.white, java.awt.Color.white, java.awt.Color.white, java.awt.Color.white));

    jPanel2.setBackground(new java.awt.Color(0, 0, 0));

    jLabel7.setForeground(new java.awt.Color(255, 255, 255));
    jLabel7.setText("Tel. No :              +94");

    jTextField2.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jTextField2ActionPerformed(evt);
        }
    });

    jLabel1.setForeground(new java.awt.Color(255, 255, 255));
    jLabel1.setText("First Name :");

    jLabel2.setForeground(new java.awt.Color(255, 255, 255));
    jLabel2.setText("Surname :");

    jLabel3.setForeground(new java.awt.Color(255, 255, 255));
    jLabel3.setText("Sex :");

    jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Male", "Female" }));
    jComboBox1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jComboBox1ActionPerformed(evt);
        }
    });

    jLabel4.setForeground(new java.awt.Color(255, 255, 255));
    jLabel4.setText("NIC No :");

    jButton1.setText("Save");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton1ActionPerformed(evt);
        }
    });

    jLabel5.setForeground(new java.awt.Color(255, 255, 255));
    jLabel5.setText("Batch Code :         CF");

    jButton2.setText("Cancel");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton2ActionPerformed(evt);
        }
    });

    jLabel6.setForeground(new java.awt.Color(255, 255, 255));
    jLabel6.setText("Student Number : CB");

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel2Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel1)
                        .addComponent(jLabel2)
                        .addComponent(jLabel3)
                        .addComponent(jLabel4))
                    .addGap(39, 39, 39)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jTextField4, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jTextField2)))
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.LEADING))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addGap(0, 95, Short.MAX_VALUE)
                            .addComponent(jButton1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jButton2))
                        .addComponent(jTextField6)
                        .addComponent(jTextField7)
                        .addComponent(jTextField5))))
            .addContainerGap())
    );
    jPanel2Layout.setVerticalGroup(
        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
            .addContainerGap(27, Short.MAX_VALUE)
            .addGroup(jPanel2Layout.createParallelGroup(javax

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have code in your own program that you're not yet showing us, likely in an ActionListener or in a method that one of your ActionListener's calls, that throws this exception. Find it, and fix it, simple as that.

As noted by many, the exception's own Stacktrace message will tell you what lines are causing the exception, but again, I'm betting it will be in a method that has been created by NetBeans and that looks something like:

// where the X below is some number
private void jButtonXActionPerformed(java.awt.event.ActionEvent evt) {
    throws new UnsupportedOperationException("Not supported yet.");
}

To fix this, remove the throws statement and instead add code that should be called when this button is pressed.


OK, I was wrong about the location, but correct with my overall thoughts, your code is throwing the exception right here in your Student constructor:

public Student() {
   throw new UnsupportedOperationException("Not supported yet."); 
}

Again, get rid of this, and instead add appropriate code for this constructor

public Student() {
   // add appropriate code here
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...