Need help with method... wrote an addition program... have most of it

Writing an addition program... have most of it below. Need help in getting the program to work.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Ch10program2 extends JFrame implements ActionListener
private static final int FRAME_WIDTH = 750;
private static final int FRAME_HEIGHT = 150;
private static final int BUTTON_HEIGHT = 50;
private static final int BUTTON_WIDTH = 50;
private static final int BUTTON_Y_POSITION = 50;
private static final String EMPTY_STRING = "";
private int XbuttonPosition = 15;
private JButton[] button;
private String[] buttonLabels = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "=", "c"};
private JTextField mytextfield;
private int[] numberOne;
private int[] numberTwo;
private int[] sum;
private int numberCounter = 0;
private boolean adding = false;
public static void main (String[] args)
Ch10program2 frame = new Ch10program2 ();
frame.setVisible (true);
public Ch10program2 ()
Container contentPane = getContentPane ();
// set the frame properties
setSize (FRAME_WIDTH, FRAME_HEIGHT);
setLocation (200, 200);
setTitle ("Big Integer Adder");
setResizable (false);
//set the content pane properties
contentPane.setLayout (null);
//creating each button
button = new JButton [13];
for (int i = 0 ; i < button.length ; i++)
button = new JButton (buttonLabels [i]);
button [i].setBounds (XbuttonPosition, BUTTON_Y_POSITION, BUTTON_WIDTH, BUTTON_HEIGHT);
XbuttonPosition += 55;
button [i].setForeground (Color.blue);
if (i > 9)
button [i].setForeground (Color.red);
contentPane.add (button [i]);
button [i].addActionListener (this);
//set the arrays
numberOne = new int [50];
numberTwo = new int [50];
//set the needed textfield
mytextfield = new JTextField ("");
mytextfield.setBounds (10, 10, 720, 25);
mytextfield.setBorder (BorderFactory.createLoweredBevelBorder ());
mytextfield.setHorizontalAlignment (JTextField.RIGHT);
contentPane.add (mytextfield);
setDefaultCloseOperation (EXIT_ON_CLOSE);
public void actionPerformed (ActionEvent event)
JButton clickedButton = (JButton) event.getSource ();
String oldText = mytextfield.getText ();
if ((event.getActionCommand ()).equals ("+"))
mytextfield.setText (oldText + " + ");
adding = true;
numberCounter = 0;
else if ((event.getActionCommand ()).equals ("="))
mytextfield.setText (oldText + " = ");
addArrays ();
displayArray ();
else if ((event.getActionCommand ()).equals ("c"))
clearText ();
else if (adding == false)
mytextfield.setText (oldText + event.getActionCommand ());
if (numberCounter == 0)
numberOne [numberCounter] = Integer.parseInt (event.getActionCommand ());
else
for (int i = numberOne.length - 1 ; i > 0 ; i--)
numberOne [i] = numberOne [i - 1];
numberOne [0] = Integer.parseInt (event.getActionCommand ());
numberCounter++;
else
mytextfield.setText (oldText + event.getActionCommand ());
if (numberCounter == 0)
numberTwo [numberCounter] = Integer.parseInt (event.getActionCommand ());
else
for (int i = numberTwo.length - 1 ; i > 0 ; i--)
numberTwo [i] = numberTwo [i - 1];
numberTwo [0] = Integer.parseInt (event.getActionCommand ());
numberCounter++;
oldText = mytextfield.getText ();
public void addArrays ()
int temp = 0;
int carriedDigit = 0;
for (int i = 0 ; i < 50 ; i++)
temp = carriedDigit + numberOne [i] + numberTwo [i];
if (temp > 10)
sum [i] = (temp - 10);
carriedDigit = 1;
else
sum [i] = temp;
public void displayArray ()
private void clearText ()
mytextfield.setText (EMPTY_STRING);

I don't know what you want to do
but i have taken your program to get the GUI then the logic is your's
You try solving it.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Ch10program2 extends JFrame implements ActionListener
private static final int FRAME_WIDTH = 750;
private static final int FRAME_HEIGHT = 150;
private static final int BUTTON_HEIGHT = 50;
private static final int BUTTON_WIDTH = 50;
private static final int BUTTON_Y_POSITION = 50;
private static final String EMPTY_STRING = "";
private int XbuttonPosition = 15;
private JButton[] button;
private String[] buttonLabels = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "=", "c"};
private JTextField mytextfield;
private int[] numberOne;
private int[] numberTwo;
private int[] sum;
private int numberCounter = 0;
private boolean adding = false;
public static void main (String[] args)
Ch10program2 frame = new Ch10program2 ();
frame.setVisible (true);
public Ch10program2 ()
Container contentPane = getContentPane ();
// set the frame properties
setSize (FRAME_WIDTH, FRAME_HEIGHT);
setLocation (200, 200);
setTitle ("Big Integer Adder");
setResizable (false);
//set the content pane properties
contentPane.setLayout (null);
//creating each button
button = new JButton [13];
for (int i = 0 ; i < button.length ; i++)
button[i] = new JButton (buttonLabels);
button[i].setBounds (XbuttonPosition, BUTTON_Y_POSITION, BUTTON_WIDTH, BUTTON_HEIGHT);
XbuttonPosition += 55;
button[i].setForeground (Color.blue);
if (i > 9)
button[i].setForeground (Color.red);
contentPane.add (button[i]);
button[i].addActionListener (this);
//set the arrays
numberOne = new int [50];
numberTwo = new int [50];
//set the needed textfield
mytextfield = new JTextField ("");
mytextfield.setBounds (10, 10, 720, 25);
mytextfield.setBorder (BorderFactory.createLoweredBevelBorder ());
mytextfield.setHorizontalAlignment (JTextField.RIGHT);
contentPane.add (mytextfield);
setDefaultCloseOperation (EXIT_ON_CLOSE);
public void actionPerformed (ActionEvent event)
JButton clickedButton = (JButton) event.getSource ();
String oldText = mytextfield.getText ();
if ((event.getActionCommand ()).equals ("+"))
mytextfield.setText (oldText + " + ");
adding = true;
numberCounter = 0;
else if ((event.getActionCommand ()).equals ("="))
mytextfield.setText (oldText + " = ");
addArrays ();
displayArray ();
else if ((event.getActionCommand ()).equals ("c"))
clearText ();
else if (adding == false)
mytextfield.setText (oldText + event.getActionCommand ());
if (numberCounter == 0)
numberOne [numberCounter] = Integer.parseInt (event.getActionCommand ());
else
for (int i = numberOne.length - 1 ; i > 0 ; i--)
numberOne[i] = numberOne [i - 1];
numberOne [0] = Integer.parseInt (event.getActionCommand ());
numberCounter++;
else
mytextfield.setText (oldText + event.getActionCommand ());
if (numberCounter == 0)
numberTwo [numberCounter] = Integer.parseInt (event.getActionCommand ());
else
for (int i = numberTwo.length - 1 ; i > 0 ; i--)
numberTwo[i] = numberTwo [i - 1];
numberTwo [0] = Integer.parseInt (event.getActionCommand ());
numberCounter++;
oldText = mytextfield.getText ();
public void addArrays ()
int temp = 0;
int carriedDigit = 0;
for (int i = 0 ; i < 50 ; i++)
temp = carriedDigit + numberOne[i] + numberTwo[i] ;
if (temp > 10)
sum[i] = (temp - 10);
carriedDigit = 1;
else
sum[i] = temp;
public void displayArray ()
private void clearText ()
mytextfield.setText (EMPTY_STRING);
All The Best

Similar Messages

  • I need help with my text tone and I have ring tone. no text tone for the 4s.

    I need help with my text tone. I have ring tone no text tone. I have a 4s.

        Hi Sarar2333!  Let's get your text tones working again!
    Here's a link with instructions how to enable and change your alert sounds for your text/notification settings on your iPhone 4S: http://vz.to/1stiF8a.  You can ensure text tones are enabled by selecting a tone in the "Text Tone" setting.  Let me know how that works out for you.  Thanks!
    AnthonyTa_VZW
    Follow us on Twitter @VZWSupport

  • Need help with method calling

    I have a problem with method calling as it does the method but doesn't send the values to the main program. The Need section in the main should take in the Max and Allocation arrays from the setMax and setAllocation but it doesn't. I figure I'm missing a return call or something. Could you help me out.
        public class Project4
           public static void main (String[] args)
             int[] Available=new int[4];
             int[][]Max=new int[5][4];
             int[][]Allocation=new int[5][4];
             int[][] Need=new int[5][4];
             setMax();
             setAllocated();
             setAvailable();
           //Creates the need.
             int numMax, numAlloc, numNeed;
             for(int row=0; row<5; row++)
                for (int col=0; col<4; col++)
                   numMax=Max[row][col];
                   numAlloc=Allocation[row][col];
                   numNeed=numMax-numAlloc;
                   Need[row][col]=numNeed;
             for(int row=0; row<Need.length; row++)
                for (int col=0; col<Need[row].length; col++)
                   System.out.print (Need[row][col]);
                System.out.println();
             System.out.println();
            //From here on checks to see if available.     
             int[] processLeft=new int[5];
             int numChecker, numAvail, counter, check, num, stop, processCounter;
             int i=0; 
             num=0;
             stop=3;
             processCounter=0;
             for(int row=num; row<Need.length; row++)
                int col=0;
                counter=Need[row].length; 
                numChecker=Need[row][col];
                numAvail=Available[col];
                do
                   check=0;
                   numChecker= Need[row][col];
                   numAvail=Available[col];
                   col++;
                   if (numChecker<=numAvail)
                      check=1;
                   while(numChecker<=numAvail && col<counter);
                if(col==counter && check==1)
                   System.out.println("Process P"+row+" executes");
                   for(col=0; col<Allocation.length-1; col++)
                      numChecker=Allocation[row][col];
                      numAvail=Available[col];
                      numAvail=numChecker+numAvail;
                      Available[col]=numAvail;
                   num++; 
                   processCounter=processCounter+1;
                else
                   processLeft=row;
    i++;
    // Checks the processes left over
    int j=0;
    int row=0;
    int col=0;
    counter=Need[row].length;
    while(processLeft[j]!=5 && processCounter!=5)
    row=processLeft[j];
    do
    check=0;
    numChecker= Need[row][col];
    numAvail=Available[col];
    col++;
    if (numChecker<=numAvail)
    check=1;
    while(numChecker<=numAvail && col<counter);
    if(col==counter && check==1)
    System.out.println("Process P"+row+" executes");
    for(col=0; col<Allocation.length-1; col++)
    numChecker=Allocation[row][col];
    numAvail=Available[col];
    numAvail=numChecker+numAvail;
    Available[col]=numAvail;
    processCounter=processCounter+1;
    j++;
    safe(processCounter);
    public static void setAllocated()
         // Creates the Allocation
    int[][] Allocation= {{3,0,0,2},{1,0,0,0},{1,3,5,4},{0,6,3,2},{0,0,1,4}};
    for(int row=0; row<Allocation.length; row++)
    for (int col=0; col<Allocation[row].length; col++)
    System.out.print (Allocation[row][col]);
    System.out.println();
    System.out.println();
    public static void setMax()
         // Creates the max
    int[][] Max= {{3,0,1,2},{1,5,5,0},{2,3,5,6},{0,6,5,2},{0,6,5,6}};
    for(int row=0; row<Max.length; row++)
    for (int col=0; col<Max[row].length; col++)
    System.out.print (Max[row][col]);
    System.out.println();
    System.out.println();
    public static void setAvailable()
    // Creates the Available.
    int[] Available={3,5,2,0};
    public static void safe(int processCounter)
         // Prints if it is safe or not     
    if(processCounter!=5)
    System.out.println("\n The system is not safe");     
    else
    System.out.println("\n The system is safe");

    those methods declare and initialize variables that exist only within that specific method, so no other method can see them
    move the 4 arrays you declare in main() out of the method into the class body, then in the other methods, don't declare new arrays, simply initialize the ones you just moved into the class body
    or alternatively, you could make the methods return the arrays they create, and instead of your main method creating arrays, it simply works with whatever those methods return
    btw 20 minutes is a bit early to be getting impatient

  • I need help with Changing my Security Questions, I have forgotten them.

    Its simple, I tried buying a Gym Buddy Application and I had to answer my security questions... Which I have forgotten I made this a while ago so I probably entered something stupid and fast to make I really regert it now. When i'm coming to this...

    Hello Adrian,
    The steps in the articles below will guide you in setting up your rescue email address and resetting your security questions:
    Rescue email address and how to reset Apple ID security questions
    http://support.apple.com/kb/HT5312
    Apple ID: All about Apple ID security questions
    http://support.apple.com/kb/HT5665
    If you continue to have issues, please contact our Account Security Team as outlined in this article for assistance with resetting the security questions:
    Apple ID: Contacting Apple for help with Apple ID account security
    http://support.apple.com/kb/HT5699
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

  • Need HELP with objects and classes problem (program compiles)

    Alright guys, it is a homework problem but I have definitely put in the work. I believe I have everything right except for the toString method in my Line class. The program compiles and runs but I am not getting the right outcome and I am missing parts. I will post my problems after the code. I will post the assignment (sorry, its long) also. If anyone could help I would appreciate it. It is due on Monday so I am strapped for time.
    Assignment:
    -There are two ways to uniquely determine a line represented by the equation y=ax+b, where a is the slope and b is the yIntercept.
    a)two diffrent points
    b)a point and a slope
    !!!write a program that consists of three classes:
    1)Point class: all data MUST be private
    a)MUST contain the following methods:
    a1)public Point(double x, double y)
    a2)public double x ()
    a3public double y ()
    a4)public String toString () : that returns the point in the format "(x,y)"
    2)Line class: all data MUST be private
    b)MUST contain the following methods:
    b1)public Line (Point point1, Point point2)
    b2)public Line (Point point1, double slope)
    b3)public String toString() : that returns the a text description for the line is y=ax+b format
    3)Point2Line class
    c1)reads the coordinates of a point and a slope and displays the line equation
    c2)reads the coordinates of another point (if the same points, prompt the user to change points) and displays the line equation
    ***I will worry about the user input later, right now I am using set coordinates
    What is expected when the program is ran: example
    please input x coordinate of the 1st point: 5
    please input y coordinate of the 1st point: -4
    please input slope: -2
    the equation of the 1st line is: y = -2.0x+6.0
    please input x coordinate of the 2nd point: 5
    please input y coordinate of the 2nd point: -4
    it needs to be a diffrent point from (5.0,-4.0)
    please input x coordinate of the 2nd point: -1
    please input y coordinate of the 2nd point: 2
    the equation of the 2nd line is: y = -1.0x +1.0
    CODE::
    public class Point{
         private double x = 0;
         private double y = 0;
         public Point(){
         public Point(double x, double y){
              this.x = x;
              this.y = y;
         public double getX(){
              return x;
         public double setX(){
              return this.x;
         public double getY(){
              return y;
         public double setY(){
              return this.y;
         public String toString(){
              return "The point is " + this.x + ", " + this.y;
    public class Line
         private double x = 0;
         private double y = 0;
         private double m = 0;
         private double x2 = 0;
         private double y2 = 0;
         public Line()
         public Line (Point point1, Point point2)
              this.x = point1.getX();
              this.y = point1.getY();
              this.x2 = point2.getX();
              this.y2 = point2.getY();
              this.m = slope(point1, point2);
         public Line (Point point1, double slope)
              this.x = point1.getX();
              this.y = point1.getY();
         public double slope(Point point1, Point point2)//finds slope
              double m1 = (point1.getY() - point2.getY())/(point1.getX() - point2.getX());
              return m1;
         public String toString()
              double temp = this.x- this.x2;
              return this.y + " = " +temp + "" + "(" + this.m + ")" + " " + "+ " + this.y2;
              //y-y1=m(x-x1)
    public class Point2Line
         public static void main(String[]args)
              Point p = new Point(3, -3);
              Point x = new Point(10, 7);
              Line l = new Line(p, x);
              System.out.println(l.toString());
    }My problems:
    I dont have the right outcome due to I don't know how to set up the toString in the Line class.
    I don't know where to put if statements for if the points are the same and you need to prompt the user to put in a different 2nd point
    I don't know where to put in if statements for the special cases such as if the line the user puts in is a horizontal or vertical line (such as x=4.7 or y=3.4)
    Edited by: ta.barber on Apr 20, 2008 9:44 AM
    Edited by: ta.barber on Apr 20, 2008 9:46 AM
    Edited by: ta.barber on Apr 20, 2008 10:04 AM

    Sorry guys, I was just trying to be thorough with the assignment. Its not that if the number is valid, its that you cannot put in the same coordinated twice.
    public class Line
         private double x = 0;
         private double y = 0;
         private double m = 0;
         private double x2 = 0;
         private double y2 = 0;
         public Line()
         public Line (Point point1, Point point2)
              this.x = point1.getX();
              this.y = point1.getY();
              this.x2 = point2.getX();
              this.y2 = point2.getY();
              this.m = slope(point1, point2);
         public Line (Point point1, double slope)
              this.x = point1.getX();
              this.y = point1.getY();
         public double slope(Point point1, Point point2)//finds slope
              double m1 = (point1.getY() - point2.getY())/(point1.getX() - point2.getX());
              return m1;
         public String toString()
              double temp = this.x- this.x2;
              return this.y + " = " +temp + "" + "(" + this.m + ")" + " " + "+ " + this.y2;
              //y-y1=m(x-x1)
    public class Point2Line
         public static void main(String[]args)
              Point p = new Point(3, -3);
              Point x = new Point(10, 7);
              Line l = new Line(p, x);
              System.out.println(l.toString());
    }The problem is in these lines of code.
    public double slope(Point point1, Point point2) //if this method finds the slope than how would i use the the two coordinates plus "m1" to
              double m1 = (point1.getY() - point2.getY())/(point1.getX() - point2.getX());
              return m1;
         public String toString()
              double temp = this.x- this.x2;
              return this.y + " = " +temp + "" + "(" + this.m + ")" + " " + "+ " + this.y2;
              //y-y1=m(x-x1)
         }if slope method finds the slope than how would i use the the two coordinates + "m1" to create a the line in toString?

  • Need help with search function in my program

    Hello all, some of you may remeber me from my previous inventory programs. Well I am finally on my last one and I need to add a search option to the code. Here is the class that will contain that option.
    import java.util.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class Inventory2 extends JFrame implements ActionListener {
    //Utility class for displaying the picture
    //If we are going to use a class/method/variable inside that class only, we declare it private in that class
    private class MyPanel extends JPanel {
    ImageIcon image = new ImageIcon("Sample.jpg");
    int width = image.getIconWidth();
    int height = image.getIconHeight();
    long angle = 30;
    public MyPanel(){
    super();
    public void paintComponent(Graphics g){
         super.paintComponent(g);
         Graphics2D g2d = (Graphics2D)g;
         g2d.rotate (Math.toRadians(angle), 60+width/2, 60+height/2);
         g2d.drawImage(image.getImage(), 60, 60, this);
         g2d.dispose();
    }//end class MyPanel
    int currentIndex; //Currently displayed Item
    Product[] supplies = new Product[4];
    JLabel name ;
    JLabel number;
    JLabel rating;
    JLabel quantity;
    JLabel price;
    JLabel fee;
    JLabel totalValue;
    JTextField nameField = new JTextField(20);
    JTextField numberField = new JTextField(20);
    JTextField ratingField = new JTextField(20);
    JTextField quantityField = new JTextField(20);
    JTextField priceField = new JTextField(20);
    JPanel display;
    JPanel displayHolder;
    JPanel panel;
    boolean locked = false; //Notice how I've used this flag to keep the interface clean
    public Inventory2() {
    makeTheDataItems();
    setSize(700, 500);
    setTitle("Inventory Program");
    //make the panels
    display = new JPanel();
    JPanel other = new JPanel();
    other.setLayout(new GridLayout(2, 1));
    JPanel picture = new MyPanel();
    JPanel buttons = new JPanel();
    JPanel centerPanel = new JPanel();
    displayHolder = new JPanel();
    display.setLayout(new GridLayout(7, 1));
    //other.setLayout(new GridLayout(1, 1));
    //make the labels
    name = new     JLabel("Name :");
    number = new JLabel("Number :");
    rating = new JLabel("Rating     :");
    quantity = new JLabel("Quantity :");
    price = new JLabel("Price     :");
    fee = new JLabel("Restocking Fee (5%) :");
    totalValue = new JLabel("Total Value :");
    //Use the utility method to make the buttons
    JButton first = makeButton("First");
    JButton next = makeButton("Next");
    JButton previous = makeButton("Previous");
    JButton last = makeButton("Last");
    JButton search = makeButton("Search");
    //Other buttons
    JButton add = makeButton("Add");
    JButton modify = makeButton("Modify");
    JButton delete = makeButton("Delete");
    JButton save = makeButton("Save");
    JButton exit = makeButton("Exit");
    //Add the labels to the display panel
    display.add(name);
    display.add(number);
    display.add(rating);
    display.add(quantity);
    display.add(price);
    display.add(fee);
    //add the buttons to the buttonPanel
    buttons.add(first);
    buttons.add(previous);
    buttons.add(next);
    buttons.add(last);
    buttons.add(search);
    //Add the picture panel and display to the centerPanel
    displayHolder.add(display);
    centerPanel.setLayout(new GridLayout(2, 1));
    centerPanel.add(picture);
    centerPanel.add(displayHolder);
    other.add(buttons);
    JPanel forAdd = new JPanel(); // add the other buttons to this panel
    forAdd.add(add);
    forAdd.add(modify);
    forAdd.add(delete);
    forAdd.add(save);
    forAdd.add(exit);
    other.add(forAdd);
    //Add the panels to the frame
    getContentPane().add(centerPanel, "Center");
    getContentPane().add(other, "South");
    this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    setVisible(true);
    private void makeTheDataItems () {
    Product p1 = new DVD("The one", 001, 200, 100, "The one");
    Product p2 = new DVD("Once upon a time in China V", 002, 500, 10000, "Once upon a time in China V");
    Product p3 = new DVD("Rat Race", 003, 100, 3000, "Rat Race");
    Product p4 = new DVD("The Man in the Iron Mask", 004, 3000, 9000, "The Man in the Iron Mask");
    supplies[0] = p1;
    supplies[1] = p2;
    supplies[2] = p3;
    supplies[3] = p4;
    //Utility method for creating and dressing buttons
    private JButton makeButton(String label) {
    JButton button = new JButton(label);
    button.setPreferredSize(new Dimension(100, 25));
    button.setActionCommand(label);
    button.addActionListener(this);
    return button;
    private void addItem() {
    panel = new JPanel();
    JPanel add = new JPanel();
    add.setLayout(new GridLayout(7, 2));
    JButton addIt = makeButton("Add Item");
    JLabel name = new JLabel("Name :");
    JLabel rating = new JLabel("Rating     :");
    JLabel quantity = new JLabel("Quantity :");
    JLabel price = new JLabel("Price     :");
    add.add(name); add.add(nameField);
    add.add(rating); add.add(ratingField);
    add.add(quantity); add.add(quantityField);
    add.add(price); add.add(priceField);
    panel.add(add);
    JPanel forAddIt = new JPanel();
    forAddIt.add(addIt);
    panel.add(forAddIt);
    displayHolder.remove(display);
    displayHolder.add(panel);
    //display = panel;
    this.setVisible(true);
    public static void main( String args[]) {
    new Inventory2().displayFirst(); //The main method should not have too much code
    } // end main method
    public void actionPerformed(ActionEvent event) {
      String command = event.getActionCommand(); //This retrieves the command that we set for the button
      //Always compare strings using the .equals method and not using ==
      if(command.equals("First")) {
       if(!locked) {
         displayFirst();
      else if(command.equals("Next")) {
       if(!locked) {
         displayNext();
      else if(command.equals("Previous")) {
       if(!locked) {
         displayPrevious();
      else if(command.equals("Last")) {
       if(!locked) {
         displayLast();
      else if(command.equals("Exit")) {
       this.dispose();
       System.exit(0);
      else if(command.equals("Add")) {
       if(!locked) {
         addItem();
         locked = true;
      else if(command.equals("Add Item")) {
       addItemToArray();
      else if(command.equals("Modify")) {
       if(!locked) {
         modify();
         locked = true;
      else if(command.equals("Update")) {
          if(!locked) {
         modifyItemInArray();
         locked = true;
      else if(command.equals("Delete")) {
       if(!locked) {
         DVD dvd = (DVD)supplies[currentIndex];
            int confirm = JOptionPane.showConfirmDialog(this, "Are you sure you want to delete item "+dvd.getItemNumber());
                if(confirm == JOptionPane.YES_OPTION) {
          removeItemAt(currentIndex);
          displayFirst();
    private void modify() {
    DVD dvd = (DVD)supplies[currentIndex];
    panel = new JPanel();
    JPanel add = new JPanel();
    add.setLayout(new GridLayout(7, 2));
    JButton update = makeButton("Update");
    JLabel number = new JLabel("Number :");
    JLabel name = new JLabel("Name :");
    JLabel rating = new JLabel("Rating     :");
    JLabel quantity = new JLabel("Quantity :");
    JLabel price = new JLabel("Price     :");
    add.add(number);
    numberField.setText(""+dvd.getItemNumber()); numberField.setEditable(false); add.add(numberField);
    add.add(name);
    nameField.setText(dvd.getItemName()); add.add(nameField);
    ratingField.setText(dvd.getRating()); ratingField.setEditable(false);
    add.add(rating); add.add(ratingField);
    add.add(quantity);
    quantityField.setText(""+dvd.getStockQuantity());
    add.add(quantityField);
    add.add(price);
    add.add(priceField); priceField.setText(""+dvd.getItemPrice());
    panel.add(add);
    JPanel forAddIt = new JPanel();
    forAddIt.add(update);
    panel.add(forAddIt);
    displayHolder.remove(display);
    displayHolder.add(panel);
    //display = panel;
          this.setVisible(true);
    private void addItemToArray() {
    Product p = new DVD(nameField.getText(), supplies.length + 1, Long.parseLong(quantityField.getText()),
    Double.parseDouble(priceField.getText()), ratingField.getText());
    //Extend size of array by one first
    Product[] ps = new Product[supplies.length + 1];
    for(int i = 0; i < ps.length-1; i++) {
    ps[i] = supplies;
    ps[supplies.length] = p;
    supplies = ps;
    displayHolder.remove(panel);
    displayHolder.add(display);
    displayLast();
    this.setVisible(false);
    this.setVisible(true);
    //Utility method to ease the typing and reuse code
    //This method reduces the number of lines of our code
    private void displayItemAt(int index) {
    DVD product = (DVD)supplies[index];
    name.setText("Item Name: "+ product.getItemName());
    number.setText("Item Number: "+ product.getItemNumber());
    rating.setText("Rating: "+ product.getRating());
    quantity.setText("Quantity In Stock: "+ product.getStockQuantity());
    price.setText("Item Price: "+ product.getItemPrice());
    totalValue.setText("Total: " + product.calculateInventoryValue());
    fee.setText("Restocking Fee (5%) :"+product.calculateRestockFee());
    locked = false;
    this.repaint();
    this.setVisible(true);
    private void modifyItemInArray() {
    Product p = new DVD(nameField.getText(), supplies.length + 1, Long.parseLong(quantityField.getText()),
    Double.parseDouble(priceField.getText()), ratingField.getText());
    supplies[currentIndex] = p;
    displayHolder.remove(panel);
    displayHolder.add(display);
         displayItemAt(currentIndex);
    this.setVisible(false);
    this.setVisible(true);
    private void removeItemAt(int index) {
    Product[] temp = new Product[supplies.length-1];
    int counter = 0;
    for(int i = 0; i < supplies.length;i++) {
    if(i == index) { //skip the item to delete
    else {
         temp[counter++] = supplies[i];
    supplies = temp;
    public void displayFirst() {
    displayItemAt(0);
    currentIndex = 0;
    public void displayNext() {
    if(currentIndex == supplies.length-1) {
    displayFirst();
    currentIndex = 0;
    else {
    displayItemAt(currentIndex + 1);
    currentIndex++;
    public void displayPrevious() {
    if(currentIndex == 0) {
    displayLast();
    currentIndex = supplies.length-1;
    else {
    displayItemAt(currentIndex - 1);
    currentIndex--;
    public void displayLast() {
    displayItemAt(supplies.length-1);
    currentIndex = supplies.length-1;
    }//end class Inventory2
    I am not sure where to put it and how to set it up. If you guys need the other two classes let me know. Thanks in advanced.

    Here are the other two classes:
    import java.util.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    class Product implements Comparable {
    String name;
    int number;
    long stockQuantity;
    double price;
    public Product() {
      name = "";
          number = 0;
          stockQuantity = 0L;
          price = 0.0;
    public Product(String name, int number, long stockQuantity, double price) {
      this.name = name;
          this.number = number;
          this.stockQuantity = stockQuantity;
          this.price = price;
         public void setItemName(String name) {
      this.name = name;
    public String getItemName() {
      return name;
    public void setItemNumber(int number) {
      this.number = number;
    public int getItemNumber() {
      return number;
    public void setStockQuantity(long quantity) {
      stockQuantity = quantity;
    public long getStockQuantity() {
      return stockQuantity;
    public void setItemPrice(double price) {
      this.price = price;
    public double getItemPrice() {
      return price;
    public double calculateInventoryValue() {
      return getItemPrice() * getStockQuantity();
    public int compareTo (Object o) {
      Product p = (Product)o;
      return name.compareTo(p.getItemName());
    public String toString() {
      return "Name :"+getItemName() + "\nNumber"+number+"\nPrice"+price+"\nQuantity"+stockQuantity + "\nValue :"+calculateInventoryValue();
    class DVD extends Product implements Comparable {
    private String rating;
    public DVD() {
      super(); //Call the constructor in Product
      rating = ""; //Add the additonal attribute
    public DVD(String name, int number, long stockQuantity, double price, String rating) {
      super(name, number, stockQuantity, price); //Call the constructor in Product
      this.rating = rating; //Add the additonal attribute
         public void setRating(String rating) {
      this.rating = rating;
    public String getRating() {
      return rating;
    public double calculateInventoryValue() {
      return getItemPrice() * getStockQuantity() + getItemPrice()*getStockQuantity()*0.05;
    public double calculateRestockFee() {
      return getItemPrice() * 0.05;
    public int compareTo (Object o) {
      Product p = (Product)o;
      return getItemName().compareTo(p.getItemName());
    public String toString() {
      return "Name :"+getItemName() + "\nNumber"+getItemNumber()+"\nPrice"+getItemPrice()+"\nQuantity"+getStockQuantity() +"\nRating :"+getRating()+"\nValue"+calculateInventoryValue();
    }You should be able to search through these items, and any other items that have been added to the program.

  • Need help with algorithm for my paint program

    I was making a paint program with using a BufferedImage where the user draws to the BufferedImage and then I draw the BufferedImage onto the class I am extending JPanel with. I want the user to be able to use an undo feature via ctrl+z and I also want them to be able to update what kind of paper they're writing on live: a) blank paper b) graph paper c) lined paper. I cannot see how to do this by using BufferedImages. Is there something I'm missing or must I do it another way? I am trying to avoid the other way because it seems too demanding on the computer but if this is not do-able then I guess I must but I feel I should ask you guys if what I am doing is logical or monstrous.
    What I am planning to do is make a LinkedList that has the following 4 parameters:
    1) previous Point
    2) current Point
    3) current Color
    4) boolean connectPrevious
    which means that the program would basically draw the instantaneous line using the two points and color specified in paintComponent(Graphics g). The boolean value is for ctrl+z (undo) purposes. I am also planning to use a background thread to eliminate repeated entries in the LinkedList except for the last 25 components of the LinkedList (that number might change in practice).
    What do you guys think?
    Any input would be greatly appreciated!
    Thanks in advance!

    Look at the package javax.swing.undo package - UndoableEdit interface and UndoManager class.
    Just implement the interface. Store all necessary data to perform your action (colors, pixels, shapes etc.). Add all your UndoableEdits in an UndoManager instance and call undo() redo() when you need.

  • Please I need help with methods!

    Could anyone please help me with this problem?
    I know that objects are passed to methods by reference, including arrays also. Then I'm writing methods where I assign other values to argument objects.
    However, when I call these methods from main() with null arguments, they still remain null (verified 100% in debugging)! How could this happen? Is it probably because I'm assigning the object values inside try blocks in the methods?

    Could anyone please help me with this problem?
    I know that objects are passed to methods by
    reference, including arrays also. Then I'm
    writing methods where I assign other values to
    argument objects.
    sigh
    Objects are not passed by reference.
    Object references are passed by value into methods.
    Arrays are objects, so they're passed like all other objects.
    Then I'm
    writing methods where I assign other values to
    argument objects.Since the reference is passed by value, you can't change it. You can change the state of the object that it points to, however, as long as it's not final or immutable.
    However, when I call these methods from main() with
    null arguments, they still remain null
    (verified 100% in debugging)! How could this happen?
    Is it probably because I'm assigning the object
    values inside try blocks in the methods?Remember, of course, that declaring an array of objects means that all the references it points to are null. You have to set each one individually.
    Better go back and re-read some fundamental stuff.
    %

  • Need help with dbwizard in loading additional items on forms

    I used database dbblock wizard to create a form called employee. I took four fields from employee table and put them on my form.
    My questin is If i want to add more items in my form from the same employee table, how can i do it.
    These items should reside on same block as the other items.
    plss help

    Hi rahman,
    Greetings,
    Simple, just add text item, with the help of layout editor, in the same block as per your requirement and then click and check the property of newly add item to fix database => yes , column => as per your table column name / change the textitem Name as per you table column name.
    Then it will work fine.
    kanish

  • Need help with method development

    I want to stop the takeInput method when the user enters -1. But the way it is currently written, it just continues to repeat, and I can't figure out why. What needs to be changed?
    import java.util.*;
    public class Appt
         public static Scanner kb = new Scanner(System.in).useDelimiter("\n");
         public static String start,end,event;
         public static void main(String args[])
              while(takeInput() == true)
              takeInput();
         public static void enterAppt(String start, String end, String event)
         public static boolean takeInput()
              String stopVar = "-1";
              System.out.println("To finish entering appointments, type -1");
              System.out.println("Enter a start time:");
              start = kb.next();
              if(start == stopVar) return false;
              System.out.println("Enter an end time:");
              end = kb.next();
              if(end == stopVar) return false;
              System.out.println("Enter an event:");
              event = kb.next();
              if(event == stopVar) return false;
              return true;
    }Edited by: Jago6060 on Apr 20, 2008 11:46 PM

    Use equals, not == to compare objects' states, including Strings' contents.
    Also, you're getting user input twice for every pass through the loop. Also, you don't need "== true". Also, why is takeInput public?
    while(takeInput() == true) // once
              takeInput(); // twice
              }You could just do
    while (takeInput());However, that's not the normal way to do it. Rather, takeInput would be something like
    private static void takeInput() {
      boolean done = false;
      while (!done) {
        get the input
        if it's -1, done = true;
    }Also, if you go through the loop 5 times, you'll still only have one appointment. You'll just change it 5 times. If you want to create appointments, you need to make start, end, and event non-static, and create a new Appt object each time through the loop.
    [http://java.sun.com/docs/books/tutorial/java/concepts/index.html]
    [http://java.sun.com/docs/books/tutorial/java/javaOO/index.html]

  • Need help with updates and new apple programs

    something happened to my pc. having problems with my pc when it restarts.
    wondered if anyone whichapple updates require a restart, and which don't?
    if they require a restart to finish installation, they fail, and my pc crashes, and i have to resintall os.
    i know the iwork does not require a restart, where ilife does. so for now, i can install iwork, but not ilife.
    in anyone familiar with 10.5.6 knows which updates/add ond require a restart and which don't, please post. any help appreciated. 4th re install now.

    Hey network --
    Sorry to hear of your problems . . .
    What Mac are you running there?
    Did the installation of 10.5.6 finally go well?
    You're having problems with iLife, but what about Snow Leopard?

  • Need help with signing up for dev program - questions

    Greetings,
    I am planning on signing up for the dev program and I will be making a game to upload into the apple store. When I try sign up for the dev program/apple id, my country is not in the available list of countries. I am currently living in Mongolia and there is no itunes store available here. Would I be able to sign up for the dev program and develop/upload/sell?

    I am able to use the singapore store as I made this account using singapore as my region. If I do that with my dev account, will I not run into problems with billing/confirmation issues?

  • Need help with total in my mortgage program

    I have been work on this program and I can't seem to correct how the amount is shown. It gives several numbers after the decimal. Can anyone please help.
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    /* Diana Saddler
    * PRG-421  Java Programming II
    public class mortgage extends JFrame implements ActionListener {
    private JPanel panelAdder;
    private JLabel labela;
    private JLabel labelt;
    private JLabel labelr;
    private JTextField textFieldAmount;
    private JTextField textFieldTerm;
    private JTextField textFieldRate;
    private JTextField textFieldResult;
    private JButton buttonCalc;
    public mortgage() {
      initComponents();
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setVisible(true);
      pack();
      // Add Listeners
      buttonCalc.addActionListener(this);
    public void initComponents() {
    //Initialize Components
    panelAdder = new JPanel();
    labela = new JLabel("Amount");
    textFieldAmount = new JTextField();
    labelt = new JLabel("Term");
    textFieldTerm = new JTextField();
    labelr = new JLabel("Rate");
    textFieldRate = new JTextField();
    textFieldResult = new JTextField();
    buttonCalc = new JButton("Calculate");
    //Set Object Attributes
    textFieldResult.setEditable(false);
    textFieldResult.setColumns(8);
    textFieldAmount.setColumns(6);
    textFieldTerm.setColumns(3);
    textFieldRate.setColumns(3);
    Container contentPane = getContentPane();
    contentPane.setLayout(new FlowLayout());
    //Add the components to the panel
    panelAdder.add(labela);
    panelAdder.add(textFieldAmount);
    panelAdder.add(labelt);
    panelAdder.add(textFieldTerm);
    panelAdder.add(labelr);
    panelAdder.add(textFieldRate);
    panelAdder.add(buttonCalc);
    panelAdder.add(textFieldResult);
    contentPane.add(panelAdder);
        public static void main(String[] args) {
             mortgage frame = new mortgage();
    //calculate
        private void setResultValue() {
       double amount = Double.parseDouble(textFieldAmount.getText());
       double term = Integer.parseInt(textFieldTerm.getText());
       double rate = Double.parseDouble(textFieldRate.getText()) / 100.;
       double result = amount * ( rate * Math.pow ( ( 1 + rate ), term ) ) / ( Math.pow( ( 1 + rate ), term ) - 1 );
       textFieldResult.setText(Double.toString(result));
    public void actionPerformed(ActionEvent event) {
      System.out.println("Action Button");
      String command = event.getActionCommand();
      if ("Calculate".equals(command))
          setResultValue();
    }

    DecimalFormat

  • Need help with SMS message telling me I have a voice mail, need to get rid of that

    I have done a few searches on the internet and have found nothing that fixes my problem.
    I use two message boxes/folders, one is for phone calls and the other is for SMS/MMS messages.  I need to keep these this way (I am not searching though 100 text messages to find a phone number that is critical).
    The problem occurred after I downloaded a new update (Jan 11th, 2010; think is like version 4.6 or something).  Before, if I got a call it showed up in my call message box/folder and if they left a voice mail I have a special ring tone for voice mail messages.   I also had it when I got a SMS/MMS message it went to its own "mailbox/folder" and had its own ring tone when a new one was sent.  Now when I get a voice mail message due to the fact I also get a SMS/MMS message I only hear a text message ring tone (not good).
    I need to know the instant I get a voice mail, the text messages are a nice thing to have for my significant other and friends.  If I walk out of a location that I did not have reception and I get a voice mail, I now think its a text message and get to it when I can even though I needed it then.
    Example: just think of leaving a building with your hands full heading to point B, when the voice mail told you a correction and divert to point C;
    voice mail = hold everything and get the message all good
    text message = head to point B, see a problem and pray you get to point C before anything bad happens).
    I went to my local Sprint/Nextel store and they told me there was nothing I could do.
    If this can't be fixed I will be forced to get another cell, then everyone including me will sufer because we will have to pay for it (just think taxes).
    I feel exahusted in looking for a solution, if there is not one then blackberry needs to do an update.
    Provided its a software problem that needs an update or maybe I am not to bright to find where to turn this off.
    My questions about this would be:
    1.  How does the phone get a text message, does it generate it from my phone number or the phone number where my voice mail is sent
    2.  Once I know which number it is being sent from, can I put a text block on it
    3.  Last but not least, will it solve the problem?
    Thanks
    Incase it does not show up I have a Blackberry Curve 8350i from Nextel OS V4.6.313

    This is a peer-to-peer community.
    All people responding are user just like you.
    However, many of are users have solved many problems for other blackberry users in need of assistance.
    If you see you haven't been responded to in a long time, just reply 'bump' on the same thread you originally posted.
    The term 'bump' is used because a thread remaining unanswered usually moes down the list and gets lost in older pages. By replying to a post, it gets moved ("bumped") back to the top of the first page of that category.
    If you see a solution to your problem, feel free to mark it as a solution. Also you can thank the user who helped you or give him a 'kudo'. A 'kudo' is the little star found underneath the avatar (picture) of the user. It's like giving them credit for the work they did.
    Welcome to the community! We hope to see you posting soon.
    Sincerely,
    jakoby4204
    Jakoby4204                                                                                                 New to the Community click here  
    Community Moderator

  • Need help with my Zen Touch. I have no clue what's wro

    I downloaded some firmware a few weeks ago, and ever since then my Zen Touch hasn't been working properly. My current is version .0.03. As soon as I downloaded that my computer would not detect the player. When I plugged it in the USB I got three quick low pitched beeps, and then nothing. Since the player isn't connectng to my computer of course I can't transfer any music. I've tried to get it to connect a million times but it's always the same. I evn tried it on another computer so I'm guessing something's wrong with the player itself.
    Can anyone hel me please?Message Edited by Shart780 on 02-4-2006 08:09 AM

    because they are needed to detect your player, that is!
    just try it out, you'll do no harm by doing so

Maybe you are looking for

  • I have 16gb of RAM, but only 10gb are usable?

    Hello everyone,      I have a Mid 2012 15" Macbook Pro running Yosemite. When I first got it, I upgraded to 16gb of 1600 MHz DDR3 RAM because I would be needing it for a lot of the programs I run. I have the 2.3 GHz i7 processor. Stock 500gb hard dri

  • Merging / sharing across accounts

    I have an iTunes Account from which i have bourght lots of music and games for my iPhone my girlfriend also has her own iTunes account for her iPhone, and lots of music and games on her account. when mooving together. is there anyway to merge this da

  • Special Characters on the keyboard

    Is there a way to assign special characters to particular key sequence? When one needs to write in different languages switching keyboards becomes impractical. There must be a way to assign, say: ą, to a combination of keys such that US keyboard can

  • Submit Statment inside Loop - Problem in display O/P

    Hi All,           Iam Using Submit statment inside the Loop with Return , when the first line in the loop completes the O/P gets display and the Second line is not processed and get in O/P.Can any one let me know why this problem occurs?... Regards,

  • Bc4j.xcfg

    If anyone can help with this it would be great oracle.jbo.JboException: JBO-33001: Cannot find the configuration file /portaluniverse/eres/model/bo/diagrams/common/bc4j.xcfg in the classpath      at oracle.jbo.client.Configuration.loadFromClassPath(C