Welcome to Dream.In.Code
Become a Java Expert!

Join 150,038 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,589 people online right now. Registration is fast and FREE... Join Now!




getting my GUI to Loop

2 Pages V  1 2 >  
Reply to this topicStart new topic

getting my GUI to Loop

smithgang1994
13 Jun, 2008 - 05:39 PM
Post #1

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
I have my if loop but It isn't working..which means I messed up again tongue.gif
Can someone help me Please!!!
CODE

import javax.swing.JOptionPane;
import java.awt.FlowLayout; // specifies how components are arranged
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame; // provides basic window features
import javax.swing.JLabel; // displays text and images
import javax.swing.SwingConstants;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JPanel;
import javax.swing.Box;



public class GUI extends JFrame
{

private JLabel label2; // JLabel Item number
private JLabel label3; // JLabel Title of Movie
private JLabel label4; // JLabel Movie Rating
private JLabel label5; // JLabel Stock Number
private JLabel label6; // JLabel Number of Item in Stock
private JLabel label7; // JLabel Restocking Fee
private JLabel label8; // JLabel Purchase Price
private JLabel label9; // JLabel Inventory Value
private JLabel label10; // JLabel Total Inventory Value
private JTextField jtfItem;
private JTextField jtfVideo; //1
private JTextField jtfRating; //2
private JTextField jtfitmNumber; //3
private JTextField jtfStock;//4
private JTextField jtfReStock; //5   getrestock()
private JTextField jtfPrice; //6
private JTextField jtfValue;   //7   getresult()
private JTextField jtftotalInv;//8
private JLabel label11; //JLabel icon
private JButton btnFirst;
private JButton btnPrevious;
private JButton btnNext;
private JButton btnLast;

DVD[] dvd;
int index = 0;

// LabelFrame constructor adds JLabels to JFrame
public GUI()
{
super( "Inventory of DVD Movies" );
// JLabel constructor with a string argument
  //this.inventory1 = inventory1;


    JLabel jl;
    JPanel jp;

setLayout( new FlowLayout() ); // set frame layout




label2 = new JLabel("Item#: " );
label2.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfItem = new JTextField (30);
jtfItem.setEditable(false);
add( label2 ); // add label2 to JFrame
add(jtfItem);

label3 = new JLabel( "Title of Movie: ");
label3.setHorizontalTextPosition( SwingConstants.RIGHT );
label2.setVerticalTextPosition( SwingConstants.CENTER );
jtfVideo = new JTextField (30);
jtfVideo.setEditable(false);
add( label3 ); // add label2 to JFrame
add(jtfVideo);


label4 = new JLabel("Movie Rating:");
label4.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfRating = new JTextField (30);
jtfRating.setEditable(false);
add( label4 ); // add label2 to JFrame
add(jtfRating);

label5 = new JLabel("Item Number:");
label5.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfitmNumber = new JTextField (30);
jtfitmNumber.setEditable(false);
add( label5 ); // add label2 to JFrame
add(jtfitmNumber);

label6 = new JLabel( "# of Items in Stock:");
label6.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfStock = new JTextField (30);
jtfStock.setEditable(false);
add( label6 ); // add label2 to JFrame
add(jtfStock);

label7 = new JLabel( "Restocking Fee:" );
label7.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfReStock = new JTextField (30);
jtfReStock.setEditable(false);
add( label7 ); // add label2 to JFrame
add(jtfReStock);

label8 = new JLabel( "Purchase Price:");
label8.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfPrice = new JTextField (30);
jtfPrice.setEditable(false);
add( label8 ); // add label2 to JFrame
add(jtfPrice);

label9 = new JLabel( "Inventory Value:");
label9.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfValue = new JTextField (30);
jtfValue.setEditable(false);
add( label9 ); // add label2 to JFrame
add(jtfValue);

label10 = new JLabel( "Total Inventory Value:\n");
label10.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtftotalInv = new JTextField (30);
jtftotalInv.setEditable(false);
add( label10 ); // add label2 to JFrame
add(jtftotalInv);

Icon dvd = new ImageIcon(getClass().getResource( "dvd.jpg" ));
label11 = new JLabel ( dvd, SwingConstants.LEFT);
label11.setVerticalTextPosition( SwingConstants.TOP);
add( label11 );

btnFirst = new JButton( "First" );
add( btnFirst );


btnPrevious = new JButton( "Previous" );
add( btnPrevious );

btnNext = new JButton( "Next" );
add( btnNext );

btnLast = new JButton( "Last" );
add( btnLast );





setSize(800,500);
     setVisible(true);



} // end LabelFrame constructor

void setDVD(DVD[] dvd)
{
    this.dvd = dvd;
    index = 0;
    display();
}
void display() {
    jtfItem.setText("" + dvd[index].getItems());
        jtfVideo.setText("" + dvd[index].getVideo());
               jtfRating.setText("" + dvd[index].getRating());
               jtfitmNumber.setText("" + dvd[index].getNumber());
               jtfStock.setText("" + dvd[index].getStock());
               jtfReStock.setText("" + dvd[index].getRestockingFee());
               jtfPrice.setText("" + dvd[index].getPrice());
               jtfValue.setText("" + dvd[index].getValue());
               jtftotalInv.setText("" );

}
   // to display next movie
   void displayNext() {
         index++;
         if(index <= dvd.length)   // wrap around
           index = 0;
         display();
       }
       // display previous
       void displayPrevious() {
           index--;
           if(index > 0)                    // wrap around
             index = dvd.length - 1;
           display();
}
} // end class GUI


CODE

import java.lang.String;
import java.text.DecimalFormat;
import java.awt.FlowLayout; // specifies how components are arranged
import javax.swing.JFrame; // provides basic window features
import javax.swing.JLabel; // displays text and images
import javax.swing.JTextField;


public class Inventory1Test
{
static DecimalFormat formatter = new DecimalFormat("$##,###.00");



    public static void main( String args[] )
    {

        DVD[] library = new DVD[4];

        library[0] = new DVD( "1", "Star Wars", "PG", 232, 5, 13.45);
        library[1] = new DVD("2", "Cars", "G", 233, 7, 12.23 );
        library[2] = new DVD("3", "Fantastic Four", "PG", 234, 8, 18.45);
        library[3] = new DVD("4", "Batman", "PG-13", 235, 2, 10.88);

GUI gui = new GUI();
gui.setDVD(library);





Double totalInv = library[0].CalculateTotalInventoryValue(library);


//Double restockingFee = library[index].getRestockingFee();

//System.out.printf( "Restocking Fee(5%): \t%s\n\n", library[index].getRestockingFee());







}//end main



}//end class Inventory1Test

User is offlineProfile CardPM
+Quote Post

pbl
RE: Getting My GUI To Loop
13 Jun, 2008 - 07:01 PM
Post #2

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
I have searched for "for" and for "while"
haven't found any loop in your code
so to which loop are you refrerring to ?
you also only have to "if" statements that seems OK (actually I wrote them biggrin.gif )

So of which if/loop do you talk about
User is online!Profile CardPM
+Quote Post

smithgang1994
RE: Getting My GUI To Loop
13 Jun, 2008 - 07:22 PM
Post #3

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
See you are know far and wide biggrin.gif I am not sure what I am missing I can get my program to compile and run but I can't get my buttons to work. I am not very good at looping so I am not actually sure what I am missing. I am not asking for you to do my work for me, just help steer me in the right direction. between you and a couple of others I have learned more about java than from my own instructor.

QUOTE(pbl @ 13 Jun, 2008 - 08:01 PM) *

I have searched for "for" and for "while"
haven't found any loop in your code
so to which loop are you refrerring to ?
you also only have to "if" statements that seems OK (actually I wrote them biggrin.gif )

So of which if/loop do you talk about


User is offlineProfile CardPM
+Quote Post

pbl
RE: Getting My GUI To Loop
13 Jun, 2008 - 07:41 PM
Post #4

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
Ok that is a complete new issue....

To have your buttons to work they must have an ActionListener
so your class GUI needs to "implement" Action listener

CODE

class GUI extends JFrame implements ActionListener


now you have to add the actionListner to your buttons... as GUI implements ActionListener you use "this" tho say that this is that class

CODE

btnFirst = new JButton( "First" );
btnFirst.addActionListener(this);
add( btnFirst );

btnPrevious = new JButton( "Previous" );
btnPrevoius.addActionListener(this);
add( btnPrevious );

btnNext = new JButton( "Next" );
btnNext.addActionListener(this);
add( btnNext);


Now as GUI implements ActionListener it should implements the method actionPerformed

CODE

public void actionPerformed(ActionEvent e) {
   // detremine which object fires that actionPerformed
   Object buttonPressed = e.getSource();
   if(buttonPressed == buttonFirst) {
      index = 0;
      display();
      return;
   }
   if(buttonPressed == buttonNext) {
      displayNext();
      return;
   }
   // not first not next so must be previous
   displayPrevious();
}



User is online!Profile CardPM
+Quote Post

smithgang1994
RE: Getting My GUI To Loop
14 Jun, 2008 - 05:19 AM
Post #5

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
Thank you!!! I read the book and tried to put in an Action listener but couldnt figure out where it went!! I havent tried it yet but thanks for the help!


QUOTE(pbl @ 13 Jun, 2008 - 08:41 PM) *

Ok that is a complete new issue....

To have your buttons to work they must have an ActionListener
so your class GUI needs to "implement" Action listener

CODE

class GUI extends JFrame implements ActionListener


now you have to add the actionListner to your buttons... as GUI implements ActionListener you use "this" tho say that this is that class

CODE

btnFirst = new JButton( "First" );
btnFirst.addActionListener(this);
add( btnFirst );

btnPrevious = new JButton( "Previous" );
btnPrevoius.addActionListener(this);
add( btnPrevious );

btnNext = new JButton( "Next" );
btnNext.addActionListener(this);
add( btnNext);


Now as GUI implements ActionListener it should implements the method actionPerformed

CODE

public void actionPerformed(ActionEvent e) {
   // detremine which object fires that actionPerformed
   Object buttonPressed = e.getSource();
   if(buttonPressed == buttonFirst) {
      index = 0;
      display();
      return;
   }
   if(buttonPressed == buttonNext) {
      displayNext();
      return;
   }
   // not first not next so must be previous
   displayPrevious();
}




User is offlineProfile CardPM
+Quote Post

smithgang1994
RE: Getting My GUI To Loop
14 Jun, 2008 - 05:34 AM
Post #6

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
One question:
Do I take out this
CODE


void setDVD(DVD[] dvd)
{
    this.dvd = dvd;
    index = 0;
    display();
}
void display() {
    jtfItem.setText("" + dvd[index].getItems());
        jtfVideo.setText("" + dvd[index].getVideo());
               jtfRating.setText("" + dvd[index].getRating());
               jtfitmNumber.setText("" + dvd[index].getNumber());
               jtfStock.setText("" + dvd[index].getStock());
               jtfReStock.setText("" + dvd[index].getRestockingFee());
               jtfPrice.setText("" + dvd[index].getPrice());
               jtfValue.setText("" + dvd[index].getValue());
               jtftotalInv.setText("" );

}
   // to display next movie
   void displayNext() {
         index++;
         if(index <= dvd.length)   // wrap around
           index = 0;
         display();
       }
       // display previous
       void displayPrevious() {
           index--;
           if(index > 0)                    // wrap around
             index = dvd.length - 1;
           display();
}


then do I put this in?
CODE


public void actionPerformed(ActionEvent e) {
   // detremine which object fires that actionPerformed
   Object buttonPressed = e.getSource();
   if(buttonPressed == buttonFirst) {
      index = 0;
      display();
      return;
   }
   if(buttonPressed == buttonNext) {
      displayNext();
      return;
   }
   // not first not next so must be previous
   displayPrevious();
}

QUOTE(pbl @ 13 Jun, 2008 - 08:41 PM) *

Ok that is a complete new issue....

To have your buttons to work they must have an ActionListener
so your class GUI needs to "implement" Action listener

CODE

class GUI extends JFrame implements ActionListener


now you have to add the actionListner to your buttons... as GUI implements ActionListener you use "this" tho say that this is that class

CODE

btnFirst = new JButton( "First" );
btnFirst.addActionListener(this);
add( btnFirst );

btnPrevious = new JButton( "Previous" );
btnPrevoius.addActionListener(this);
add( btnPrevious );

btnNext = new JButton( "Next" );
btnNext.addActionListener(this);
add( btnNext);


Now as GUI implements ActionListener it should implements the method actionPerformed

CODE

public void actionPerformed(ActionEvent e) {
   // detremine which object fires that actionPerformed
   Object buttonPressed = e.getSource();
   if(buttonPressed == buttonFirst) {
      index = 0;
      display();
      return;
   }
   if(buttonPressed == buttonNext) {
      displayNext();
      return;
   }
   // not first not next so must be previous
   displayPrevious();
}




User is offlineProfile CardPM
+Quote Post

smithgang1994
RE: Getting My GUI To Loop
14 Jun, 2008 - 08:30 AM
Post #7

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
Can someone tell me what I did wrong to get these errors?

C:\Users\Michael\Desktop\Java5\GUI.java:187: <identifier> expected
Public void actionPerformed(ActionEvent e){
^
C:\Users\Michael\Desktop\Java5\GUI.java:200: ';' expected
^
CODE

import javax.swing.JOptionPane;
import java.awt.FlowLayout; // specifies how components are arranged
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame; // provides basic window features
import javax.swing.JLabel; // displays text and images
import javax.swing.SwingConstants;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JPanel;
import javax.swing.Box;



public class GUI extends JFrame implements ActionListener
{

private JLabel label2; // JLabel Item number
private JLabel label3; // JLabel Title of Movie
private JLabel label4; // JLabel Movie Rating
private JLabel label5; // JLabel Stock Number
private JLabel label6; // JLabel Number of Item in Stock
private JLabel label7; // JLabel Restocking Fee
private JLabel label8; // JLabel Purchase Price
private JLabel label9; // JLabel Inventory Value
private JLabel label10; // JLabel Total Inventory Value
private JTextField jtfItem;
private JTextField jtfVideo; //1
private JTextField jtfRating; //2
private JTextField jtfitmNumber; //3
private JTextField jtfStock;//4
private JTextField jtfReStock; //5   getrestock()
private JTextField jtfPrice; //6
private JTextField jtfValue;   //7   getresult()
private JTextField jtftotalInv;//8
private JLabel label11; //JLabel icon
private JButton btnFirst;
private JButton btnPrevious;
private JButton btnNext;
private JButton btnLast;

DVD[] dvd;
int index = 0;

// LabelFrame constructor adds JLabels to JFrame
public GUI()
{
super( "Inventory of DVD Movies" );
// JLabel constructor with a string argument
  //this.inventory1 = inventory1;


    JLabel jl;
    JPanel jp;

setLayout( new FlowLayout() ); // set frame layout




label2 = new JLabel("Item#: " );
label2.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfItem = new JTextField (30);
jtfItem.setEditable(false);
add( label2 ); // add label2 to JFrame
add(jtfItem);

label3 = new JLabel( "Title of Movie: ");
label3.setHorizontalTextPosition( SwingConstants.RIGHT );
label2.setVerticalTextPosition( SwingConstants.CENTER );
jtfVideo = new JTextField (30);
jtfVideo.setEditable(false);
add( label3 ); // add label2 to JFrame
add(jtfVideo);


label4 = new JLabel("Movie Rating:");
label4.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfRating = new JTextField (30);
jtfRating.setEditable(false);
add( label4 ); // add label2 to JFrame
add(jtfRating);

label5 = new JLabel("Item Number:");
label5.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfitmNumber = new JTextField (30);
jtfitmNumber.setEditable(false);
add( label5 ); // add label2 to JFrame
add(jtfitmNumber);

label6 = new JLabel( "# of Items in Stock:");
label6.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfStock = new JTextField (30);
jtfStock.setEditable(false);
add( label6 ); // add label2 to JFrame
add(jtfStock);

label7 = new JLabel( "Restocking Fee:" );
label7.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfReStock = new JTextField (30);
jtfReStock.setEditable(false);
add( label7 ); // add label2 to JFrame
add(jtfReStock);

label8 = new JLabel( "Purchase Price:");
label8.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfPrice = new JTextField (30);
jtfPrice.setEditable(false);
add( label8 ); // add label2 to JFrame
add(jtfPrice);

label9 = new JLabel( "Inventory Value:");
label9.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfValue = new JTextField (30);
jtfValue.setEditable(false);
add( label9 ); // add label2 to JFrame
add(jtfValue);

label10 = new JLabel( "Total Inventory Value:\n");
label10.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtftotalInv = new JTextField (30);
jtftotalInv.setEditable(false);
add( label10 ); // add label2 to JFrame
add(jtftotalInv);

Icon dvd = new ImageIcon(getClass().getResource( "dvd.jpg" ));
label11 = new JLabel ( dvd, SwingConstants.LEFT);
label11.setVerticalTextPosition( SwingConstants.TOP);
add( label11 );

btnFirst = new JButton( "First" );
btnFirst.addActionListener(this);
add( btnFirst );


btnPrevious = new JButton( "Previous" );
btnPrevious.addActionListener(this);
add( btnPrevious );

btnNext = new JButton( "Next" );
btnNext.addActionListener(this);
add( btnNext );

btnLast = new JButton( "Last" );
btnLast.addActionListener(this);
add( btnLast );





setSize(800,500);
     setVisible(true);



} // end LabelFrame constructor


void setDVD(DVD[] dvd)
{
    this.dvd = dvd;
    index = 0;
    display();
}
void display() {
    jtfItem.setText("" + dvd[index].getItems());
        jtfVideo.setText("" + dvd[index].getVideo());
               jtfRating.setText("" + dvd[index].getRating());
               jtfitmNumber.setText("" + dvd[index].getNumber());
               jtfStock.setText("" + dvd[index].getStock());
               jtfReStock.setText("" + dvd[index].getRestockingFee());
               jtfPrice.setText("" + dvd[index].getPrice());
               jtfValue.setText("" + dvd[index].getValue());
               jtftotalInv.setText("" );
}
Public void actionPerformed(ActionEvent e){
    Object buttonPressed = e.getSource();
    if(buttonPressed == btnFirst){
        index = 0;
        display();
        return;
    }
    if (buttonPressed == btnNext) {
        displayNext();
        return;
    }
    displayPrevious();
}

} // end class GUI



QUOTE(smithgang1994 @ 14 Jun, 2008 - 06:34 AM) *

One question:
Do I take out this
CODE


void setDVD(DVD[] dvd)
{
    this.dvd = dvd;
    index = 0;
    display();
}
void display() {
    jtfItem.setText("" + dvd[index].getItems());
        jtfVideo.setText("" + dvd[index].getVideo());
               jtfRating.setText("" + dvd[index].getRating());
               jtfitmNumber.setText("" + dvd[index].getNumber());
               jtfStock.setText("" + dvd[index].getStock());
               jtfReStock.setText("" + dvd[index].getRestockingFee());
               jtfPrice.setText("" + dvd[index].getPrice());
               jtfValue.setText("" + dvd[index].getValue());
               jtftotalInv.setText("" );

}
   // to display next movie
   void displayNext() {
         index++;
         if(index <= dvd.length)   // wrap around
           index = 0;
         display();
       }
       // display previous
       void displayPrevious() {
           index--;
           if(index > 0)                    // wrap around
             index = dvd.length - 1;
           display();
}


then do I put this in?
CODE


public void actionPerformed(ActionEvent e) {
   // detremine which object fires that actionPerformed
   Object buttonPressed = e.getSource();
   if(buttonPressed == buttonFirst) {
      index = 0;
      display();
      return;
   }
   if(buttonPressed == buttonNext) {
      displayNext();
      return;
   }
   // not first not next so must be previous
   displayPrevious();
}

QUOTE(pbl @ 13 Jun, 2008 - 08:41 PM) *

Ok that is a complete new issue....

To have your buttons to work they must have an ActionListener
so your class GUI needs to "implement" Action listener

CODE

class GUI extends JFrame implements ActionListener


now you have to add the actionListner to your buttons... as GUI implements ActionListener you use "this" tho say that this is that class

CODE

btnFirst = new JButton( "First" );
btnFirst.addActionListener(this);
add( btnFirst );

btnPrevious = new JButton( "Previous" );
btnPrevoius.addActionListener(this);
add( btnPrevious );

btnNext = new JButton( "Next" );
btnNext.addActionListener(this);
add( btnNext);


Now as GUI implements ActionListener it should implements the method actionPerformed

CODE

public void actionPerformed(ActionEvent e) {
   // detremine which object fires that actionPerformed
   Object buttonPressed = e.getSource();
   if(buttonPressed == buttonFirst) {
      index = 0;
      display();
      return;
   }
   if(buttonPressed == buttonNext) {
      displayNext();
      return;
   }
   // not first not next so must be previous
   displayPrevious();
}





User is offlineProfile CardPM
+Quote Post

sktr4life
RE: Getting My GUI To Loop
14 Jun, 2008 - 09:31 AM
Post #8

New D.I.C Head
*

Joined: 24 May, 2008
Posts: 16

let me see if i can help you...let me test it out real quick.

LOL!!


CODE


Public void actionPerformed(ActionEvent e){



look at it CAREFULLY.

"Public" isnt used or identified by JAVA, because "public" isnt capitalized.

insted of "Public" use "public"

User is offlineProfile CardPM
+Quote Post

pbl
RE: Getting My GUI To Loop
14 Jun, 2008 - 01:43 PM
Post #9

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
QUOTE(smithgang1994 @ 14 Jun, 2008 - 06:34 AM) *

One question:
Do I take out this


Your choice.... these System.out.println() won't be seen by the user running your GUI, they are just there for your debugging purpose.
You might move the System.out.println() in your actionPerformed() method especially if you think to add an "Insert" and "Delete" buttons in the future. Keep in mind thow that this System.out.println() will be displayed every time the user hit a button.

User is online!Profile CardPM
+Quote Post

smithgang1994
RE: Getting My GUI To Loop
15 Jun, 2008 - 08:19 PM
Post #10

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
K i fixed the public capitalization error now I get a cant find symbol error for displayNext and displayPrevious. Here is a copy of my code. Thanks.
CODE

import javax.swing.JOptionPane;
import java.awt.FlowLayout; // specifies how components are arranged
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame; // provides basic window features
import javax.swing.JLabel; // displays text and images
import javax.swing.SwingConstants;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JPanel;
import javax.swing.Box;



public class GUI extends JFrame implements ActionListener
{

private JLabel label2; // JLabel Item number
private JLabel label3; // JLabel Title of Movie
private JLabel label4; // JLabel Movie Rating
private JLabel label5; // JLabel Stock Number
private JLabel label6; // JLabel Number of Item in Stock
private JLabel label7; // JLabel Restocking Fee
private JLabel label8; // JLabel Purchase Price
private JLabel label9; // JLabel Inventory Value
private JLabel label10; // JLabel Total Inventory Value
private JTextField jtfItem;
private JTextField jtfVideo; //1
private JTextField jtfRating; //2
private JTextField jtfitmNumber; //3
private JTextField jtfStock;//4
private JTextField jtfReStock; //5   getrestock()
private JTextField jtfPrice; //6
private JTextField jtfValue;   //7   getresult()
private JTextField jtftotalInv;//8
private JLabel label11; //JLabel icon
private JButton btnFirst;
private JButton btnPrevious;
private JButton btnNext;
private JButton btnLast;

DVD[] dvd;
int index = 0;

// LabelFrame constructor adds JLabels to JFrame
public GUI()
{
super( "Inventory of DVD Movies" );
// JLabel constructor with a string argument
  //this.inventory1 = inventory1;


    JLabel jl;
    JPanel jp;

setLayout( new FlowLayout() ); // set frame layout




label2 = new JLabel("Item#: " );
label2.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfItem = new JTextField (30);
jtfItem.setEditable(false);
add( label2 ); // add label2 to JFrame
add(jtfItem);

label3 = new JLabel( "Title of Movie: ");
label3.setHorizontalTextPosition( SwingConstants.RIGHT );
label2.setVerticalTextPosition( SwingConstants.CENTER );
jtfVideo = new JTextField (30);
jtfVideo.setEditable(false);
add( label3 ); // add label2 to JFrame
add(jtfVideo);


label4 = new JLabel("Movie Rating:");
label4.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfRating = new JTextField (30);
jtfRating.setEditable(false);
add( label4 ); // add label2 to JFrame
add(jtfRating);

label5 = new JLabel("Item Number:");
label5.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfitmNumber = new JTextField (30);
jtfitmNumber.setEditable(false);
add( label5 ); // add label2 to JFrame
add(jtfitmNumber);

label6 = new JLabel( "# of Items in Stock:");
label6.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfStock = new JTextField (30);
jtfStock.setEditable(false);
add( label6 ); // add label2 to JFrame
add(jtfStock);

label7 = new JLabel( "Restocking Fee:" );
label7.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfReStock = new JTextField (30);
jtfReStock.setEditable(false);
add( label7 ); // add label2 to JFrame
add(jtfReStock);

label8 = new JLabel( "Purchase Price:");
label8.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfPrice = new JTextField (30);
jtfPrice.setEditable(false);
add( label8 ); // add label2 to JFrame
add(jtfPrice);

label9 = new JLabel( "Inventory Value:");
label9.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfValue = new JTextField (30);
jtfValue.setEditable(false);
add( label9 ); // add label2 to JFrame
add(jtfValue);

label10 = new JLabel( "Total Inventory Value:\n");
label10.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtftotalInv = new JTextField (30);
jtftotalInv.setEditable(false);
add( label10 ); // add label2 to JFrame
add(jtftotalInv);

Icon dvd = new ImageIcon(getClass().getResource( "dvd.jpg" ));
label11 = new JLabel ( dvd, SwingConstants.LEFT);
label11.setVerticalTextPosition( SwingConstants.TOP);
add( label11 );

btnFirst = new JButton( "First" );
btnFirst.addActionListener(this);
add( btnFirst );


btnPrevious = new JButton( "Previous" );
btnPrevious.addActionListener(this);
add( btnPrevious );

btnNext = new JButton( "Next" );
btnNext.addActionListener(this);
add( btnNext );

btnLast = new JButton( "Last" );
btnLast.addActionListener(this);
add( btnLast );





setSize(800,500);
     setVisible(true);



} // end LabelFrame constructor


void setDVD(DVD[] dvd)
{
    this.dvd = dvd;
    index = 0;
    display();
}
void display() {
    jtfItem.setText("" + dvd[index].getItems());
        jtfVideo.setText("" + dvd[index].getVideo());
               jtfRating.setText("" + dvd[index].getRating());
               jtfitmNumber.setText("" + dvd[index].getNumber());
               jtfStock.setText("" + dvd[index].getStock());
               jtfReStock.setText("" + dvd[index].getRestockingFee());
               jtfPrice.setText("" + dvd[index].getPrice());
               jtfValue.setText("" + dvd[index].getValue());
               jtftotalInv.setText("" );
}
Public void actionPerformed(ActionEvent e){
    Object buttonPressed = e.getSource();
    if(buttonPressed == btnFirst){
        index = 0;
        display();
        return;
    }
    if (buttonPressed == btnNext) {
        displayNext();
        return;
    }
    displayPrevious();
}

} // end class GUI


QUOTE(sktr4life @ 14 Jun, 2008 - 10:31 AM) *

let me see if i can help you...let me test it out real quick.

LOL!!


CODE


Public void actionPerformed(ActionEvent e){



look at it CAREFULLY.

"Public" isnt used or identified by JAVA, because "public" isnt capitalized.

insted of "Public" use "public"


User is offlineProfile CardPM
+Quote Post

pbl
RE: Getting My GUI To Loop
15 Jun, 2008 - 08:39 PM
Post #11

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
Het Sweetie (you are a "she" if I remeber well) where are your methods

CODE

// to display next movie
   void displayNext() {
         index++;
         if(index <= dvd.length)   // wrap around
           index = 0;
         display();
       }
       // display previous
       void displayPrevious() {
           index--;
           if(index > 0)                    // wrap around
             index = dvd.length - 1;
           display();
}


displayNext() and displayPrevious() that were in your original code ?
User is online!Profile CardPM