i try to compile and run
seems like work perfectly but once i click the "add" button(something like save)
error come out
i dont know what problem with the codes
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* NewJFrame1.java
*
* Created on Jul 4, 2010, 2:45:14 PM
*/
import java.io.*;
import java.util.*;
import javax.swing.*;
/**
*
* @author Rick
*/
public class NewJFrame1 extends javax.swing.JFrame {
//File data = new File("data.txt");
DataOutputStream ostream;
GregorianCalendar aCalendar = new GregorianCalendar();
@SuppressWarnings("static-access")
int year = aCalendar.get(aCalendar.YEAR);
@SuppressWarnings("static-access")
int month = aCalendar.get(aCalendar.MONTH);
@SuppressWarnings("static-access")
int day = aCalendar.get(aCalendar.DAY_OF_MONTH);
public String name[], date[], subject[], message[], priority[];
public int add=0;
public String MAX[]=new String[20];
/** Creates new form NewJFrame1 */
public NewJFrame1() {
try
{
ostream = new DataOutputStream(new FileOutputStream("record.dat"));
}
catch(IOException e)
{
JOptionPane.showMessageDialog(null, e.getMessage());
System.exit(1);
}
initComponents();
jLabel8.setText(day+"/"+(1+month)+"/"+ year);
}
/** 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">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel6 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jComboBox4 = new javax.swing.JComboBox();
jLabel9 = new javax.swing.JLabel();
jLabel6.setText("jLabel6");
jLabel6.setName("jLabel6"); // NOI18N
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Add Memo");
jLabel1.setText("Name :");
jLabel1.setName("jLabel1"); // NOI18N
jLabel3.setText("Subject :");
jLabel3.setName("jLabel3"); // NOI18N
jLabel4.setText("Message :");
jLabel4.setName("jLabel4"); // NOI18N
jLabel5.setText("Priority :");
jLabel5.setName("jLabel5"); // NOI18N
jTextField1.setName("jTextField1"); // NOI18N
jTextField3.setName("jTextField3"); // NOI18N
jScrollPane1.setName("jScrollPane1"); // NOI18N
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jTextArea1.setName("jTextArea1"); // NOI18N
jScrollPane1.setViewportView(jTextArea1);
jButton1.setText("Back");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("Add Memo");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jLabel7.setText("Date :");
jLabel7.setName("jLabel7"); // NOI18N
jLabel8.setName("jLabel8"); // NOI18N
jComboBox4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "10 ", "9", "8", "7", "6", "5", "4", "3", "2", "1" }));
jComboBox4.setName("jComboBox4"); // NOI18N
jLabel9.setText("*10 is the highest*");
jLabel9.setName("jLabel9"); // 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()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel4)
.addComponent(jLabel5)
.addComponent(jLabel7)
.addComponent(jLabel3))
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 381, Short.MAX_VALUE)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel9))
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(225, Short.MAX_VALUE)))))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel7)
.addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(8, 8, 8)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel9))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 42, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
Object source =evt.getSource();
if(source == jButton2){
if(jTextField1.getText().equals("")){
JOptionPane.showMessageDialog(this,"Please write your name", "Error", JOptionPane.ERROR_MESSAGE);
}
else if(jTextField3.getText().equals("")){
JOptionPane.showMessageDialog(this, "Please enter a subject", "Error", JOptionPane.ERROR_MESSAGE);
}
else if(jTextArea1.getText().equals("")){
JOptionPane.showMessageDialog(this,"Please enter a message", "Error", JOptionPane.ERROR_MESSAGE);
}
else{
JOptionPane.showMessageDialog(this, "Memo sent", "Good Job", JOptionPane.INFORMATION_MESSAGE);
}
try
{
add++;
name[add]=jTextField1.getText();
date[add]=jLabel8.getText();
subject[add]=jTextField3.getText();
message[add]=jTextArea1.getText();
priority[add]=(jComboBox4.getSelectedIndex()+"");
ostream.writeUTF(name[add]);
ostream.writeUTF(date[add]);
ostream.writeUTF(subject[add]);
ostream.writeUTF(message[add]);
ostream.writeUTF(priority[add]+"");
/*ostream.writeInt(jComboBox1.getSelectedIndex());
ostream.writeUTF(jComboBox2.getSelectedIndex()+"");
ostream.writeInt(jComboBox3.getSelectedIndex());
ostream.writeInt(jComboBox4.getSelectedIndex());*/
jTextField1.setText("");
jTextField3.setText("");
jTextArea1.setText("");
}
catch(IOException e){
System.err.println("Error occur");
System.exit(1);
}
}
// TODO add your handling code here:
}//GEN-LAST:event_jButton2ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
NewJFrame page1 = new NewJFrame();
page1.setVisible(true);
dispose() ; // TODO add your handling code here:
}//GEN-LAST:event_jButton1ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[])throws IOException, Exception {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame1().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JComboBox jComboBox4;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField3;
// End of variables declaration//GEN-END:variables
}