|
Hello, been trying to finish a project and im now stuck, when i try and run it says no main method found. I have created a Jframe form and Object Class. Theres no errors on the object class, but there are a few on the Jframe Form relating to the buttons.
Note: Error in Asterix.
private void cmdAddActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
BookRecord record;
try{
*record = new BookRecord(*
txtIsbn.getText(),
txtTitle.getText(),
txtAuthor.getText(),
Integer.parseInt(txtLast.getText()),
Float.parseFloat(txtCost.getText()));
output.writeObject(record);
} catch(IOException e){
}
catch(Exception e){
}
}
Theres also a few other, side erros such as.
*txtLast.setText(Integer.toString(record.getLast())); *
*txtIsbn.setText(Integer.toString(record.getIsbn()));*
Which i'd like to change to a Char11
txtSupplier.setText(Integer.toString(record.getSupplier()));
Changed to a 2 Digit Number
And
txtCost.setText(Float.toString(record.getCost()));
To 2 Decimal Places
Here is the object Class, no errors.
import java.io.*;
public class BookRecord implements Serializable{
private String isbn;
private float cost;
private int supplier;
private String author;
private String title;
private int last;
/** Creates a new instance of bookRecord */
public BookRecord() {
this(0,0,"","","",0);
}
public BookRecord(int l, int s, String i, String a, String t, float c)
{
setIsbn(i);
setCost(c);
setTitle(t);
setAuthor(a);
setSupplier(s);
setLast(l);
}
public void setIsbn(String i){
isbn = i;
}
public String getIsbn(){
return isbn;
}
public void setTitle(String t) {
title = t;
}
public String getTitle(){
return title;
}
public void setSupplier(int s) {
supplier = s;
}
public int getSupplier(){
return supplier;
}
public void setCost(float c) {
cost = c;
}
public float getCost(){
return cost;
}
public void setAuthor(String a){
author = a;
}
public String getAuthor(){
return author;
}
public void setLast(int l){
last = l;
}
public int geLast(){
return last;
}
}
What is causing Run to through a no main method Error? I dont understand.
Please Help, Suggestions and possible fixes welcome.
|
|
|
The constructor in the "actionPerformed" method
record = new BookRecord(txtIsbn.getText(),
txtTitle.getText(),
txtAuthor.getText(),
Integer.parseInt(txtLast.getText()),
Float.parseFloat(txtCost.getText()));
|
|
is using the following argument types
record = new BookRecord(String, String, String, Integer, Float);
|
|
In your BookRecoder class the constructor
public BookRecord(int l, int s, String i, String a, String t, float c)
|
|
has argument types:
BookRecord(int, int, String, String, String, float)
|
|
These types must match. "int" and "float" are primitive types; "Integer" and "Float" are objects of their own type (ie, type Integer and type Float) and are used as wrappers for the primitives. Starting in j2se 1.5 which has the auto-boxing feature you can get away with being careless about the distinction. In the "actionPerformed" method your constructor has 5 arguments. Your BookRecord class has two constructors: one with no arguments and one with 6 arguments. The compiler will not like this.
It is useful to be careful about the details of types and the order of method/constructor arguments.
In your BookRecord class
class BookRecord implements Serializable {
private String isbn;
private float cost;
private int supplier;
private String author;
private String title;
private int last;
...
public BookRecord(int l, int s, String i, String a, String t, float c) {
// "isbn" is declared above as a String and "setIsbn" takes a String,
// you are trying to send the "setIsbn" method an "int"
setIsbn(i);
setCost(c);
setTitle(t);
setAuthor(a);
setSupplier(s);
setLast(l);
}
|
|
The order of arguments is different than the order of declaration of member variables which makes things more confusing. Try something like this:
class BookRecord implements Serializable {
// declarations of member variables
private String isbn;
private String author;
private String title;
private float cost;
private int supplier;
private int last;
...
public BookRecord(String isbn, String author, String title,
float c, int supplier, int last) {
// assigning values to member variables by sending
// local variables/arguments to "set" methods
setIsbn(isbn);
setAuthor(author);
setTitle(title);
setCost(c);
setSupplier(supplier);
setLast(last);
}
|
|
in this
txtIsbn.setText(Integer.toString(record.getIsbn()));
|
|
the "getIsbn" method returns a String so you don't need to convert it to a String.
You can also use the "String.valueOf(...)" methods for these kind of conversions - see String api.
Theres also a few other, side erros such as.
*txtLast.setText(Integer.toString(record.getLast())); *
|
|
The error message posted in the console will give the reason for the compile-error. Without it and/or more code I can't do much with these other few statements.
|
|
|
I've fixed some of the small errors and placed everything in the right order, however anything to do with "Last" results in red lining.
*txtLast.setText(Integer.toString(record.getLast())); *
Ive deleted Package Name from the top of each file, JFrame and BookRecord.Java
My Project is in a folder Called Filehandling.
I have a "data" Folder in the src folder which contains book.txt.
Theres a 2nd filehandling folder (lower case) which contains BookRecord.java and NewJframe.java
New Errors are in relation to "BookRecord record;"
and "record = (BookRecord)input.readObject();"
Throughout the project.
Hovering the mouse over says "Cannot find Symbol" "Symbol: Class BookRecord" "Location: NewJFrame"
Really quite stuck now, did you say how to get some things as Char11 and 4 digits, 2 Decimal places etc?
Heres the BookRecord.java Code:
No Errors detected.
import java.io.*;
public class BookRecord implements Serializable{
private String isbn;
private String author;
private String title;
private float cost;
private int supplier;
private int last;
/** Creates a new instance of bookRecord */
public BookRecord() {
this("","","",0,0,0);
}
public BookRecord(String isbn, String author, String title, float c, int supplier, int last) {
setIsbn(isbn);
setAuthor(author);
setTitle(title);
setCost(c);
setSupplier(supplier);
setLast(last);
}
public void setIsbn(String i){
isbn = i;
}
public String getIsbn(){
return isbn;
}
public void setTitle(String t) {
title = t;
}
public String getTitle(){
return title;
}
public void setSupplier(int s) {
supplier = s;
}
public int getSupplier(){
return supplier;
}
public void setCost(float c) {
cost = c;
}
public float getCost(){
return cost;
}
public void setAuthor(String a){
author = a;
}
public String getAuthor(){
return author;
}
public void setLast(int l){
last = l;
}
public int geLast(){
return last;
}
}
NewJFrame.java Code:
Errors in *
import java.io.*;
import java.text.NumberFormat;
public class NewJFrame extends javax.swing.JFrame {
ObjectOutputStream output;
ObjectInputStream input;
File file = new File(System.getProperty("user.dir")+"/data/book.txt");
/** Creates new form NewJFrame */
public NewJFrame() {
initComponents();
}
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
txtIsbn = new javax.swing.JTextField();
txtTitle = new javax.swing.JTextField();
txtAuthor = new javax.swing.JTextField();
txtCost = new javax.swing.JTextField();
txtSupplier = new javax.swing.JTextField();
txtLast = new javax.swing.JTextField();
cmdNew = new javax.swing.JButton();
cmdAdd = new javax.swing.JButton();
cmdFirst = new javax.swing.JButton();
cmdNext = new javax.swing.JButton();
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("ISBN");
getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 30, -1, -1));
jLabel2.setText("Title");
getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 50, -1, -1));
jLabel3.setText("Author");
getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 70, -1, -1));
jLabel4.setText("Cost");
getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 110, -1, -1));
jLabel5.setText("Supplier No:");
getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 140, -1, -1));
jLabel6.setText("Last Order Date");
getContentPane().add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 170, -1, 10));
getContentPane().add(txtIsbn, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 30, 80, -1));
getContentPane().add(txtTitle, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 50, 110, -1));
getContentPane().add(txtAuthor, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 70, 110, -1));
getContentPane().add(txtCost, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 110, 50, -1));
getContentPane().add(txtSupplier, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 140, 80, -1));
getContentPane().add(txtLast, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 170, 70, -1));
cmdNew.setText("New");
cmdNew.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdNewActionPerformed(evt);
}
});
getContentPane().add(cmdNew, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 30, -1, -1));
cmdAdd.setText("Add");
cmdAdd.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdAddActionPerformed(evt);
}
});
getContentPane().add(cmdAdd, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 60, -1, -1));
cmdFirst.setText("First");
cmdFirst.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdFirstActionPerformed(evt);
}
});
getContentPane().add(cmdFirst, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 210, -1, -1));
cmdNext.setText("Next");
cmdNext.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdNextActionPerformed(evt);
}
});
getContentPane().add(cmdNext, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 210, -1, -1));
pack();
}
// </editor-fold>
private void cmdNextActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
* BookRecord record; *
try{
*record = (BookRecord)input.readObject();*
txtIsbn.setText(record.getIsbn());
txtAuthor.setText(record.getAuthor());
txtTitle.setText(record.getTitle());
txtCost.setText(Float.toString(record.getCost()));
txtSupplier.setText(Integer.toString(record.getSupplier()));
} catch (IOException e){
} catch (ClassNotFoundException c){
}
catch(Exception e){
}
}
private void cmdFirstActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
*BookRecord record;*
try{
input = new ObjectInputStream(new FileInputStream(file));
*record = (BookRecord)input.readObject();*
txtIsbn.setText(record.getIsbn());
txtAuthor.setText(record.getAuthor());
txtTitle.setText(record.getTitle());
txtCost.setText(Float.toString(record.getCost()));
txtSupplier.setText(Integer.toString(record.getSupplier()));
} catch (IOException e){
} catch (ClassNotFoundException c){
}
}
private void cmdAddActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
*BookRecord record;*
try{
* record = new BookRecord( *
txtIsbn.getText(),
txtAuthor.getText(),
txtTitle.getText(),
Float.parseFloat(txtCost.getText()));
Integer.parseInt(txtLast.getText());
output.writeObject(record);
} catch(IOException e){
}
catch(Exception e){
}
}
private void cmdNewActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
output = new ObjectOutputStream(new FileOutputStream(file));
} catch(IOException i){
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton cmdAdd;
private javax.swing.JButton cmdFirst;
private javax.swing.JButton cmdNew;
private javax.swing.JButton cmdNext;
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;
private javax.swing.JLabel jLabel6;
private javax.swing.JTextField txtAuthor;
private javax.swing.JTextField txtCost;
private javax.swing.JTextField txtIsbn;
private javax.swing.JTextField txtLast;
private javax.swing.JTextField txtSupplier;
private javax.swing.JTextField txtTitle;
// End of variables declaration
}
|
|
|
Seems to be working now, after correcting strings that and then moving a "," anyway.
However when the programs runs, its remembers the Entry i last put in, but when
i type a new entry it saves it but forgets the previous entry and blocks me of using the next button.
Still havnt tried putting last back in which needs to be a date in the 22/05/06 format...How?
ISBN Char 11
Cost 2 Decimal places
Supply No: 4 digit
Thats all im stuck on really.
Heres the code for the next button, no errors probably a logistics error.
private void cmdNextActionPerformed(java.awt.event.ActionEvent evt) {
BookRecord record;
try{
record = (BookRecord)input.readObject();
txtSupplier.setText(Integer.toString(record.getSupplier()));
txtIsbn.setText(record.getIsbn());
txtAuthor.setText(record.getAuthor());
txtTitle.setText(record.getTitle());
txtCost.setText(Float.toString(record.getCost()));
} catch (ClassNotFoundException e){
e.printStackTrace();
} catch (EOFException e){
cmdNext.setEnabled(false);
} catch (IOException e){
e.printStackTrace();
}
"First" Button Code:
private void cmdFirstActionPerformed(java.awt.event.ActionEvent evt) {
BookRecord record;
try{
input = new ObjectInputStream(new FileInputStream(file));
record = (BookRecord)input.readObject();
txtSupplier.setText(Integer.toString(record.getSupplier()));
txtIsbn.setText(record.getIsbn());
txtAuthor.setText(record.getAuthor());
txtTitle.setText(record.getTitle());
txtCost.setText(Float.toString(record.getCost()));
} catch (IOException e){
e.printStackTrace();
} catch (ClassNotFoundException e){
e.printStackTrace();
}
"New" Button Code:
private void cmdNewActionPerformed(java.awt.event.ActionEvent evt) {
try{
output = new ObjectOutputStream(new FileOutputStream(file));
} catch(IOException i){
}
Add Button Code:
private void cmdAddActionPerformed(java.awt.event.ActionEvent evt) {
BookRecord record;
try{
record = new BookRecord(
Integer.parseInt(txtSupplier.getText()),
txtIsbn.getText(),
txtAuthor.getText(),
txtTitle.getText(),
Float.parseFloat(txtCost.getText()));
output.writeObject(record);
} catch(IOException e){
}
}
|
|
|
I don't have netbeans so had to move some things around. Still havnt tried putting last back in which needs to be a date in the 22/05/06 format...How?
Use DateFormat to format and parse.
ISBN Char 11
I don't understand what this means.
Cost 2 Decimal places
Use NumberFormat to control number of decimal spaces shown. Or you can use NumberFormat.getCurrencyInstance to format currency data.
Supply No: 4 digit
I don't understand what this means.
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
public class NJF extends JFrame {
ObjectOutputStream output;
ObjectInputStream input;
File file = new File(System.getProperty("user.dir")+"/data/book.txt");
//"/forum/book.txt");
DateFormat df;
NumberFormat nf;
public NJF() {
df = new SimpleDateFormat("dd/MM/yy");
nf = NumberFormat.getInstance();
nf.setMinimumFractionDigits(2);
nf.setMaximumFractionDigits(2);
initComponents();
}
private void initComponents() {
jLabel1 = new JLabel();
jLabel2 = new JLabel();
jLabel3 = new JLabel();
jLabel4 = new JLabel();
jLabel5 = new JLabel();
jLabel6 = new JLabel();
txtIsbn = new JTextField();
txtTitle = new JTextField();
txtAuthor = new JTextField();
txtCost = new JTextField();
txtSupplier = new JTextField();
txtLast = new JTextField();
cmdNew = new JButton();
cmdAdd = new JButton();
cmdFirst = new JButton();
cmdNext = new JButton();
Container cp = getContentPane();
cp.setLayout(null);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("ISBN");
addComponent(cp, jLabel1, 30, 30, -1, -1);
jLabel2.setText("Title");
addComponent(cp, jLabel2, 30, 50, -1, -1);
jLabel3.setText("Author");
addComponent(cp, jLabel3, 30, 70, -1, -1);
jLabel4.setText("Cost");
addComponent(cp, jLabel4, 60, 110, -1, -1);
jLabel5.setText("Supplier No:");
addComponent(cp, jLabel5, 40, 140, -1, -1);
jLabel6.setText("Last Order Date");
addComponent(cp, jLabel6, 30, 170, -1, 10);
addComponent(cp, txtIsbn, 70, 30, 80, -1);
addComponent(cp, txtTitle, 70, 50, 110, -1);
addComponent(cp, txtAuthor, 70, 70, 110, -1);
addComponent(cp, txtCost, 90, 110, 50, -1);
addComponent(cp, txtSupplier, 110, 140, 80, -1);
addComponent(cp, txtLast, 120, 170, 70, -1);
cmdNew.setText("New");
cmdNew.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
cmdNewActionPerformed(evt);
}
});
addComponent(cp, cmdNew, 240, 30, -1, -1);
cmdAdd.setText("Add");
cmdAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
cmdAddActionPerformed(evt);
}
});
addComponent(cp, cmdAdd, 240, 60, -1, -1);
cmdFirst.setText("First");
cmdFirst.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
cmdFirstActionPerformed(evt);
}
});
addComponent(cp, cmdFirst, 50, 210, -1, -1);
cmdNext.setText("Next");
cmdNext.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
cmdNextActionPerformed(evt);
}
});
addComponent(cp, cmdNext, 120, 210, -1, -1);
txtIsbn.setText("123456789");
txtTitle.setText("hello world");
txtAuthor.setText("duke");
txtCost.setText("1.00");
txtSupplier.setText("792");
Date now = Calendar.getInstance().getTime();
txtLast.setText(df.format(now));
cp.setPreferredSize(computeSize(cp));
pack();
setLocationRelativeTo(null);
}
private void addComponent(Container parent, Component child,
int x, int y, int w, int h) {
parent.add(child);
if(w == -1)
w = child.getPreferredSize().width;
if(h == -1)
h = child.getPreferredSize().height;
child.setBounds(x, y, w, h);
}
/**
* content pane has no idea what size it needs for
* display - this is computed by a layout manager
* which we don't have here. so we'll try to get
* a rough idea with this
*/
private Dimension computeSize(Container cp) {
Component[] c = cp.getComponents();
int w = 0;
int h = 0;
for(int j = 0; j < c.length; j++) {
Dimension d = c[j].getBounds().getSize();
int maxX = c[j].getX() + d.width;
int maxY = c[j].getY() + d.height;
if(maxX > w)
w += (maxX - w);
if(maxY > h)
h += (maxY - h);
}
return new Dimension(w, h);
}
private void cmdNextActionPerformed(ActionEvent evt) {
BookRecord record;
try {
input = new ObjectInputStream(new FileInputStream(file));
record = (BookRecord)input.readObject();
input.close();
txtIsbn.setText(record.getIsbn());
txtAuthor.setText(record.getAuthor());
txtTitle.setText(record.getTitle());
txtCost.setText(nf.format(record.getCost()));
txtSupplier.setText(Integer.toString(record.getSupplier()));
txtLast.setText(record.getLast());
} catch (IOException ioe) {
System.err.println("cmdNext read error: " + ioe.getMessage());
} catch (ClassNotFoundException cnfe) {
System.err.println("cmdNext error: " + cnfe.getMessage());
} catch(Exception e) {
System.err.println("cmdNext error: " + e.getMessage());
}
}
private void cmdFirstActionPerformed(ActionEvent evt) {
BookRecord record;
try {
input = new ObjectInputStream(new FileInputStream(file));
record = (BookRecord)input.readObject();
input.close();
txtSupplier.setText(Integer.toString(record.getSupplier()));
txtIsbn.setText(record.getIsbn());
txtAuthor.setText(record.getAuthor());
txtTitle.setText(record.getTitle());
txtLast.setText(record.getLast());
txtCost.setText(nf.format(record.getCost()));
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
}
private void cmdAddActionPerformed(ActionEvent evt) {
BookRecord record;
try {
// arguments didn't match BookRecord constructor
// String isbn, String author, String title,
// float cost, int supplier, int last
record = new BookRecord(txtIsbn.getText(),
txtAuthor.getText(),
txtTitle.getText(),
Float.parseFloat(txtCost.getText()),
Integer.parseInt(txtSupplier.getText()),
txtLast.getText());
output = new ObjectOutputStream(new FileOutputStream(file));
output.writeObject(record);
output.close();
} catch(IOException ioe) {
System.err.println("cmdAdd write error: " + ioe.getMessage());
} catch(Exception e) {
System.err.println("cmdAdd error: " + e.getMessage());
}
}
private void cmdNewActionPerformed(ActionEvent evt) {
try {
output = new ObjectOutputStream(new FileOutputStream(file));
output.close();
} catch(IOException ioe) {
System.err.println("cmdNew io error: " + ioe.getMessage());
}
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
new NJF().setVisible(true);
}
});
}
private JButton cmdAdd;
private JButton cmdFirst;
private JButton cmdNew;
private JButton cmdNext;
private JLabel jLabel1;
private JLabel jLabel2;
private JLabel jLabel3;
private JLabel jLabel4;
private JLabel jLabel5;
private JLabel jLabel6;
private JTextField txtAuthor;
private JTextField txtCost;
private JTextField txtIsbn;
private JTextField txtLast;
private JTextField txtSupplier;
private JTextField txtTitle;
}
class BookRecord implements Serializable {
private String isbn;
private String author;
private String title;
private float cost;
private int supplier;
private String last;
public BookRecord() {
this("","","",0,0,"unknown");
}
public BookRecord(String isbn, String author, String title,
float cost, int supplier, String last) {
setIsbn(isbn);
setAuthor(author);
setTitle(title);
setCost(cost);
setSupplier(supplier);
setLast(last);
}
public void setIsbn(String i) { isbn = i; }
public String getIsbn() { return isbn; }
public void setTitle(String t) { title = t; }
public String getTitle() { return title; }
public void setSupplier(int s) { supplier = s; }
public int getSupplier() { return supplier; }
public void setCost(float c) { cost = c; }
public float getCost() { return cost; }
public void setAuthor(String a) { author = a; }
public String getAuthor() { return author; }
public void setLast(String l) { last = l; }
public String getLast() { return last; }
}
|
|
|
|
|
The program runs and compiles ok however i get a cmdAdd Empty String Error.
private void cmdAddActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
BookRecord record;
try{
record = new BookRecord(txtIsbn.getText(),
txtAuthor.getText(),
txtTitle.getText(),
Float.parseFloat(txtCost.getText()),
Integer.parseInt(txtSupplier.getText()),
txtLast.getText());
output = new ObjectOutputStream(new FileOutputStream(file));
output.writeObject(record);
output.close();
} catch(IOException ioe) {
System.err.println("cmdAdd write error: " + ioe.getMessage());
} catch(Exception e) {
System.err.println("cmdAdd error: " + e.getMessage());
}
Gota get this done in the nxt few hours really.
|
|
|
No idea how but i no longer get the swing error message, but what i do get now is a problem where i can enter and save a record, click first, the record comes up, Click next nothing happens, even when 2 records have been entered.
rivate void cmdNextActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
BookRecord record;
try {
input = new ObjectInputStream(new FileInputStream(file));
record = (BookRecord)input.readObject();
input.close();
txtIsbn.setText(record.getIsbn());
txtAuthor.setText(record.getAuthor());
txtTitle.setText(record.getTitle());
txtCost.setText(nf.format(record.getCost()));
txtSupplier.setText(Integer.toString(record.getSupplier()));
txtLast.setText(record.getLast());
} catch (IOException ioe) {
System.err.println("cmdNext read error: " + ioe.getMessage());
} catch (ClassNotFoundException cnfe) {
System.err.println("cmdNext error: " + cnfe.getMessage());
} catch(Exception e) {
System.err.println("cmdNext error: " + e.getMessage());
}
<Added>
*CORRECTION*
Still get empty swing error. however only when starting with blank fields. If the user pushes the "Reset" Button This happens...
txtIsbn.setText("11 Characters");
txtAuthor.setText("Author Name");
txtTitle.setText("Book Title");
txtSupplier.setText("0");
txtCost.setText("0");
Date now = Calendar.getInstance().getTime();
txtLast.setText(df.format(now));
After this the user can change one or 2 of the fields and the data be saved. How come?
Still a problem with the "next button" will not cycle through/remember in previous inputs.
<Added>
Ive noticed that when clicking Next that yes nothing changes but by highlightin the txt reveals the changed text underneath?
|
|
|
|
|
|
|
// |