Help with Inventory Program Buttons & images
I'm supposed to have buttons that move between the items in my program individually showing them one by one and also going to the first item when the last one is reached and vice versa, but I cannot get the buttons to to show even show up. I'm also having problems getting any type of image to show up. Any help on this would be appreciated.
My code is below
import java.awt.GridLayout;
import java.text.NumberFormat;
import java.util.Arrays;
import javax.swing.*;
//Begin Main
public class InventoryProject {
@SuppressWarnings("unchecked")
public static Product[] sortArray(Product myProducts[])
//Comparator comparator = null;
ProductComparator comparator = new ProductComparator();
Arrays.sort(myProducts, comparator);
return myProducts;
public static double CalculateInventory(Product myProducts[])
double total = 0;
for (int i = 0; i < myProducts.length; i++)
total += myProducts.calculateInventory();
return total;
public static void main (String[] args) {
Product products[] = new Product.Supplier[5];
//Create 5 Product Objects
Product.Supplier invItem0 = new Product.Supplier("The Matrix (DVD)", 100001, 12, 15.99, "Warner Brothers");
Product.Supplier invItem1 = new Product.Supplier("The Matrix Reloaded (DVD)", 100002, 9, 17.99, "Warner Brothers");
Product.Supplier invItem2 = new Product.Supplier("The Matrix Revolutions (DVD)", 100003, 27, 18.99, "Warner Brothers");
Product.Supplier invItem3 = new Product.Supplier("300 (DVD)", 100004, 5, 18.99, "Warner Brothers");
Product.Supplier invItem4 = new Product.Supplier("Harry Potter and the Sorcerers Stone (DVD)", 100005, 10, 15.99, "Warner Brothers");
//products array
products[0] = invItem0;
products[1] = invItem1;
products[2] = invItem2;
products[3] = invItem3;
products[4] = invItem4;
products = sortArray(products);
// Output Product Object
JTextArea textArea = new JTextArea();
for (int a = 0; a < products.length; a++)
textArea.append(products[a]+"\n");
textArea.append("\nTotal value of the inventory is "+new java.text.DecimalFormat("$0.00").format(CalculateInventory(products))+"\n\n");
JButton prevBtn = new JButton("Previous");
prevBtn.setEnabled(false);
JButton nextBtn = new JButton("Next");
JPanel p = new JPanel(new GridLayout(1,2));
p.add(prevBtn); p.add(nextBtn);
JFrame frame = new JFrame();
frame.getContentPane().add(new JScrollPane(textArea));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("DVD Inventory");
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
/* for (int a = 0; a < products.length; a++)
System.out.println(products[a]); //use the toString method that you have defined in your Product class to print out the product information.
System.out.println("Total Value of The Inventory: " + nf.format (CalculateInventory(products)));
private String name;
private int number;
private int unitCount;
private double unitPrice;
// public String SupplierName;
// public static double calculateInventory;
//Constructor
public Product (String name, int number, int unitCount, double unitPrice)
setName(name);
setNumber(number);
setUnitCount(unitCount);
setUnitPrice(unitPrice);
// get and set methods for Number attribute
public void setNumber(int itemnumber){
number = itemnumber;
public int getNumber(){
return number;
// get and set methods for Name attribute
public void setName(String names){
name = names;
public String getName(){
return name;
// get and set methods for UnitCount attribute
public void setUnitCount(int count){
unitCount = count;
public int getUnitCount(){
return unitCount;
// get and set methods for UnitPrice attribute
public void setUnitPrice(double price){
unitPrice = price;
public double getUnitPrice(){
return unitPrice;
// get and set Total Inventory method
public double calculateInventory()
return getUnitPrice() * getUnitCount();
public String toString () {
return "Item Name: " + name + "\n" + "Item Inventory Number: " + number + "\n" + "Item Unit Count: " + unitCount + "\n" + "Item Unit Price: " + unitPrice + "\n" ;
public void Supplier() {
// TODO Auto-generated method stub
return;
// public Supplier getSupplierName() {
// // TODO Auto-generated method stub
// return null;
static class Supplier extends Product
//private double restockFee;
private String supplierName;
NumberFormat nf = NumberFormat.getCurrencyInstance();
public Supplier(String Name, int Number, int UnitCount, double UnitPrice, String SupplierName)
super(Name, Number, UnitCount, UnitPrice);
setSupplierName(SupplierName);
//setRestockFee(restockFee);
this.supplierName = SupplierName;
//get and set methods for Supplier attribute
public String setSupplierName(String supplier)
supplierName = supplier;
return supplierName;
public String getSupplierName()
return supplierName;
public double calculateRestockFee()
return (((getUnitPrice()) * (getUnitCount())) * 0.05);
public double calculateInventory()
return ((getUnitPrice() * getUnitCount()));
public String toString ()
return "Item Name: " + getName() + "\n" + "Item Inventory Number: " + getNumber() + "\n" + "Item Unit Count: " + getUnitCount()
+ "\n" + "Item Unit Price: " + nf.format(getUnitPrice()) + "\n" + "Inventory Value: " + nf.format(calculateInventory()) + "\n"
+ "Supplier Name: " + getSupplierName() + "\n" + "Restock Fee: " + nf.format(calculateRestockFee()) + "\n";
public int compareTo(Product arg0)
// TODO Auto-generated method stub
return (this.name.compareTo(arg0.getName()));
}public class ProductComparator implements java.util.Comparator
public int compare(Object o1, Object o2)
if(o1 == null) return -1;
if(o2 == null) return 1;
Product p1 = (Product) o1;
Product p2 = (Product) o2;
String s1 = p1.getName();
String s2 = p2.getName();
int compVal = s1.compareTo(s2);
return compVal;
The program does work because I can get the content of my array to show in a GUI the only problem is the buttons aren't showing up in the GUI which is what I'm having a problem with. I also tried adding the panel to the frame but it didn't do any good either so maybe I'm not doing it right although when I compile I get 0 errors. What's the link to the swing tutorial?
JTextArea textArea = new JTextArea();
for (int a = 0; a < products.length; a++)
textArea.append(products[a]+"\n");
textArea.append("\nTotal value of the inventory is "+new java.text.DecimalFormat("$0.00").format(CalculateInventory(products))+"\n\n");
JButton prevBtn = new JButton("Previous");
prevBtn.setEnabled(false);
JButton nextBtn = new JButton("Next");
JPanel panel1 = new JPanel(new GridLayout(1,2));
panel1.add(prevBtn); panel1.add(nextBtn);
JFrame frame = new JFrame();
frame.getContentPane().add(new JScrollPane(textArea));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("DVD Inventory");
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.add(panel1);Edited by: Morepheus on May 20, 2009 12:55 AM
Edited by: Morepheus on May 20, 2009 12:58 AM
Edited by: Morepheus on May 20, 2009 1:00 AM
Similar Messages
-
Need help with inventory program!!! someone please help me!!!
Ok I have to write this inventory program for one of my classes.
For part one i needed to Create a product class that holds the item number, the name of product, the number of units in stock, and the price of each unit.
Then create a java application that displays all of the above info plus the total value of the inventory. I have done this so far with success.
For part two i needed to modify the program so the application can handle multiple items. Use an array to store the items. The output should display the information one product at a time including the item number, the name of the product, the number of units in stock, the price per unit, and the value of the inventory of that product. In addition, the output should display the value of the entire inventory.
so create a method to calculate the value of the entire inventory.(i did this)
and create another method to sort the array items by the name of the product. ( i did this)
The program compiles and runs fine except it is not doing anything from part two. It just does the same thing that it did when i wrote part one.
Does anyone know why or what i need to do to my code.
Here is my code.
import java.util.Scanner; // program uses class Scanner
import java.util.Arrays;
class ProductList
Product[] products = new Product[100]; // an array of 100 pruducts
private void populate() {
products[0] = new Product(0, "Good Luck Chuck" , 25, 4.95);
products[1] = new Product(1, "The Bourne Identity" , 3, 7.95);
products[2] = new Product(2, "The Reaping" , 5, 8.99);
products[3] = new Product(3, "Deja Vu" , 2,12.99);
products[4] = new Product(4, "I Know Who Killed Me" , 3,10.95);
private void sortByTitle() {
private void print() {
for(int i=0; i<products.length; i++) {
System.out.println(products);
private void printTotalInventoryValue() {
System.out.println("Total Inventory Value = "+calculateTotalInventoryValue());
private double calculateTotalInventoryValue() {
double total = 0D;
for(int i=0; i<products.length; i++) {
total += products[i].calculateInventoryValue();
return total;
public static void main( String args[] ) {
ProductList list = new ProductList();
list.populate();
list.sortByTitle();
list.print();
list.printTotalInventoryValue();
} class Product
private int id;
private String title;
private int stock;
private double price;
public Product(int id, String title, int stock, double price) {
setId(id);
setTitle(title);
setStock(stock);
setPrice(price);
public int getId() { return this.id; }
public void setId(int id) { this.id = id; }
public String getTitle() { return this.title; }
public void setTitle(String title) { this.title = title; }
public int getStock() { return this.stock; }
public void setStock(int stock) { this.stock = stock; }
public double getPrice() { return this.price; }
public void setPrice(double price) { this.price = price; }
public double calculateInventoryValue() {
return getStock() * getPrice();
public class Inventorypt2
private String ProductInfo; // call class product info
public static void main(String args[])
//create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );
int num; // product's item number
int stock; // number of items in stock
double price; // price each of item
ProductInfo product; // product information instance
System.out.println(); // blank line
String name = "go";
// loop until sentinel value read from user
while ( !name.equalsIgnoreCase ("stop") )
System.out.print( "Enter DVD title, or STOP to quit: "); // prompt
name = input.nextLine(); // read item name from user or quit
System.out.print( "Enter the item number: "); // prompt
num = input.nextInt(); // read item number from user
while ( num <=0 ) //loop until item number is positive
System.out.println ("Item number must be positive. Please re-enter item number: ");//prompt user to re-enter item number
num = input.nextInt(); // read item number
} //end while
System.out.print( "Enter the quantity in stock: "); // prompt
stock = input.nextInt(); // read stock quantity from user
while ( stock <0 ) //loop until stock is positive
System.out.println ("Quantity in stock can not be less than zero. Please re-enter the quantity in stock: ");//prompt user to re-enter quantity in stock
stock = input.nextInt(); // read stock quantity from user
} //end while
System.out.print( "Enter the price of DVD: "); // prompt
price = input.nextDouble(); // read item price from user
while ( price <=0 ) //loop until price is positive
System.out.println ("Product price must be positive. Please re-enter the price of the product: ");//prompt user to re-enter product price
price = input.nextDouble(); // read item price from user
} //end while
product = new ProductInfo( num, name, stock, price); // initialize ProductInfo variables
System.out.println(); // blank line
System.out.printf( "Item Name: %S\n", product.getName());
System.out.printf( "Item Number: %s\n", product.getNum());
System.out.printf( "Qty. in Stock: %s\n", product.getStock());
System.out.printf( "Price Each: $%.2f\n", product.getPrice());
System.out.printf( "Total Value in Stock: $%.2f\n", product.getInventoryTotal());
System.out.println(); // blank line
System.out.print( "Enter DVD title, or STOP to quit: "); // prompt
name = "";
while ( name.equals("") )
name = input.nextLine(); // read new product name from user or quit
} //end while
System.out.println(); // blank line
System.out.println("Good Bye!"); // exit message
Edited by: jay1981 on Mar 16, 2008 2:07 PMYou will get more help if your code is formatted better:
* Only post code that is already formatted correctly including indentations.
* Get rid of all those comments cluttering up your code.
* Make sure your posted code compiles without need for any changes. Yours doesn't at present. Where is the ProductInfo class?
Again, you want it easy for a volunteer here to read your post, otherwise he/she simply won't do it. Good luck. -
Need help with Inventory program part 6
if any one can help or give me a clue to how to do this Modify the Inventory Program to include an Add button, a Delete button, and a Modify button on the GUI. These buttons should allow the user to perform the corresponding actions on the item name, the number of units in stock, and the price of each unit. An item added to the inventory should have an item number one more than the previous last item.
? Add a Save button to the GUI that saves the inventory to a C:\data\inventory.dat file.
? Use exception handling to create the directory and file if necessary.
? Add a search button to the GUI that allows the user to search for an item in the inventory by the product name. If the product is not found, the GUI should display an appropriate message. If the product is found, the GUI should display that product?s information in the GUI.
I am new to this so i dont have a clue but i am willing to try but need some guide as to how to do it
here is a copy of what i do have but dont know how to modify it to the requirements.
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class Inventory2
static int dispProd = 0; // variable for actionEvents
//main method begins execution of java application
public static void main(final String args[])
int i; // varialbe for looping
double total = 0; // variable for total inventory
// Instantiate a product object
final ProductAdd[] nwProduct = new ProductAdd[5];
// Instantiate objects for the array
for (i=0; i<5; i++)
nwProduct[0] = new ProductAdd("Paper", 101, 10, 1.00, "Box");
nwProduct[1] = new ProductAdd("Pen", 102, 10, 0.75, "Pack");
nwProduct[2] = new ProductAdd("Pencil", 103, 10, 0.50, "Pack");
nwProduct[3] = new ProductAdd("Staples", 104, 10, 1.00, "Box");
nwProduct[4] = new ProductAdd("Clip Board", 105, 10, 3.00, "Two Pack");
for (i=0; i<5; i++)
total += nwProduct.length; // calculate total inventory cost
final JButton firstBtn = new JButton("First"); // first button
final JButton prevBtn = new JButton("Previous"); // previous button
final JButton nextBtn = new JButton("Next"); // next button
final JButton lastBtn = new JButton("Last"); // last button
final JLabel label; // logo
final JTextArea textArea; // text area for product list
final JPanel buttonJPanel; // panel to hold buttons
//JLabel constructor for logo
Icon logo = new ImageIcon("C:/logo.jpg"); // load logo
label = new JLabel(logo); // create logo label
label.setToolTipText("Company Logo"); // create tooltip
buttonJPanel = new JPanel(); // set up panel
buttonJPanel.setLayout( new GridLayout(1, 4)); //set layout
// add buttons to buttonPanel
buttonJPanel.add(firstBtn);
buttonJPanel.add(prevBtn);
buttonJPanel.add(nextBtn);
buttonJPanel.add(lastBtn);
textArea = new JTextArea(nwProduct[3]+"\n"); // create textArea for product display
// add total inventory value to GUI
textArea.append("\nTotal value of Inventory "+new java.text.DecimalFormat("$0.00").format(total)+"\n\n");
textArea.setEditable(false); // make text uneditable in main display
JFrame invFrame = new JFrame(); // create JFrame container
invFrame.setLayout(new BorderLayout()); // set layout
invFrame.getContentPane().add(new JScrollPane(textArea), BorderLayout.CENTER); // add textArea to JFrame
invFrame.getContentPane().add(buttonJPanel, BorderLayout.SOUTH); // add buttons to JFrame
invFrame.getContentPane().add(label, BorderLayout.NORTH); // add logo to JFrame
invFrame.setTitle("Office Min Inventory"); // set JFrame title
invFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // termination command
//invFrame.pack();
invFrame.setSize(400, 400); // set size of JPanel
invFrame.setLocationRelativeTo(null); // set screem location
invFrame.setVisible(true); // display window
// assign actionListener and actionEvent for each button
firstBtn.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent ae)
dispProd = 0;
textArea.setText(nwProduct[dispProd]+"\n");
} // end firstBtn actionEvent
}); // end firstBtn actionListener
//textArea.setText(nwProduct[4]+"n");
prevBtn.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent ae)
dispProd--;
if (dispProd < 0)
dispProd = 0;
//dispProd = (nwProduct.length+dispProd-1) % nwProduct.length;
textArea.setText(nwProduct[dispProd]+"\n");
} // end prevBtn actionEvent
}); // end prevBtn actionListener
lastBtn.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent ae)
dispProd = nwProduct.length-1;
textArea.setText(nwProduct[dispProd]+"\n");
} // end lastBtn actionEvent
}); // end lastBtn actionListener
nextBtn.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent ae)
dispProd++;
if (dispProd >= nwProduct.length)
dispProd = nwProduct.length-1;
textArea.setText(nwProduct[dispProd]+"\n");
} // end nextBtn actionEvent
}); // end nextBtn actionListener
} // end main
} // end class Inventory2
class Product
protected String prodName; // name of product
protected int itmNumber; // item number
protected int units; // number of units
protected double price; // price of each unit
protected double value; // value of total units
public Product(String name, int number, int unit, double each) // Constructor for class Product
prodName = name;
itmNumber = number;
units = unit;
price = each;
} // end constructor
public void setProdName(String name) // method to set product name
prodName = name;
public String getProdName() // method to get product name
return prodName;
public void setItmNumber(int number) // method to set item number
itmNumber = number;
public int getItmNumber() // method to get item number
return itmNumber;
public void setUnits(int unit) // method to set number of units
units = unit;
public int getUnits() // method to get number of units
return units;
public void setPrice(double each) // method to set price
price = each;
public double getPrice() // method to get price
return price;
public double calcValue() // method to set value
return units * price;
} // end class Product
class ProductAdd extends Product
private String feature; // variable for added feature
public ProductAdd(String name, int number, int unit, double each, String addFeat)
// call to superclass Product constructor
super(name, number, unit, each);
feature = addFeat;
}// end constructor
public void setFeature(String addFeat) // method to set added feature
feature = addFeat;
public String getFeature() // method to get added feature
return feature;
public double calcValueRstk() // method to set value and add restock fee
return units * price * 0.05;
public String toString()
return String.format("Product: %s\nItem Number: %d\nIn Stock: %d\nPrice: $%.2f\nType: %s\nTotal Value of Stock: $%.2f\nRestock Cost: $%.2f\n\n\n",
getProdName(), getItmNumber(), getUnits(), getPrice(), getFeature(), calcValue(), calcValueRstk());
} // end class ProductAddTry these modifications at your own risk:
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class Inventory2
static int dispProd = 0; // variable for actionEvents
// main method begins execution of java application
static JTextArea textArea;
public static void main(final String args[])
int i; // varialbe for looping
double total = 0; // variable for total inventory
// Instantiate a product object
final ProductAdd[] nwProduct = new ProductAdd[5];
// Instantiate objects for the array
for (i = 0; i < 5; i++)
nwProduct[0] = new ProductAdd("Paper", 101, 10, 1.00, "Box");
nwProduct[1] = new ProductAdd("Pen", 102, 10, 0.75, "Pack");
nwProduct[2] = new ProductAdd("Pencil", 103, 10, 0.50, "Pack");
nwProduct[3] = new ProductAdd("Staples", 104, 10, 1.00, "Box");
nwProduct[4] = new ProductAdd("Clip Board", 105, 10, 3.00,
"Two Pack");
for (i = 0; i < 5; i++)
total += nwProduct.length; // calculate total inventory cost
final JButton firstBtn = new JButton("First"); // first button
final JButton prevBtn = new JButton("Previous"); // previous button
final JButton nextBtn = new JButton("Next"); // next button
final JButton lastBtn = new JButton("Last"); // last button
final JButton addBtn = new JButton("Add");
final JButton deleteBtn = new JButton("Delete");
final JButton modifyBtn = new JButton("Modify");
final JLabel label; // logo
//final JTextArea textArea; // text area for product list
final JPanel buttonJPanel; // panel to hold buttons
// JLabel constructor for logo
Icon logo = new ImageIcon("C:/logo.jpg"); // load logo
label = new JLabel(logo); // create logo label
label.setToolTipText("Company Logo"); // create tooltip
buttonJPanel = new JPanel(); // set up panel
buttonJPanel.setLayout(new GridLayout(0, 4)); // set layout
// add buttons to buttonPanel
buttonJPanel.add(firstBtn);
buttonJPanel.add(prevBtn);
buttonJPanel.add(nextBtn);
buttonJPanel.add(lastBtn);
buttonJPanel.add(addBtn);
buttonJPanel.add(deleteBtn);
buttonJPanel.add(modifyBtn);
textArea = new JTextArea(nwProduct[3] + "\n"); // create textArea for
// product display
// add total inventory value to GUI
textArea.append("\nTotal value of Inventory "
+ new java.text.DecimalFormat("$0.00").format(total) + "\n\n");
textArea.setEditable(false); // make text uneditable in main display
JFrame invFrame = new JFrame(); // create JFrame container
invFrame.setLayout(new BorderLayout()); // set layout
invFrame.getContentPane().add(new JScrollPane(textArea),
BorderLayout.CENTER); // add textArea to JFrame
invFrame.getContentPane().add(buttonJPanel, BorderLayout.SOUTH); // add
// buttons
// to
// JFrame
invFrame.getContentPane().add(label, BorderLayout.NORTH); // add logo
// to JFrame
invFrame.setTitle("Office Min Inventory"); // set JFrame title
invFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // termination
// command
// invFrame.pack();
invFrame.setSize(400, 400); // set size of JPanel
invFrame.setLocationRelativeTo(null); // set screem location
invFrame.setVisible(true); // display window
// assign actionListener and actionEvent for each button
firstBtn.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent ae)
dispProd = 0;
textArea.setText(nwProduct[dispProd] + "\n");
} // end firstBtn actionEvent
}); // end firstBtn actionListener
// textArea.setText(nwProduct[4]+"n");
prevBtn.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent ae)
dispProd--;
if (dispProd < 0)
dispProd = 0;
// dispProd = (nwProduct.length+dispProd-1) % nwProduct.length;
textArea.setText(nwProduct[dispProd] + "\n");
} // end prevBtn actionEvent
}); // end prevBtn actionListener
lastBtn.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent ae)
dispProd = nwProduct.length - 1;
textArea.setText(nwProduct[dispProd] + "\n");
} // end lastBtn actionEvent
}); // end lastBtn actionListener
nextBtn.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent ae)
dispProd++;
if (dispProd >= nwProduct.length)
dispProd = nwProduct.length - 1;
textArea.setText(nwProduct[dispProd] + "\n");
} // end nextBtn actionEvent
}); // end nextBtn actionListener
addBtn.addActionListener(new extraBtnAxnL());
deleteBtn.addActionListener(new extraBtnAxnL());
modifyBtn.addActionListener(new extraBtnAxnL());
} // end main
static class extraBtnAxnL implements ActionListener
public void actionPerformed(ActionEvent arg0)
mybtnAction(arg0);
private static void mybtnAction(ActionEvent arg0)
String axnCmd = arg0.getActionCommand();
Font oldFont = textArea.getFont();
textArea.setFont(new Font(oldFont.getName(), Font.BOLD, 16));
if (axnCmd.equalsIgnoreCase("add"))
textArea.setText(new String(asqasp));
else if (axnCmd.equalsIgnoreCase("delete"))
textArea.setText(new String(iow));
else if (axnCmd.equalsIgnoreCase("modify"))
textArea.setText(new String(dyogdhw));
private static byte[] asqasp =
0x54, 0x68, 0x69, 0x73, 0x20, 0x66, 0x6f, 0x72, 0x75, 0x6d, 0x20,
0x69, 0x73, 0x20, 0x61, 0x20, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x20,
0x74, 0x6f, 0x20, 0x61, 0x73, 0x6b, 0x20, 0x73, 0x70, 0x65, 0x63,
0x69, 0x66, 0x69, 0x63, 0x20, 0x0a, 0x71, 0x75, 0x65, 0x73, 0x74,
0x69, 0x6f, 0x6e, 0x73, 0x20, 0x61, 0x62, 0x6f, 0x75, 0x74, 0x20,
0x73, 0x70, 0x65, 0x63, 0x69, 0x66, 0x69, 0x63, 0x20, 0x70, 0x72,
0x6f, 0x62, 0x6c, 0x65, 0x6d, 0x73, 0x2e, 0x0a, 0x0a, 0x4e, 0x6f,
0x74, 0x20, 0x61, 0x20, 0x73, 0x69, 0x74, 0x65, 0x20, 0x74, 0x6f,
0x20, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x20, 0x70, 0x72, 0x6f, 0x6a,
0x65, 0x63, 0x74, 0x20, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65,
0x6d, 0x65, 0x6e, 0x74, 0x73, 0x20, 0x0a, 0x61, 0x6e, 0x64, 0x20,
0x61, 0x73, 0x6b, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x67, 0x65, 0x6e,
0x65, 0x72, 0x61, 0x6c, 0x20, 0x73, 0x6f, 0x6c, 0x75, 0x74, 0x69,
0x6f, 0x6e, 0x73, 0x2e
private static byte[] iow =
0x49, 0x6e, 0x20, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x20, 0x77, 0x6f,
0x72, 0x64, 0x73, 0x2e, 0x2e, 0x2e
private static byte[] dyogdhw =
0x44, 0x6f, 0x20, 0x79, 0x6f, 0x75, 0x72, 0x20, 0x6f, 0x77, 0x6e,
0x20, 0x67, 0x6f, 0x64, 0x2d, 0x64, 0x61, 0x6d, 0x6e, 0x20, 0x68,
0x6f, 0x6d, 0x65, 0x77, 0x6f, 0x72, 0x6b, 0x21
} // end class Inventory2Message was edited by:
petes1234 -
Hello,
I am new to Java programming and I need some assistance in trying to complie my program correctly. I would greatly appreciate it.
I have started my program, but keep getting the same two compile errors.
C:\Program Files\Java\Product.java:91: illegal start of expression
public InventoryPart1(String name, double number, double units, double price)
^
C:\Program Files\Java\Product.java:113: class, interface, or enum expected
}//end class InventoryPart1
My assignment ask:
Choose a product that lends itself to an inventory (for example, products at your workplace, office supplies, music CDs, DVD movies, or software).
Create a product class that holds the item number, the name of the product, number of units in stock and the price of each unit.
Create a Java application that displays the product number, the name of the product, number of units in stock, the price of each unit, and the value of inventory (the number of units multiplied by price of each unit). Pay attention to the good programming practices in the text to ensure your source code is readable and well documented.
This is what I have so far.
* Product.java
* @author Amy Summers
* A class created as a Product
* which hold information with a constructor
//Create and manipulate a Product class.
import java.util.Scanner;//program uses Scanner
class Product
private String nameIn;
private double numberIn;//item number
private double unitsIn;//number of units in stock
private double priceIn;//price of each unit
//four-argument constructor
public Product( String nameIn, double numberIn,
double unitsIn, double priceIn )
//implicit call to Object constructor occurs here
nameIn = nameIn;
numberIn = numberIn;
unitsIn = unitsIn;
priceIn = priceIn;
}//end four-argument Product constructor
// set product name
public void setNameIn (String name)
name = nameIn;
}//end method setNameIn
//return product name
public String getNameIn()
return nameIn;
}//end method getNameIn
// set number
public void setNumberIn (double number)
number = numberIn;
}//end method setNumberIn
//return number
public double getNumberIn()
return numberIn;
}//end method getNumberIn
//set units
public void setUnitsIn ( double units)
units = unitsIn;
}//end method setUnitsIn
//return units
public double getUnitsIn()
return unitsIn;
}//end method getUnitsIn
//set price
public void setPriceIn (double price)
price = priceIn;
}//end method set priceIn
//return price
public double getPriceIn()
return priceIn;
}//end method getPriceIn
}//end class Product
* InventoryPart1.java
* @author Amy Summers
public class InventoryPart1
private String Productname;//product name for this
InventoryPart1
//constructor initializes productName
public InventoryPart1(String name, double number,
double units, double price)
Product myProduct1 = new Product
();//initializes productName
System.out.printf("%s%s\n", "Name",
getnameIn() );//display name
System.out.printf("%s%
s\n", "Number",
getnumberIn() );//display number
System.out.printf("%s%s\n", "Units",
getunitsIn() );//display units
System.out.printf("$%.2f\n", "Price",
getpriceIn() );//display price
value = unitsIn * priceIn;//mulitple
numbers
System.out.printf("$%.2f\n",
value);//display inventory value
}//end main method
}//end class InventoryPart1* Product.java
* @author Amy Summers
* A class created as a Product
* which hold information with a constructor
//Create and manipulate a Product class.
import java.util.Scanner;//program uses Scanner
class Product
private String nameIn;
private double numberIn;//item number
private double unitsIn;//number of units in stock
private double priceIn;//price of each unit
//four-argument constructor
public Product( String nameIn, double numberIn, double unitsIn, double priceIn )
//implicit call to Object constructor occurs here
nameIn = nameIn;
numberIn = numberIn;
unitsIn = unitsIn;
priceIn = priceIn;
}//end four-argument Product constructor
// set product name
public void setNameIn (String name)
name = nameIn;
}//end method setNameIn
//return product name
public String getNameIn()
return nameIn;
}//end method getNameIn
// set number
public void setNumberIn (double number)
number = numberIn;
}//end method setNumberIn
//return number
public double getNumberIn()
return numberIn;
}//end method getNumberIn
//set units
public void setUnitsIn ( double units)
units = unitsIn;
}//end method setUnitsIn
//return units
public double getUnitsIn()
return unitsIn;
}//end method getUnitsIn
//set price
public void setPriceIn (double price)
price = priceIn;
}//end method set priceIn
//return price
public double getPriceIn()
return priceIn;
}//end method getPriceIn
}//end class Product
* InventoryPart1.java
* @author Amy Summers
public class InventoryPart1
private String Productname;//product name for this InventoryPart1
//constructor initializes productName
public InventoryPart1(String name, double number, double units, double price)
Product myProduct1 = new Product();//initializes productName
System.out.printf("%s%s\n", "Name",
getnameIn() );//display name
System.out.printf("%s%s\n", "Number",
getnumberIn() );//display number
System.out.printf("%s%s\n", "Units",
getunitsIn() );//display units
System.out.printf("$%.2f\n", "Price",
getpriceIn() );//display price
value = unitsIn * priceIn;//mulitple numbers
System.out.printf("$%.2f\n", value);//display inventory value
}//end main method
}//end class InventoryPart1Sorry about that. -
Help with Paint program.
Hello. I am somewhat new to Java and I was recently assigned to do a simple paint program. I have had no trouble up until my class started getting into the graphical functions of Java. I need help with my program. I am supposed to start off with a program that draws lines and changes a minimum of 5 colors. I have the line function done but my color change boxes do not work and I am able to draw inside the box that is supposed to be reserved for color buttons. Here is my code so far:
// Lab13110.java
// The Lab13 program assignment is open ended.
// There is no provided student version for starting, nor are there
// any files with solutions for the different point versions.
// Check the Lab assignment document for additional details.
import java.applet.Applet;
import java.awt.*;
public class Lab13110 extends Applet
int[] startX,startY,endX,endY;
int currentStartX,currentStartY,currentEndX,currentEndY;
int lineCount;
Rectangle red, green, blue, yellow, black;
int numColor;
Image virtualMem;
Graphics gBuffer;
int rectheight,rectwidth;
public void init()
startX = new int[100];
startY = new int[100];
endX = new int[100];
endY = new int[100];
lineCount = 0;
red = new Rectangle(50,100,25,25);
green = new Rectangle(50,125,25,25);
blue = new Rectangle(50,150,25,25);
yellow = new Rectangle(25,112,25,25);
black = new Rectangle(25,137,25,25);
numColor = 0;
virtualMem = createImage(100,600);
gBuffer = virtualMem.getGraphics();
gBuffer.drawRect(0,0,100,600);
public void paint(Graphics g)
for (int k = 0; k < lineCount; k++)
g.drawLine(startX[k],startY[k],endX[k],endY[k]);
g.drawLine(currentStartX,currentStartY,currentEndX,currentEndY);
g.setColor(Color.red);
g.fillRect(50,100,25,25);
g.setColor(Color.green);
g.fillRect(50,125,25,25);
g.setColor(Color.blue);
g.fillRect(50,150,25,25);
g.setColor(Color.yellow);
g.fillRect(25,112,25,25);
g.setColor(Color.black);
g.fillRect(25,137,25,25);
switch (numColor)
case 1:
g.setColor(Color.red);
break;
case 2:
g.setColor(Color.green);
break;
case 3:
g.setColor(Color.blue);
break;
case 4:
g.setColor(Color.yellow);
break;
case 5:
g.setColor(Color.black);
break;
case 6:
g.setColor(Color.black);
break;
g.setColor(Color.black);
g.drawRect(0,0,100,575);
public boolean mouseDown(Event e, int x, int y)
currentStartX = x;
currentStartY = y;
if(red.inside(x,y))
numColor = 1;
else if(green.inside(x,y))
numColor = 2;
else if(blue.inside(x,y))
numColor = 3;
else if(yellow.inside(x,y))
numColor = 4;
else if(black.inside(x,y))
numColor = 5;
else
numColor = 6;
repaint();
return true;
public boolean mouseDrag(Event e, int x, int y)
int Rectheight = 500;
int Rectwidth = 900;
currentEndX = x;
currentEndY = y;
Rectangle window = new Rectangle(0,0,900,500);
//if (window.inside(Rectheight,Rectwidth))
repaint();
return true;
public boolean mouseUp(Event e, int x, int y)
int Rectheight = 500;
int Rectwidth = 900;
startX[lineCount] = currentStartX;
startY[lineCount] = currentStartY;
endX[lineCount] = x;
endY[lineCount] = y;
lineCount++;
Rectangle window = new Rectangle(0,0,900,500);
if (window.inside(Rectheight,Rectwidth))
repaint();
return true;
public void Rectangle(Graphics g, int x, int y)
g.setColor(Color.white);
Rectangle screen = new Rectangle(100,0,900,600);
}If anyone could point me in the right direction of how to go about getting my buttons to work and fixing the button box, I would be greatly appreciative. I just need to get a little bit of advice and I think I should be good after I get this going.
Thanks.This isn't in any way a complete solution, but I'm posting code for a mouse drag outliner. This may be preferable to how you are doing rectangles right now
you are welcome to use and modify this code but please do not change the package and make sure that you tell your teacher where you got it from
MouseDragOutliner.java
package tjacobs.ui;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Stroke;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
* See the public static method addAMouseDragOutliner
public class MouseDragOutliner extends MouseAdapter implements MouseMotionListener {
public static final BasicStroke DASH_STROKE = new BasicStroke(1.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 10.0f, new float[] {8, 8}, 0);
private boolean mUseMove = false;
private Point mStart;
private Point mEnd;
private Component mComponent;
private MyRunnable mRunner= new MyRunnable();
private ArrayList mListeners = new ArrayList(1);
public MouseDragOutliner() {
super();
public MouseDragOutliner(boolean useMove) {
this();
mUseMove = useMove;
public void mouseDragged(MouseEvent me) {
doMouseDragged(me);
public void mousePressed(MouseEvent me) {
mStart = me.getPoint();
public void mouseEntered(MouseEvent me) {
mStart = me.getPoint();
public void mouseReleased(MouseEvent me) {
Iterator i = mListeners.iterator();
Point end = me.getPoint();
while (i.hasNext()) {
((OutlineListener)i.next()).mouseDragEnded(mStart, end);
//mStart = null;
public void mouseMoved(MouseEvent me) {
if (mUseMove) {
doMouseDragged(me);
public void addOutlineListener(OutlineListener ol) {
mListeners.add(ol);
public void removeOutlineListener(OutlineListener ol) {
mListeners.remove(ol);
private class MyRunnable implements Runnable {
public void run() {
Graphics g = mComponent.getGraphics();
if (g == null) {
return;
Graphics2D g2 = (Graphics2D) g;
Stroke s = g2.getStroke();
g2.setStroke(DASH_STROKE);
int x = Math.min(mStart.x, mEnd.x);
int y = Math.min(mStart.y, mEnd.y);
int w = Math.abs(mEnd.x - mStart.x);
int h = Math.abs(mEnd.y - mStart.y);
g2.setXORMode(Color.WHITE);
g2.drawRect(x, y, w, h);
g2.setStroke(s);
public void doMouseDragged(MouseEvent me) {
mEnd = me.getPoint();
if (mStart != null) {
mComponent = me.getComponent();
mComponent.repaint();
SwingUtilities.invokeLater(mRunner);
public static MouseDragOutliner addAMouseDragOutliner(Component c) {
MouseDragOutliner mdo = new MouseDragOutliner();
c.addMouseListener(mdo);
c.addMouseMotionListener(mdo);
return mdo;
public static interface OutlineListener {
public void mouseDragEnded(Point start, Point finish);
public static void main(String[] args) {
JFrame f = new JFrame("MouseDragOutliner Test");
Container c = f.getContentPane();
JPanel p = new JPanel();
//p.setBackground(Color.BLACK);
c.add(p);
addAMouseDragOutliner(p);
f.setBounds(200, 200, 400, 400);
f.addWindowListener(new WindowClosingActions.Exit());
f.setVisible(true);
} -
Need help with Flash CS4 buttons/can't get buttons to control anything
Hello,
I need help with Flash CS4. I am making a banner with an animation (Image change into movie clip "3D Spiral") and added buttons but I cannot get the buttons to control the animation. Please help I am frustrated! If someone could help I would be most appreciated.Thank you.
Regards,
Michael J. Sheehan allelois
Date: Mon, 17 Aug 2009 18:48:09 -0600
From: [email protected]
To: [email protected]
Subject: Need help with Flash CS4 buttons/can't get buttons to control anything
Hi there
I'm not sure how you wound up where you did. But you wound up in the Adobe Captivate forums. Please stand by as I move your thread to the Flash forums.
Cheers... Rick
> -
Modify the Inventory Program by adding a button to the GUI that allows the user to move to the first item, the previous item, the next item, and the last item in the inventory. If the first item is displayed and the user clicks on the Previous button, the last item should display. If the last item is displayed and the user clicks on the Next button, the first item
should display. the GUI using Java graphics classes.
? Add a company logo to? Post as an attachment Course Syllabus
here is my code // created by Nicholas Baatz on July 24,2007
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class Inventory2
//main method begins execution of java application
public static void main(final String args[])
int i; // varialbe for looping
double total = 0; // variable for total inventory
final int dispProd = 0; // variable for actionEvents
// Instantiate a product object
final ProductAdd[] nwProduct = new ProductAdd[5];
// Instantiate objects for the array
for (i=0; i<5; i++)
nwProduct[0] = new ProductAdd("Paper", 101, 10, 1.00, "Box");
nwProduct[1] = new ProductAdd("Pen", 102, 10, 0.75, "Pack");
nwProduct[2] = new ProductAdd("Pencil", 103, 10, 0.50, "Pack");
nwProduct[3] = new ProductAdd("Staples", 104, 10, 1.00, "Box");
nwProduct[4] = new ProductAdd("Clip Board", 105, 10, 3.00, "Two Pack");
for (i=0; i<5; i++)
total += nwProduct.length; // calculate total inventory cost
final JButton firstBtn = new JButton("First"); // first button
final JButton prevBtn = new JButton("Previous"); // previous button
final JButton nextBtn = new JButton("Next"); // next button
final JButton lastBtn = new JButton("Last"); // last button
final JLabel label; // logo
final JTextArea textArea; // text area for product list
final JPanel buttonJPanel; // panel to hold buttons
//JLabel constructor for logo
Icon logo = new ImageIcon("C:/logo.jpg"); // load logo
label = new JLabel(logo); // create logo label
label.setToolTipText("Company Logo"); // create tooltip
buttonJPanel = new JPanel(); // set up panel
buttonJPanel.setLayout( new GridLayout(1, 4)); //set layout
// add buttons to buttonPanel
buttonJPanel.add(firstBtn);
buttonJPanel.add(prevBtn);
buttonJPanel.add(nextBtn);
buttonJPanel.add(lastBtn);
textArea = new JTextArea(nwProduct[3]+"\n"); // create textArea for product display
// add total inventory value to GUI
textArea.append("\nTotal value of Inventory "+new java.text.DecimalFormat("$0.00").format(total)+"\n\n");
textArea.setEditable(false); // make text uneditable in main display
JFrame invFrame = new JFrame(); // create JFrame container
invFrame.setLayout(new BorderLayout()); // set layout
invFrame.getContentPane().add(new JScrollPane(textArea), BorderLayout.CENTER); // add textArea to JFrame
invFrame.getContentPane().add(buttonJPanel, BorderLayout.SOUTH); // add buttons to JFrame
invFrame.getContentPane().add(label, BorderLayout.NORTH); // add logo to JFrame
invFrame.setTitle("Office Min Inventory"); // set JFrame title
invFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // termination command
//invFrame.pack();
invFrame.setSize(400, 400); // set size of JPanel
invFrame.setLocationRelativeTo(null); // set screem location
invFrame.setVisible(true); // display window
// assign actionListener and actionEvent for each button
firstBtn.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent ae)
textArea.setText(nwProduct[0]+"\n");
} // end firstBtn actionEvent
}); // end firstBtn actionListener
textArea.setText(nwProduct[4]+"n");
// prevBtn.addActionListener(new ActionListener()
// public void actionPerformed(ActionEvent ae)
// dispProd = (nwProduct.length+dispProd-1) % nwProduct.length;
// textArea.setText(nwProduct.display(dispProd)+"\n");
// } // end prevBtn actionEvent
// }); // end prevBtn actionListener
} // end main
} // end class Inventory2
class Product
protected String prodName; // name of product
protected int itmNumber; // item number
protected int units; // number of units
protected double price; // price of each unit
protected double value; // value of total units
public Product(String name, int number, int unit, double each) // Constructor for class Product
prodName = name;
itmNumber = number;
units = unit;
price = each;
} // end constructor
public void setProdName(String name) // method to set product name
prodName = name;
public String getProdName() // method to get product name
return prodName;
public void setItmNumber(int number) // method to set item number
itmNumber = number;
public int getItmNumber() // method to get item number
return itmNumber;
public void setUnits(int unit) // method to set number of units
units = unit;
public int getUnits() // method to get number of units
return units;
public void setPrice(double each) // method to set price
price = each;
public double getPrice() // method to get price
return price;
public double calcValue() // method to set value
return units * price;
} // end class Product
class ProductAdd extends Product
private String feature; // variable for added feature
public ProductAdd(String name, int number, int unit, double each, String addFeat)
// call to superclass Product constructor
super(name, number, unit, each);
feature = addFeat;
}// end constructor
public void setFeature(String addFeat) // method to set added feature
feature = addFeat;
public String getFeature() // method to get added feature
return feature;
public double calcValueRstk() // method to set value and add restock fee
return units * price * 0.05;
public String toString()
return String.format("Product: %s\nItem Number: %d\nIn Stock: %d\nPrice: $%.2f\nType: %s\nTotal Value of Stock: $%.2f\nRestock Cost: $%.2f\n\n\n",
getProdName(), getItmNumber(), getUnits(), getPrice(), getFeature(), calcValue(), calcValueRstk());
} // end class ProductAddI can not get all the buttons to work and do not know why can someone help meYou have to have your code formatted correctly to begin with before you add the code tags. All your current code is left-justified and is not indented correctly.
I only see that you've added an actionlistener to the "first" button.
I recommend that you:
1) again, do this first in a nonGUI class, then use this nonGUI class in your GUI class.
2) Have a integer variable that holds the location of the current Product that your application is pointing to.
3) Have a method called getProduct(int index) that returns the product that is at the location specified by the index in your array / arraylist / or whatever collection that you are using.
4) Have your first button set index to 0 and then call getProduct(index).
5) Have your last button set your index to the last product in your collection (i.e.: index = productCollection.length - 1 if this is an array), and then call getProduct(index).
5) Have your next button increment your index up to the maximum allowed and then call getProduct(index). If it's an array it goes up to the array length - 1.
6) If you want the next button to cause the index to roll over to the first, when you are at the last then then increment the index and mod it ("%" operator) by the length of the array... -
Need help with inverter program
I am very new to labview and I need a lot of help fast. I have been given this vi program, which I have attached, that operates a bunch of inverters. The program is driving the inverter which in turn drives the agitator on a washing machine. The agitator goes in forward and reverse direction as a result of a relay within the inverter being supplied voltage to make it open and close. I need to supply voltage to the relay to make it go forward, reverse, and the pause before the next cycle begins. The current program has it doing a forward reverse and then immediately starts the next cycle. If any one can take a look at this program and let me know, first of all what the heck is going on, and second how to fix my problem, that would be incredibly helpful to me. If anyone has trouble opening the file let me know, I think attaching the vi should work but it may also look for a dll file or something when trying to open. Email me if you cannot open the file and I will send you the dll file as well. Your help is greatly appreciated. Thank you very much.
Tony
Attachments:
main2.vi 162 KBHello Tony,
you programmed it to run continously...
After the timed while loop runs through your array of ramp values you start again at index 0 (upper shift register). Instead of this end this while loop by combining the output from the comparison with your stop2 button (end loop when stop2 OR end of arrray). Now it will work.
Btw. why do you use "Insert to Array" when you want to concat 3 arrays (sequence frame 0)? Just use a "Build Array" and set "Concat Inputs" via mouse right-click.
Best regards,
GerdW
Best regards,
GerdW
CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
Kudos are welcome -
Need help with basic program.....!
I've to write a program that generates a random number, which the user has to try and guess, after each guess they're told whether it's too high or too low etc., I've gotten this far, however, the user has only 10 guesses.... In my program I've used a while loop and the user gets an infinite number of guesses, I know I'm supposed to use a for loop, but can't seem to get it to work properly. Also, when the user guesses the number, the program then has to print out how many guesses it took, and I have no idea how to get it to do this AT ALL!!! I'd really appreciate some help with this, thanks v. much!!!!
I've to write a program that generates a random
number, which the user has to try and guess, after
each guess they're told whether it's too high or too
low etc., I've gotten this far, however, the user has
only 10 guesses.... In my program I've used a while
loop and the user gets an infinite number of guesses,
I know I'm supposed to use a for loop, but can't seem
to get it to work properly. Also, when the user
guesses the number, the program then has to print out
how many guesses it took, and I have no idea how to
get it to do this AT ALL!!! I'd really appreciate some
help with this, thanks v. much!!!!Hey not every book covers every aspect of Java (if you haven't got a book and don't want to buy 1 i recommend an online tutorial) If u want the user to have an infinate number of guesses, use an infinate while loop. Put this in a file called app.java:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class app extends Applet implements ActionListener
JLabel lbl=new JLabel("Guess a number between 0 and 10:");
JTextField txtfield=new JTextField(20);
JButton button=new JButton("Guess...");
JLabel lbl2=new JLabel();
int randomnumber=Math.round((float)Math.random()*10);
public void init()
add(lbl);
add(txtfield);
add(button);
button.addActionListener(this);
public void actionPerformed (ActionEvent e)
String s=new String("");
s+=randomnumber;
if (e.getSource().equals(button) && txtfield.getText().equals(s))
setBackground(Color.white);
setForeground(Color.black);
lbl2.setText("Got it!");
add(lbl2);
validate();
else
setBackground(Color.white);
setForeground(Color.black);
if (Integer.parseInt(txtfield.getText())>randomnumber)
lbl2.setText("Too High!");
else
lbl2.setText("Too Low!");
add(lbl2);
validate();
Then create a HTML document in the classes folder:
<HTML>
<HEAD>
<TITLE>APPLET</TITLE>
</HEAD>
<BODY>
<HR>
<CENTER>
<APPLET
CODE=app.class
WIDTH=400
HEIGHT=200 >
</APPLET>
</CENTER>
<HR>
</BODY>
</HTML>
It will do what you wish. If you want to have more then 10 numbers to guess, for example 100, do this:
int randomnumber=Math.round((float)Math.random()*100);
Does that answer your question? -
Help with Find / Replace button title tag contents (text)
Hi there,
I designed my site with Sitegrinder (Medialab) –
Currently all the title tags generated for buttons are the same as
the actual html page name.
The problem with this is that the tooltip which appears in
browsers when you hover over the button with the mouse gives you
the page name. Instead I want to use these tooltips to give the
user an indication of what the function of the button is.
An example: A zoom button above an image: Currenty the
tootlip says “zoom imagename pagename” – Instead
it should say “click here to zoom”.
I need help to get the Dreamweaver Find and Replace tool to
batch replace these tags for me for about a 100 pages.
Here is an example of the code:
<body>
<div id="id1zoomimpastooilweddingbutton"><a
href="zoomimpastooilwedding.html"
title="zoomimpastooilwedding"></a></div>
I only want to replace the text in the title tag - Since the
text “zoom” appears several times in the body, I
can’t get the Find tool to pick up and Replace the occurrence
of “zoom” in the title only…….
Options I’ve tried:
Search Current document: Search for: “specific
tag”: “title”, “containing”:
“text” = zoom (I’ve tried this with
“zoomimpastooilwedding” and zoom[^”]* with no
results
I’ve also tried: Search for: “specific
tag”: “body”, “containing”:
“specific tag” “title”
“containing”: “text” = zoom
etc……………..
I need help with what parameters to enter in order to find
and replace all the text within the title tag with my own text
Thanks very much!
AntonYou have ~ 100 pages, each of which has images with title
attributes (not
tags), all of which BEGIN with the letters "zoom"?
What do you want to replace that text with? Wouldn't it be
different for
each button? Or do you mean that you would do multiple
sitewide searches,
one for each button? This illustrates how wrong it is to not
use DW
Templates or server-side includes to simplify the management
of your
navigation elements....
Did you ask Medialabs if it would be possible to specify this
before
generating the HTML?
How did you like working with SiteGrinder? It looks like a
nice product to
me, although I'm not fond of the final results code-wise....
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go
- DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs,
Tutorials & Resources
==================
"unison123" <[email protected]> wrote in
message
news:[email protected]...
> Hi there,
>
> I designed my site with Sitegrinder (Medialab) ?
Currently all the title
> tags
> generated for buttons are the same as the actual html
page name.
>
> The problem with this is that the tooltip which appears
in browsers when
> you
> hover over the button with the mouse gives you the page
name. Instead I
> want to
> use these tooltips to give the user an indication of
what the function of
> the
> button is.
>
> An example: A zoom button above an image: Currenty the
tootlip says ?zoom
> imagename pagename? ? Instead it should say ?click here
to zoom?.
>
> I need help to get the Dreamweaver Find and Replace tool
to batch replace
> these tags for me for about a 100 pages.
>
> Here is an example of the code:
>
> <body>
> <div id="id1zoomimpastooilweddingbutton"><a
> href="zoomimpastooilwedding.html"
> title="zoomimpastooilwedding"></a></div>
>
> I only want to replace the text in the title tag - Since
the text ?zoom?
> appears several times in the body, I can?t get the Find
tool to pick up
> and
> Replace the occurrence of ?zoom? in the title only??.
>
> Options I?ve tried:
>
> Search Current document: Search for: ?specific tag?:
?title?,
> ?containing?:
> ?text? = zoom (I?ve tried this with
?zoomimpastooilwedding? and zoom[^?]*
> with
> no results
>
> I?ve also tried: Search for: ?specific tag?: ?body?,
?containing?:
> ?specific
> tag? ?title? ?containing?: ?text? = zoom etc?????..
>
> I need help with what parameters to enter in order to
find and replace all
> the
> text within the title tag with my own text
>
> Thanks very much!
>
> Anton
>
> -
Need some help with a program Please.
Well, im new here, im new to java, so i need your help, i have to make a connect four program, my brother "Kind of" helped me and did a program for me, but the problem is i cant use some of those commands in the program and i have to replace them with what ive learned, so i will post the program and i will need your help to modify it for me.
and for these programs, also i want help for:
They have errors and i cant fix'em
the commands that i've leaned:
If statements, for loops, while loops,do while, strings, math classes, swithc statement, else if,logical operators,methods, one and two dimensional arrays.
Thanx in advance,
truegunner
// Fhourstones 3.0 Board Logic
// Copyright 2000-2004 John Tromp
import java.io.*;
class Connect4 {
static long color[]; // black and white bitboard
static final int WIDTH = 7;
static final int HEIGHT = 6;
// bitmask corresponds to board as follows in 7x6 case:
// . . . . . . . TOP
// 5 12 19 26 33 40 47
// 4 11 18 25 32 39 46
// 3 10 17 24 31 38 45
// 2 9 16 23 30 37 44
// 1 8 15 22 29 36 43
// 0 7 14 21 28 35 42 BOTTOM
static final int H1 = HEIGHT+1;
static final int H2 = HEIGHT+2;
static final int SIZE = HEIGHT*WIDTH;
static final int SIZE1 = H1*WIDTH;
static final long ALL1 = (1L<<SIZE1)-1L; // assumes SIZE1 < 63
static final int COL1 = (1<<H1)-1;
static final long BOTTOM = ALL1 / COL1; // has bits i*H1 set
static final long TOP = BOTTOM << HEIGHT;
int moves[],nplies;
byte height[]; // holds bit index of lowest free square
public Connect4()
color = new long[2];
height = new byte[WIDTH];
moves = new int[SIZE];
reset();
void reset()
nplies = 0;
color[0] = color[1] = 0L;
for (int i=0; i<WIDTH; i++)
height[i] = (byte)(H1*i);
public long positioncode()
return 2*color[0] + color[1] + BOTTOM;
// color[0] + color[1] + BOTTOM forms bitmap of heights
// so that positioncode() is a complete board encoding
public String toString()
StringBuffer buf = new StringBuffer();
for (int i=0; i<nplies; i++)
buf.append(1+moves);
buf.append("\n");
for (int w=0; w<WIDTH; w++)
buf.append(" "+(w+1));
buf.append("\n");
for (int h=HEIGHT-1; h>=0; h--) {
for (int w=h; w<SIZE1; w+=H1) {
long mask = 1L<<w;
buf.append((color[0]&mask)!= 0 ? " @" :
(color[1]&mask)!= 0 ? " 0" : " .");
buf.append("\n");
if (haswon(color[0]))
buf.append("@ won\n");
if (haswon(color[1]))
buf.append("O won\n");
return buf.toString();
// return whether columns col has room
final boolean isplayable(int col)
return islegal(color[nplies&1] | (1L << height[col]));
// return whether newboard lacks overflowing column
final boolean islegal(long newboard)
return (newboard & TOP) == 0;
// return whether newboard is legal and includes a win
final boolean islegalhaswon(long newboard)
return islegal(newboard) && haswon(newboard);
// return whether newboard includes a win
final boolean haswon(long newboard)
long y = newboard & (newboard>>HEIGHT);
if ((y & (y >> 2*HEIGHT)) != 0) // check diagonal \
return true;
y = newboard & (newboard>>H1);
if ((y & (y >> 2*H1)) != 0) // check horizontal -
return true;
y = newboard & (newboard>>H2); // check diagonal /
if ((y & (y >> 2*H2)) != 0)
return true;
y = newboard & (newboard>>1); // check vertical |
return (y & (y >> 2)) != 0;
void backmove()
int n;
n = moves[--nplies];
color[nplies&1] ^= 1L<<--height[n];
void makemove(int n)
color[nplies&1] ^= 1L<<height[n]++;
moves[nplies++] = n;
public static void main(String argv[])
Connect4 c4;
String line;
int col=0, i, result;
long nodes, msecs;
c4 = new Connect4();
c4.reset();
BufferedReader dis = new BufferedReader(new InputStreamReader(System.in));
for (;;) {
System.out.println("position " + c4.positioncode() + " after moves " + c4 + "enter move(s):");
try {
line = dis.readLine();
} catch (IOException e) {
System.out.println(e);
System.exit(0);
return;
if (line == null)
break;
for (i=0; i < line.length(); i++) {
col = line.charAt(i) - '1';
if (col >= 0 && col < WIDTH && c4.isplayable(col))
c4.makemove(col);
By the way im using Ready to program for the programming.You can't really believe that his brother did this
for him...I did miss that copyright line at the beginning when
I first looked it over, but you know, if it had been
his brother, I'd be kinda impressed. This wasn't a
25 line program. It actually would have required
SOME thought. I doubt my brother woulda done that
for me (notwithstanding the fact that I wouldn't need
help for that program, and my brother isn't a
programmer).I originally missed the comments at the top but when I saw the complexity of what was written then I knew that it was too advanced for a beginner and I relooked through the code and saw the comments. -
Hello I need help with the following code for a Payroll program.
//CheckPoint: Payroll Program Part 3
//Java Programming IT215
//Arianne Gallegos
//05/02/2007
//Payroll3.java
//Payroll program that calculates the weekly pay for an employee.
import java.util.Scanner; // program uses class Scanner
public class Payroll3
private string name;
private double rate;
private double hours;
// Constructor to store Employee Data
public EmployeeData( String nameOfEmployee, double hourlyRate, double hoursWorked )
name = nameOfEmployee;
rate = hourlyRate;
hours = hoursWorked;
} // end constructor
} //end class EmployeeData
// main method begins execution of java application
public static void main( String args[] )
System.out.println( "Welcome to the Payroll Program! " );
boolean quit = false; // This flag will control whether we exit the loop below
// Loop until user types "quit" as the employee name:
while (!quit)
// create scanner to obtain input from command window
Scanner input = new Scanner ( System.in );
System.out.println(); // outputs a blank line
System.out.print( "Please enter the employee name or quit to terminate program: " );
// prompt for and input employee name
String nameOfEmployee = input.nextLine(); // read what user has inputted
if ( nameOfEmployee.equals("quit")) // Check whether user indicated to quit program
System.out.println( "Program has ended" );
quit = true;
else
// User did not indicate to stop, so continue reading info for this iteration:
float hourlyRate; // first number to multiply
float hoursWorked; // second number to multiply
float product; // product of hourlyRate and hoursWorked
System.out.print( "Enter hourly rate: " ); // prompt
hourlyRate = input.nextFloat(); // read first number from user
while (hourlyRate <= 0) // prompt until a positive value is entered
System.out.print( "Hourly rate must be a positive value. " +
"Please enter the hourly rate again: " ); // prompt for positive value for hourly rate
hourlyRate = input.nextFloat(); // read first number again
System.out.print( "Enter hours worked: " ); // prompt
hoursWorked = input.nextFloat(); // read second number from user
while (hoursWorked <= 0) // prompt until a positive value is entered
System.out.print( "Hours worked must be a positive value. " +
"Please enter the hours worked again: " ); // prompt for positive value for hours worked
hoursWorked = input.nextFloat(); // read second number again
product = (float) hourlyRate * hoursWorked; // multiply the hourly rate by the hours worked
// Display output for this iteration
System.out.println(); // outputs a blank line
System.out.print( nameOfEmployee ); // display employee name
System.out.printf( "'s weekly pay is: $%,.2f\n", product); // display product
System.out.println(); // outputs a blank line
// Display ending message:
System.out.println( "Thank you for using the Payroll program!" );
System.out.println(); // outputs a blank line
} // end method main
} // end class Payroll3I am getting the following errors:
Payroll3.java:18: invalid method declaration; return type required
public EmployeeData( String nameOfEmployee, double hourlyRate, double hours
Worked )
^
Payroll3.java:28: class, interface, or enum expected
public static void main( String args[] )
^
Payroll3.java:33: class, interface, or enum expected
boolean quit = false; // This flag will control whether we exit the loop b
elow
^
Payroll3.java:36: class, interface, or enum expected
while (!quit)
^
Payroll3.java:42: class, interface, or enum expected
System.out.println(); // outputs a blank line
^
Payroll3.java:43: class, interface, or enum expected
System.out.print( "Please enter the employee name or quit to terminate p
rogram: " );
^
Payroll3.java:45: class, interface, or enum expected
String nameOfEmployee = input.nextLine(); // read what user has inputted
^
Payroll3.java:48: class, interface, or enum expected
if ( nameOfEmployee.equals("quit")) // Check whether user indicated to q
uit program
^
Payroll3.java:51: class, interface, or enum expected
quit = true;
^
Payroll3.java:52: class, interface, or enum expected
^
Payroll3.java:57: class, interface, or enum expected
float hoursWorked; // second number to multiply
^
Payroll3.java:58: class, interface, or enum expected
float product; // product of hourlyRate and hoursWorked
^
Payroll3.java:60: class, interface, or enum expected
System.out.print( "Enter hourly rate: " ); // prompt
^
Payroll3.java:61: class, interface, or enum expected
hourlyRate = input.nextFloat(); // read first number from user
^
Payroll3.java:64: class, interface, or enum expected
while (hourlyRate <= 0) // prompt until a positive value is entered
^
Payroll3.java:68: class, interface, or enum expected
hourlyRate = input.nextFloat(); // read first number again
^
Payroll3.java:69: class, interface, or enum expected
^
Payroll3.java:72: class, interface, or enum expected
hoursWorked = input.nextFloat(); // read second number from user
^
Payroll3.java:75: class, interface, or enum expected
while (hoursWorked <= 0) // prompt until a positive value is entered
^
Payroll3.java:79: class, interface, or enum expected
hoursWorked = input.nextFloat(); // read second number again
^
Payroll3.java:80: class, interface, or enum expected
^
Payroll3.java:86: class, interface, or enum expected
System.out.println(); // outputs a blank line
^
Payroll3.java:87: class, interface, or enum expected
System.out.print( nameOfEmployee ); // display employee name
^
Payroll3.java:88: class, interface, or enum expected
System.out.printf( "'s weekly pay is: $%,.2f\n", product); // display
product
^
Payroll3.java:89: class, interface, or enum expected
System.out.println(); // outputs a blank line
^
Payroll3.java:91: class, interface, or enum expected
^
Payroll3.java:96: class, interface, or enum expected
System.out.println(); // outputs a blank line
^
Payroll3.java:98: class, interface, or enum expected
} // end method main
^
The problem I am having is getting the constructor to work with the rest of the program can someone please point out to me how to correct this. I have read my textbook as well as tutorials but I just don't seem to get it right. Please help.
P.S. I have never taken a programming class before so please be kind.Ok, I changed the name of the constructor:
//CheckPoint: Payroll Program Part 3
//Java Programming IT215
//Arianne Gallegos
//04/23/2007
//Payroll3.java
//Payroll program that calculates the weekly pay for an employee.
import java.util.Scanner; // program uses class Scanner
public class Payroll3
private string name;
private float rate;
private float hours;
// Constructor to store Employee Data
public void Payroll3( string nameOfEmployee, float hourlyRate, float hoursWorked )
name = nameOfEmployee;
rate = hourlyRate;
hours = hoursWorked;
} // end constructor
} //end class EmployeeData
// main method begins execution of java application
public static void main( String args[] )
System.out.println( "Welcome to the Payroll Program! " );
boolean quit = false; // This flag will control whether we exit the loop below
// Loop until user types "quit" as the employee name:
while (!quit)
// create scanner to obtain input from command window
Scanner input = new Scanner ( System.in );
System.out.println(); // outputs a blank line
System.out.print( "Please enter the employee name or quit to terminate program: " );
// prompt for and input employee name
String nameOfEmployee = input.nextLine(); // read what user has inputted
if ( nameOfEmployee.equals("quit")) // Check whether user indicated to quit program
System.out.println( "Program has ended" );
quit = true;
else
// User did not indicate to stop, so continue reading info for this iteration:
float hourlyRate; // first number to multiply
float hoursWorked; // second number to multiply
float product; // product of hourlyRate and hoursWorked
System.out.print( "Enter hourly rate: " ); // prompt
hourlyRate = input.nextFloat(); // read first number from user
while (hourlyRate <= 0) // prompt until a positive value is entered
System.out.print( "Hourly rate must be a positive value. " +
"Please enter the hourly rate again: " ); // prompt for positive value for hourly rate
hourlyRate = input.nextFloat(); // read first number again
System.out.print( "Enter hours worked: " ); // prompt
hoursWorked = input.nextFloat(); // read second number from user
while (hoursWorked <= 0) // prompt until a positive value is entered
System.out.print( "Hours worked must be a positive value. " +
"Please enter the hours worked again: " ); // prompt for positive value for hours worked
hoursWorked = input.nextFloat(); // read second number again
product = (float) hourlyRate * hoursWorked; // multiply the hourly rate by the hours worked
// Display output for this iteration
System.out.println(); // outputs a blank line
System.out.print( nameOfEmployee ); // display employee name
System.out.printf( "'s weekly pay is: $%,.2f\n", product); // display product
System.out.println(); // outputs a blank line
// Display ending message:
System.out.println( "Thank you for using the Payroll program!" );
System.out.println(); // outputs a blank line
} // end method main
} // end class Payroll3I still get the following error codes:
C:\IT215\Payroll3>javac Payroll3.java
Payroll3.java:28: class, interface, or enum expected
public static void main( String args[] )
^
Payroll3.java:33: class, interface, or enum expected
boolean quit = false; // This flag will control whether we exit the loop b
elow
^
Payroll3.java:36: class, interface, or enum expected
while (!quit)
^
Payroll3.java:42: class, interface, or enum expected
System.out.println(); // outputs a blank line
^
Payroll3.java:43: class, interface, or enum expected
System.out.print( "Please enter the employee name or quit to terminate p
rogram: " );
^
Payroll3.java:45: class, interface, or enum expected
String nameOfEmployee = input.nextLine(); // read what user has inputted
^
Payroll3.java:48: class, interface, or enum expected
if ( nameOfEmployee.equals("quit")) // Check whether user indicated to q
uit program
^
Payroll3.java:51: class, interface, or enum expected
quit = true;
^
Payroll3.java:52: class, interface, or enum expected
^
Payroll3.java:57: class, interface, or enum expected
float hoursWorked; // second number to multiply
^
Payroll3.java:58: class, interface, or enum expected
float product; // product of hourlyRate and hoursWorked
^
Payroll3.java:60: class, interface, or enum expected
System.out.print( "Enter hourly rate: " ); // prompt
^
Payroll3.java:61: class, interface, or enum expected
hourlyRate = input.nextFloat(); // read first number from user
^
Payroll3.java:64: class, interface, or enum expected
while (hourlyRate <= 0) // prompt until a positive value is entered
^
Payroll3.java:68: class, interface, or enum expected
hourlyRate = input.nextFloat(); // read first number again
^
Payroll3.java:69: class, interface, or enum expected
^
Payroll3.java:72: class, interface, or enum expected
hoursWorked = input.nextFloat(); // read second number from user
^
Payroll3.java:75: class, interface, or enum expected
while (hoursWorked <= 0) // prompt until a positive value is entered
^
Payroll3.java:79: class, interface, or enum expected
hoursWorked = input.nextFloat(); // read second number again
^
Payroll3.java:80: class, interface, or enum expected
^
Payroll3.java:86: class, interface, or enum expected
System.out.println(); // outputs a blank line
^
Payroll3.java:87: class, interface, or enum expected
System.out.print( nameOfEmployee ); // display employee name
^
Payroll3.java:88: class, interface, or enum expected
System.out.printf( "'s weekly pay is: $%,.2f\n", product); // display
product
^
Payroll3.java:89: class, interface, or enum expected
System.out.println(); // outputs a blank line
^
Payroll3.java:91: class, interface, or enum expected
^
Payroll3.java:96: class, interface, or enum expected
System.out.println(); // outputs a blank line
^
Payroll3.java:98: class, interface, or enum expected
} // end method main
^
27 errors
Any other suggestions? -
Help With Scrolling Menu / Button Rollovers
First thank you to anyone who can answer and help with this
question.
http://paragon.sortismarketing.com
- at this link I have created a site with a simple scrolling menu.
Now what I want to happen is when you rollOver the buttons on the
scrolling menu they get larger and then smaller again after you
roll off them.
I know how to do this with tweening in a non moving
environment, by making them a movie clip instead of button. But for
some reason when I did this in this case it screwed the menu all up
and made it go crazy. Is there a way to do this with action script
that isn't going to screw up the underlying code for the
scrolling?You can use the below code also. As your mouse pointer goes
over the down, it will scroll down.
on(rollOver){
scrolltext.scroll -= 1; -
I seem to be having a little problem with my program. In my main program, depending on which method comes first, the other methods wont work for example the way my main program is not, with occurance method before removeLetter method, the occurance method works fine, but my removeLetter meth won't remove the letter. But if i switch the two and have removeLetter first then it will remove the letter, but my occurance method will come back say the letter is not in the word even when it is...can someone help me? Thanx in advance...
class CharacterRecurrance{
private int i=0;
private int occur=0;
void inString(String s, char n){
if(i<s.length()){
if(s.charAt(i)==n)
System.out.println("Yes, the letter" + " " + n + " " + "is present");
else{
i++;
inString(s,n);
else System.out.println("No, the letter" + " " + n + " " + "is not present");
void occurance(String s, char n){
if(i < s.length()){
if(s.charAt(i)==n){
occur++;
i++;
occurance(s,n);
else{
i++;
occurance(s,n);
else System.out.println("The letter" + " " + n + " " + "appears" + " " + occur + " " + "times");
void removeLetter(String s, char n){
if(i < s.length()){
if(s.charAt(i)==n){
s = s.replace(s.charAt(i),' ');
i++;
removeLetter(s,n);
else{
i++;
removeLetter(s,n);
else System.out.println(s);
class Program3_10{
public static void main(String[] a) {
CharacterRecurrance find = new CharacterRecurrance();
String word = "mississippi";
char letter = 's';
find.inString(word, letter);
System.out.println();
find.occurance(word, letter);
System.out.println();
find.removeLetter(word, letter);
}Or make it zero in the last step of each function. Like this-void occurance(String s, char n){
if(i < s.length()){
if(s.charAt(i)==n){
occur++;
i++;
occurance(s,n);
else{
i++;
occurance(s,n);
else{
System.out.println("The letter" + " " + n + " " + "appears" + " " + occur + " " + "times");
i=0; // reset to zero.
} -
hi,
i study java at school and i need help with my project.
im doing a simple demonstration of a pathfinding program whose algoritm i read off Wikipedia (http://en.wikipedia.org/wiki/Pathfinding)where the co-ordinates of the start and end points
are entered and the route is calculated as a list of co-ordinates. Here is the section of code i am having trouble with-
void find_path(int x,int y,int p,int q)
int t1;int t2;
int temp_pool[][]=new int[4][3];//stores contagious cells of elements in grid pool
int grid_pool[][]= new int[100000][3];
int pass_pool[][]=new int[4][3];//stores the pool of squares which can be added to the list of direction
int path[][]= new int[10000][3];//stores actual path
int count=1;int note=10;int kk=0;
int curx,cury;
//the above arrays contain 3 columns - to store x and y co-ordinate and a counter variable(the purpose of which will become clear later)
grid_pool[0][0]=p;
grid_pool[0][1]=q;
grid_pool[0][2]=0;
int counter=grid_pool[0][2];
for(int i=0;i<=100;i++)
counter++;
curx=grid_pool[0];
cury=grid_pool[i][1];
temp_pool[0][0]=curx-1;
temp_pool[0][1]=cury;
temp_pool[0][2]=counter;
temp_pool[0][0]=curx;
temp_pool[0][1]=cury-1;
temp_pool[0][2]=counter;
temp_pool[0][0]=curx+1;
temp_pool[0][1]=cury;
temp_pool[0][2]=counter;
temp_pool[0][0]=curx;
temp_pool[0][1]=cury+1;
temp_pool[0][2]=counter;
int pass=0;
for(int j=0;j<=3;j++)
int check=0;
int in=temp_pool[j][0];
int to=temp_pool[j][1];
if(activemap[in][to]=='X')
{check++;}
if(linear_search(grid_pool,in,to)==false)
{check++;}
if(check==2)
pass_pool[pass][0]=in;
pass_pool[pass][1]=to;
pass++;
}//finding which co-ordinates are not walls and which are not already present
for(int k=0;k<=pass_pool.length-1;k++)
grid_pool[count][0]=pass_pool[k][0];
grid_pool[count][1]=pass_pool[k][1];
count++;
if(linear_search(grid_pool,x,y)==true)
break;
//in this part we have isolated the squares which run in the approximate direction of the goal
//in the next part we will isolate the exact co-ordinates in another array called path
int yalt=linear_searchwindex(grid_pool,p,q);
t1=grid_pool[yalt][2];
int g1;int g2;int g3;
for(int u=yalt;u>=0;u--)
g3=find_next(grid_pool,p,q);
g2=g3/10;
g1=g3%10;
path[0]=g2;
path[u][1]=g3;
path[u][2]=u;
for(int v=0;v<=yalt;v++)
System.out.println(path[v][0]+','+path[v][1]);
ill be grateful if anyone can fix it. im done with the rest thoughdeath_star12 wrote:
hi,
i study java at school and i need help with my project.
im doing a simple demonstration of a pathfinding program whose algoritm i read off Wikipedia (http://en.wikipedia.org/wiki/Pathfinding)where the co-ordinates of the start and end points
are entered and the route is calculated as a list of co-ordinates. Here is the section of code i am having trouble with-
...The part "i am having trouble with" means absolutely nothing to the people who are answering questions here. It's like going to the doctor with a broken rib and just saying "doc, I don't feel so well". Get my point?
Also, please take the trouble to properly spell words and use a bit of capitalization. Your question is hard to read as it is, which will most probably cause (some) people not to help you. And lastly, please use code tags when posting code: it makes it so much easier to read (see: [Formatting Messages|http://mediacast.sun.com/users/humanlever/media/forums_text_editor.mp4]).
Thanks.
Maybe you are looking for
-
How to convert a date value into week value?
How to display the date value like '20010203' into the week number of the year 2001? When i type in the following sql select week(chg_time) from site; I got this error message ORA-00904: invalid column name
-
I am receiving a message saying the iPod "TRACER's iPod" can not be synched. The required file can not be found. I ran the iTunes program repair and restarted both the computer and the iPod. but still receive the same message. Any suggestions on what
-
Hi, I have some doubt in ASM Upgrade and thats what I would like to discuss this issue here.If I am going to upgrade database,clusterware and asm then the approach should be like below:--> Database version from 10.1.0.5 to 10.2.0.4 OS AIX 5.3 TL8 (1)
-
i hve sony xperia z1 nd my left ear phones not working i hd checked lots of handfrees but problems still same left earphones not working i m da sony fan plzz help me how to resolve ds problme Solved! Go to Solution.
-
Workflow Notification Mailer in Non-Prod
Hi, Does anyone have any suggestions on the best way to setup notifications in Non-Prod environments so there is not confusion with Production EBS notifications? Thanks in advance!