File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Problem with sales enquiry in Java Editplus Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with sales enquiry in Java Editplus" Watch "Problem with sales enquiry in Java Editplus" New topic

Problem with sales enquiry in Java Editplus

ahmed helsinki

Joined: Jan 22, 2007
Posts: 1
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import javax.swing.JFrame;
import java.awt.event.*;

class Product implements Comparable {
private int cost;
private String name;
private String brief;

public Product(int c, String n, String b) {
cost = c;
name = n;
brief = b;

public Product() {
this("default", "default", "default", "default");
public int getCost() {
return cost;
public String getName() {
return name;

public String getBrief() {
return Brief;
// compareTo() allows Product instances in a container
// (e.g. an ArrayList) to be sorted by Collections.sort().

// It can only sort things in one order (e.g. ascending order of
// name). Need to investigate the use of Comparator objects to
// allow different sort orders to be defined.

public int compareTo(Object o) {
Product temp = (Product) o;

// Strings already implement compareTo() so just use that
return (name.compareTo(;
return (brief.compareTo(temp.brief));
public class GUI1 extends JFrame {

// A container for the Product instances
ArrayList products = new ArrayList();

// GUI bits and bobs
JPanel panInput = new JPanel(new GridLayout(3,1)),
panAdd =new JPanel(),
panDelSort = new JPanel(),
panbrief =new JPanel();

JTextField txtName = new JTextField(600),
txtCost = new JTextField(20),
txtBrief = new JTextField(30);

JButton btnAdd =new JButton("Add"),
btnDelete = new JButton("Delete"),
btnSort =new JButton("Sort Products");

JTable tab = new JTable();

// The DefaultTableModel will allow the contents of the
// JTable to be manipulated.
DefaultTableModel tabMod = new DefaultTableModel();

Product [] initialProducts = {new Product(57, "Widget", "Welco"),
new Product(700, "Cuddly toy", "welco"),
new Product(12000, "Digital Camera", "Welco")};

public GUI1() {
super("Product list");
tabMod.addColumn("Product Name");
tabMod.addColumn("Product Cost");

btnAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {

btnDelete.setToolTipText("Select the records to delete first");
btnDelete.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
btnSort.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {

panAdd.add(new JLabel("Product name:"));
panAdd.add(new JLabel("Product cost:"));
panAdd.add(new JLabel("Product brief:"));
getContentPane().add(panInput, BorderLayout.SOUTH);
getContentPane().add(new JScrollPane(tab));
// Delete a product from the ArrayList and from the JTable
public void deleteProduct() {
int [] rows = tab.getSelectedRows();
for (int i = 0; i < rows.length; i++) {

tabMod.removeRow(rows[i] - i); // delete from JTable
products.remove(rows[i] - i); // delete from ArrayList

// Sort the products in the ArrayList and then
// reload them into the JTable in the sorted order

public void sortProducts() {
Collections.sort(products); // sorts into name order

// Add a new products to the ArrayList and the JTable
public void addProduct() {
String [] row = new String [2];

Product newProd = new Product(Integer.parseInt(txtCost.getText()), txtName.getText()), txtbrief.getText());

products.add(newProd); // add to the ArrayList
row[0] = newProd.getName();
row[1] = Integer.toString(newProd.getCost, newProd.getBrief());
tabMod.addRow(row); // add to the JTable
public void loadInitialProducts() {
for (int i = 0; i < initialProducts.length; i++) {
public void loadProductsIntoTable() {

String [] row = new String [2];
for (Iterator i = products.iterator(); i.hasNext() {
Product temp = (Product);
row[0] = temp.getName();
row[1] = Integer.toString(temp.getCost());
row[2] = Integer.toString(temp.getBrief());

public static void main(String [] a){
GUI1 me = new GUI1();
me.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0) ;

error message:

---------- javac ---------- ';' expected
Product newProd = new Product(Integer.parseInt(txtCost.getText()), txtName.getText()), txtbrief.getText());
1 error

Output completed (0 sec consumed) - Normal Termination
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24189


Welcome to JavaRanch!

I'm moving this to our "Java in General (Beginner)" forum where it will get the attention it deserves.

[Jess in Action][AskingGoodQuestions]
Nicholas Carrier
Ranch Hand

Joined: Apr 14, 2005
Posts: 78
Basically you have too many closing )'s

You have

Product newProd = new Product(Integer.parseInt(txtCost.getText()), txtName.getText()), txtbrief.getText());

It should look like this:

Product newProd = new Product(Integer.parseInt(txtCost.getText()), txtName.getText(),txtbrief.getText());

There is a need for the extra ) after txtCost because you are closing out the parseInt() method, and there is a need for the extra ) after textbrief because you are closing out the constructor, but there is no need for the extra ) after txtName.

Hope that helps.
[ January 22, 2007: Message edited by: Nicholas Carrier ]

Teaching yourself anything is always the cheapest way, but it definitely takes a lot of time and effort.<br /> <br />Thank you javaranch <a href="http://""" target="_blank" rel="nofollow">Learn How to Ask Your Question</a> and be nice
I agree. Here's the link:
subject: Problem with sales enquiry in Java Editplus
It's not a secret anymore!