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

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




help with buttons

 
Reply to this topicStart new topic

help with buttons

smithgang1994
13 Jun, 2008 - 12:36 PM
Post #1

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
I am trying to add 5 buttons to work. What am I missing?



CODE

import java.util.Arrays;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//a liitle GUI
class GUI1 extends JFrame {
    protected double currentItems;
    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 JButton btnIcon; //JLabel icon
    private JButton btnFirst;
    private JButton btnPrevious;
    private JButton btnNext;
    private JButton btnLast;

// movies to display
DVD[] dvd;
// index of the movie to display
int index = 0;


    GUI1(){
        super("Inventory Part of DVD Movies");
        //this.inventory1 = inventory1;

        JButton btn;
        JPanel jp;
        JLabel jl;
        JPanel outerPanel = new JPanel();
        outerPanel.setLayout(new BoxLayout(outerPanel, BoxLayout.Y_AXIS));

        JPanel titlePanel = new JPanel();
        titlePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
        jl = new JLabel("Inventory Part 4");
        titlePanel.add(jl);
        outerPanel.add(titlePanel);

        JPanel numberPanel = new JPanel();
        numberPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("Video: " );
        numberPanel.add(jl);
        jtfVideo = new JTextField (21);
        jtfVideo.setEditable(false);
        numberPanel.add(jtfVideo);
        outerPanel.add(numberPanel);

        JPanel number1Panel = new JPanel();
        number1Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("Rating: " );
        number1Panel.add(jl);
        jtfRating = new JTextField(21);
        jtfRating.setEditable(false);
        number1Panel.add(jtfRating);
        outerPanel.add(number1Panel);

        JPanel number2Panel = new JPanel();
        number2Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("Item Number: ");
        number2Panel.add(jl);
        jtfitmNumber = new JTextField(21);
        jtfitmNumber.setEditable(false);
        number2Panel.add(jtfitmNumber);
        outerPanel.add(number2Panel);

        JPanel number3Panel = new JPanel();
        number3Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("Stock: " );
        number3Panel.add(jl);
        jtfStock = new JTextField(21);
        jtfStock.setEditable(false);
        number3Panel.add(jtfStock);
        outerPanel.add(number3Panel);

        JPanel number4Panel = new JPanel();
        number4Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("Restocking Fee: $ " );
        number4Panel.add(jl);
        jtfReStock = new JTextField(21);
        jtfReStock.setEditable(false);
        number4Panel.add(jtfReStock);
        outerPanel.add(number4Panel);

        JPanel number5Panel = new JPanel();
        number5Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("Price: $ " );
        number5Panel.add(jl);
        jtfPrice = new JTextField(21);
        jtfPrice.setEditable(false);
        number5Panel.add(jtfPrice);
        outerPanel.add(number5Panel);

        JPanel number6Panel = new JPanel();
        number6Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("Value: $ " );
        number6Panel.add(jl);
        jtfValue = new JTextField(21);
        jtfValue.setEditable(false);
        number6Panel.add(jtfValue);
        outerPanel.add(number6Panel);

        JPanel number7Panel = new JPanel();
        number7Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("Total Invenory Value: $" );
        number7Panel.add(jl);
        jtftotalInv = new JTextField(21);
        jtftotalInv.setEditable(false);
        number7Panel.add(jtftotalInv);
        outerPanel.add(number7Panel);


        Icon dvd = new ImageIcon(getClass().getResource( "dvd.jpg" ));
        btnIcon = new JButton ( "DVD",dvd);
        add( btnIcon );

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

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

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

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

        ButtonHandler handler = new ButtonHandler();
        btnIcon.addActionListener( handler );
        btnFirst.addActionListener( handler );
        btnPrevious.addActionListener( handler );
        btnNext.addActionListener( handler );
        btnLast.addActionListener( handler );


        setContentPane(outerPanel);
        setResizable(false);
        setSize(800, 800);
        setVisible(true);

      }

void setDVD(DVD[] dvd) {
   // keep the movies
   this.dvd = dvd;
   index = 0;
   display();
}

   void display() {
       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 GUI1 class


CODE

//Overloaded constructors used to initialize inventory
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



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);

GUI1 gui1 = new GUI1();
gui1.setDVD(library);





for (int index = 0; index < library.length; index++)
    {



}//end


library[0].SortInventory1(library);

for (int index = 0; index < library.length; index++)
    {

}//end


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

mensahero
RE: Help With Buttons
13 Jun, 2008 - 12:39 PM
Post #2

c0mput3rz Are Only Human
Group Icon

Joined: 26 May, 2008
Posts: 664



Thanked: 17 times
Dream Kudos: 75
My Contributions
QUOTE

I am trying to add 5 buttons to work. What am I missing?


is that a trick question? blink.gif .. or I'm just stupid I don't get it.. lmao..

This post has been edited by mensahero: 13 Jun, 2008 - 12:39 PM
User is offlineProfile CardPM
+Quote Post

gl3thr0
RE: Help With Buttons
13 Jun, 2008 - 12:39 PM
Post #3

D.I.C Head
**

Joined: 27 Oct, 2007
Posts: 209



Thanked: 3 times
My Contributions
LOL
i love when you get two ppl from the same class (i think thats what we have here)

smithgang1994 do you happen to know deepacc?
u both seem to have the same assignment

This post has been edited by gl3thr0: 13 Jun, 2008 - 12:47 PM
User is offlineProfile CardPM
+Quote Post

mensahero
RE: Help With Buttons
13 Jun, 2008 - 12:42 PM
Post #4

c0mput3rz Are Only Human
Group Icon

Joined: 26 May, 2008
Posts: 664



Thanked: 17 times
Dream Kudos: 75
My Contributions
QUOTE(gl3thr0 @ 13 Jun, 2008 - 01:39 PM) *

LOL
i love when you get two ppl from the same class (i think thats what we have here)

smithgang1994 do happen to know deepacc?
u both seem to have the same assignment


they have the same GUI class.. lmao.. and same requirements.. maybe the whole class is in here.. biggrin.gif biggrin.gif

DIC is the standard programming community promoted in Computer Schools.. lmao.. blink.gif

User is offlineProfile CardPM
+Quote Post

smithgang1994
RE: Help With Buttons
13 Jun, 2008 - 12:46 PM
Post #5

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
nope dont know him...just trying to muttle my way with this class. I only have one week after this. Hopefully after this I will not have to do Java ever again :-) I just need to make it through this class. So any help will be greatly appreciated.

QUOTE(gl3thr0 @ 13 Jun, 2008 - 01:39 PM) *

LOL
i love when you get two ppl from the same class (i think thats what we have here)

smithgang1994 do happen to know deepacc?
u both seem to have the same assignment



If it is they neglected to inform us smile.gif I found this site through google and it has been a great help so far.

QUOTE(mensahero @ 13 Jun, 2008 - 01:42 PM) *

QUOTE(gl3thr0 @ 13 Jun, 2008 - 01:39 PM) *

LOL
i love when you get two ppl from the same class (i think thats what we have here)

smithgang1994 do happen to know deepacc?
u both seem to have the same assignment


they have the same GUI class.. lmao.. and same requirements.. maybe the whole class is in here.. biggrin.gif biggrin.gif

DIC is the standard programming community promoted in Computer Schools.. lmao.. blink.gif


User is offlineProfile CardPM
+Quote Post

mensahero
RE: Help With Buttons
13 Jun, 2008 - 12:47 PM
Post #6

c0mput3rz Are Only Human
Group Icon

Joined: 26 May, 2008
Posts: 664



Thanked: 17 times
Dream Kudos: 75
My Contributions
ok.. you're not related.. but still.. your problem is not specific..

QUOTE

I am trying to add 5 buttons to work. What am I missing?


Is that all? no more info on the problem? .. or that's a trick question.. are we supposed to guess what's missing? lmao.. blink.gif
User is offlineProfile CardPM
+Quote Post

smithgang1994
RE: Help With Buttons
13 Jun, 2008 - 12:55 PM
Post #7

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
no, sorry I am leaving to go out of town tomorrow and this assignment is due Sunday. I am stressed and didnt think before I posted. What I need to know is this:
I am getting these errors and I followed the textbook so why doesnt this work for me? besides the fact that I can never get an answer from my instructor!! I agree with mensahero(my instructor leaves alot to be desired!!)

C:\Users\Michael\Desktop\Java5\GUI1.java:133: cannot find symbol
symbol : class ButtonHandler
location: class GUI1
ButtonHandler handler = new ButtonHandler();
^
C:\Users\Michael\Desktop\Java5\GUI1.java:133: cannot find symbol
symbol : class ButtonHandler
location: class GUI1
ButtonHandler handler = new ButtonHandler();
^
2 errors


QUOTE(mensahero @ 13 Jun, 2008 - 01:47 PM) *

ok.. you're not related.. but still.. your problem is not specific..

QUOTE

I am trying to add 5 buttons to work. What am I missing?


Is that all? no more info on the problem? .. or that's a trick question.. are we supposed to guess what's missing? lmao.. blink.gif


User is offlineProfile CardPM
+Quote Post

smithgang1994
RE: Help With Buttons
13 Jun, 2008 - 01:05 PM
Post #8

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
okay scrap that code I gave you I got it to work with my other code I was using!!
CODE

public class GUI extends JFrame
{
private JLabel label1; // JLabel Non sorted DVD Inventory
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 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;
setLayout( new FlowLayout() ); // set frame layout


label1 = new JLabel("<html><font size=+1>Non sorted DVD inventory</html>");
label1.setHorizontalTextPosition( SwingConstants.CENTER );
label1.setVerticalTextPosition( SwingConstants.CENTER );

add( label1 ); // add label1 to JFrame

label2 = new JLabel( "\nItem#: " );
label2.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );

add( label2 ); // add label2 to JFrame

label3 = new JLabel( "\nTitle of Movie: ");
add( label3 ); // add label3 to JFrame

label4 = new JLabel("\nMovie Rating:");
add( label4 );

label5 = new JLabel("\nItem Number:");
add( label5 );

label6 = new JLabel( "\n# of Items in Stock:");
add( label6 );

label7 = new JLabel( "\nRestocking Fee:" );
add( label7 );

label8 = new JLabel( "\nPurchase Price:");
add( label8 );

label9 = new JLabel( "\nInventory Value:");
add( label9 );

label10 = new JLabel( "\nTotal Inventory Value:\n");
add( label10 );

Icon dvd = new ImageIcon(getClass().getResource( "dvd.jpg" ));
label11 = new JLabel ( dvd, SwingConstants.LEFT);
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(500,300);
     setVisible(true);



} // end LabelFrame constructor

void setDVD(DVD[] dvd)
{
    this.dvd = dvd;
    index = 0;
    display();
}
void display() {
        label2.setText("/Item #:" + dvd[index].getItems());
       label3.setText("/Video Name:" + dvd[index].getVideo());
       label4.setText("/Video Rating:" + dvd[index].getRating());
       label5.setText("/Item Number: " + dvd[index].getNumber());
       label6.setText("/Number of Items in Stock: " + dvd[index].getStock());
       label7.setText("/Restocking Fee: " + dvd[index].getRestockingFee());
       label8.setText("/Price of Movie: " + dvd[index].getPrice());
       label9.setText("/Inventory Value: " + dvd[index].getValue());
       label10.setText("/Total Inventory Value: ");

}
   // 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

User is offlineProfile CardPM
+Quote Post

smithgang1994
RE: Help With Buttons
13 Jun, 2008 - 01:43 PM
Post #9

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
okay..new question. I cant get my icon to go into the bottom left hand corner . What am I doing wrong...besides everything tongue.gif

CODE


import javax.swing.JOptionPane;
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.SwingConstants;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;



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 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;
setLayout( new FlowLayout() ); // set frame layout




label2 = new JLabel( "\nItem#: " );
label2.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );

add( label2 ); // add label2 to JFrame

label3 = new JLabel( "Title of Movie: ");
label3.setHorizontalTextPosition( SwingConstants.LEFT );
add( label3 ); // add label3 to JFrame

label4 = new JLabel("Movie Rating:");
label4.setHorizontalTextPosition( SwingConstants.LEFT );
add( label4 );

label5 = new JLabel("Item Number:");
label5.setHorizontalTextPosition( SwingConstants.LEFT );
add( label5 );

label6 = new JLabel( "# of Items in Stock:");
label6.setHorizontalTextPosition( SwingConstants.LEFT );
add( label6 );

label7 = new JLabel( "Restocking Fee:" );
label7.setHorizontalTextPosition( SwingConstants.LEFT );
add( label7 );

label8 = new JLabel( "Purchase Price:");
label8.setHorizontalTextPosition( SwingConstants.LEFT );
add( label8 );

label9 = new JLabel( "Inventory Value:");
label9.setHorizontalTextPosition( SwingConstants.LEFT );
add( label9 );

label10 = new JLabel( "Total Inventory Value:\n");
label10.setHorizontalTextPosition( SwingConstants.LEFT );
add( label10 );

Icon dvd = new ImageIcon(getClass().getResource( "dvd.jpg" ));
label11 = new JLabel ( dvd, SwingConstants.LEFT);
label11.setVerticalTextPosition( SwingConstants.BOTTOM);
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(500,300);
     setVisible(true);



} // end LabelFrame constructor

void setDVD(DVD[] dvd)
{
    this.dvd = dvd;
    index = 0;
    display();
}
void display() {
        label2.setText("/Item #:" + dvd[index].getItems());
       label3.setText("/Video Name:" + dvd[index].getVideo());
       label4.setText("/Video Rating:" + dvd[index].getRating());
       label5.setText("/Item Number: " + dvd[index].getNumber());
       label6.setText("/Number of Items in Stock: " + dvd[index].getStock());
       label7.setText("/Restocking Fee: " + dvd[index].getRestockingFee());
       label8.setText("/Price of Movie: " + dvd[index].getPrice());
       label9.setText("/Inventory Value: " + dvd[index].getValue());
       label10.setText("/Total Inventory Value: ");

}
   // 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


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 10:43PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month