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

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




GUI help

 
Reply to this topicStart new topic

GUI help

smithgang1994
8 Jun, 2008 - 04:35 PM
Post #1

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
I can get my labels to work but I can't get my data from the rest of my program to compile into my GUI. In the reading that we were given on this topic it does not show us how to get the data. It only shows how to type the data in line by line, but I know there has to be an easier way.

CODE

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;


public class LabelFrame 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 Sorted DVD Inventory
private JLabel label12; // JLabel Item number
private JLabel label13; // JLabel Title of Movie
private JLabel label14; // JLabel Movie Rating
private JLabel label15; // JLabel Stock Number
private JLabel label16; // JLabel Number of Item in Stock
private JLabel label17; // JLabel Restocking Fee
private JLabel label18; // JLabel Purchase Price
private JLabel label19; // JLabel Inventory Value
private JLabel label20; // JLabel Total Inventory Value

int index = 0;

// LabelFrame constructor adds JLabels to JFrame
public LabelFrame()
{
super( "Inventory of DVD Movies" );
setLayout( new FlowLayout() ); // set frame layout

// JLabel constructor with a string argument
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 );

label11 = new JLabel("<html><font size=+1>\nSorted DVD inventory</html>");
label11.setHorizontalTextPosition( SwingConstants.CENTER );
label11.setVerticalTextPosition( SwingConstants.CENTER );
add(label11 );

label12 = new JLabel( "\nItem#:" );
label12.setHorizontalTextPosition( SwingConstants.LEFT );
label12.setVerticalTextPosition( SwingConstants.TOP );
  add( label12 ); // add label2 to JFrame

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

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

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

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

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

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

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

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

setSize(1200,300);
     setVisible(true);
} // end LabelFrame constructor

public static void main(String args[])
{
LabelFrame f = new LabelFrame();



}
} // end class LabelFrame


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




System.out.println( "\nInventory of DVD Movies: " );

for (int index = 0; index < library.length; index++)
    {
        System.out.printf( "\nItem #%s ", library[index].getItems());
        System.out.printf( "\nTitle of Movie: \t%s", library[index].getVideo());
        System.out.printf( "\nMovie Rating: \t\t%s", library[index].getRating() );
        System.out.printf( "\nItem Number:   \t\t%s", library[index].getNumber());
        System.out.printf( "\n# of Items in Stock: \t%s", library[index].getStock());
        System.out.printf( "\nRestocking Fee: \t%s", library[index].getRestockingFee() );
      System.out.printf( "\nPurchase Price: \t$%s", library[index].getPrice());
        System.out.printf( "\nInventory Value: \t$%s\n\n", library[index].getValue());



}//end




library[0].SortInventory1(library);
System.out.println( "\nSorted Inventory of DVD Movies:");
for (int index = 0; index < library.length; index++)
    {
      System.out.printf( "\nItem #%s ", library[index].getItems());
      System.out.printf( "\nTitle of Movie: \t%s", library[index].getVideo());
      System.out.printf( "\nMovie Rating: \t\t%s", library[index].getRating() );
      System.out.printf( "\nItem Number:   \t\t%s", library[index].getNumber());
      System.out.printf( "\n# of Items in Stock: \t%s", library[index].getStock());
    System.out.printf( "\nRestocking Fee: \t%s", library[index].getRestockingFee() );
     System.out.printf( "\nPurchase Price: \t$%s", library[index].getPrice());
      System.out.printf( "\nInventory Value: \t$%s\n\n", library[index].getValue());

}//end


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

  System.out.printf( "Total Inventory Value: \t$%s\n\n", totalInv );

//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: GUI Help
8 Jun, 2008 - 06:15 PM
Post #2

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
There is no link betwwen your LabelFrame class/object and your Inventory1Test class/object
These a 2 different program

Somebody had the same problem then you have with almost the same program
(and problem turning a console incentory program into a GUI version)

http://www.dreamincode.net/forums/showtopic54041.htm


User is offlineProfile CardPM
+Quote Post

mensahero
RE: GUI Help
8 Jun, 2008 - 07:41 PM
Post #3

c0mput3rz Are Only Human
Group Icon

Joined: 26 May, 2008
Posts: 664



Thanked: 17 times
Dream Kudos: 75
My Contributions
QUOTE(pbl @ 8 Jun, 2008 - 07:15 PM) *


Somebody had the same problem then you have with almost the same program
(and problem turning a console incentory program into a GUI version)

http://www.dreamincode.net/forums/showtopic54041.htm



off topic..

Weird.. maybe they all belong in the same class.. blink.gif they all have the same project.. the same problem.. and so on.. blink.gif blink.gif

DIC is really popular.. biggrin.gif

User is offlineProfile CardPM
+Quote Post

smithgang1994
RE: GUI Help
8 Jun, 2008 - 07:48 PM
Post #4

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
QUOTE(mensahero @ 8 Jun, 2008 - 08:41 PM) *

QUOTE(pbl @ 8 Jun, 2008 - 07:15 PM) *


Somebody had the same problem then you have with almost the same program
(and problem turning a console incentory program into a GUI version)

http://www.dreamincode.net/forums/showtopic54041.htm



off topic..

Weird.. maybe they all belong in the same class.. blink.gif they all have the same project.. the same problem.. and so on.. blink.gif blink.gif

DIC is really popular.. biggrin.gif


User is offlineProfile CardPM
+Quote Post

smithgang1994
RE: GUI Help
8 Jun, 2008 - 08:04 PM
Post #5

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
My post didn't go through but what I said was, yes you are very popular smile.gif I think it is because you guys explain well what needs to be done and why. The reading we are given has good examples but does not do an adaquate job of describing. I will be so glad when this class is over and I can leave Java to the experts...YA'll smile.gif Thanks for all the help that that has been given.

QUOTE(mensahero @ 8 Jun, 2008 - 08:41 PM) *

QUOTE(pbl @ 8 Jun, 2008 - 07:15 PM) *


Somebody had the same problem then you have with almost the same program
(and problem turning a console incentory program into a GUI version)

http://www.dreamincode.net/forums/showtopic54041.htm



off topic..

Weird.. maybe they all belong in the same class.. blink.gif they all have the same project.. the same problem.. and so on.. blink.gif blink.gif

DIC is really popular.. biggrin.gif


User is offlineProfile CardPM
+Quote Post

smithgang1994
RE: GUI Help
8 Jun, 2008 - 08:22 PM
Post #6

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
I am looking and pondering what you gave the other guy... but I have one question for you... Does it matter that he is working with JTextField and I am working with JLabel. One part I am not too clear on is where you gave him this: do I just change the jtf to jl?
CODE

// code that display movie[index] in the JTextField
         void display() {
          // now here you have to add the code to take the fiels in movie[index]
          // and to put them in the JTextField of GUI
          // as I don't have the code of the class Movie I cannot write it for you
          // but it should look like
          jtfrdName.setText(movie[index].getName());
          jtfprdUnit.setText("" + movie[index].getUnit());
          jtfprdItem.setText("" + movie[index].getItem());
          ///and so on



QUOTE(pbl @ 8 Jun, 2008 - 07:15 PM) *

There is no link betwwen your LabelFrame class/object and your Inventory1Test class/object
These a 2 different program

Somebody had the same problem then you have with almost the same program
(and problem turning a console incentory program into a GUI version)

http://www.dreamincode.net/forums/showtopic54041.htm


User is offlineProfile CardPM
+Quote Post

pbl
RE: GUI Help
8 Jun, 2008 - 08:28 PM
Post #7

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
QUOTE(smithgang1994 @ 8 Jun, 2008 - 09:22 PM) *

I am looking and pondering what you gave the other guy... but I have one question for you... Does it matter that he is working with JTextField and I am working with JLabel. One part I am not too clear on is where you gave him this: do I just change the jtf to jl?

In your case the only difference will be that JLabel are (by default) transparent so they will have the same background color as the panel/frame
JTextField have a default background color an can be edited... might not be a good idea in your case unles you want the GUI to be able to change Item name, number, prices, ......

but you can change the "transparent" behaviour of JLabel by making them opaque

JLabel label = new JLabel("");
label.setOpaque(true);
label.setBackground(Color.WHITE);

if your code works with one or the other don't bother changing them

This post has been edited by pbl: 8 Jun, 2008 - 08:31 PM
User is offlineProfile CardPM
+Quote Post

smithgang1994
RE: GUI Help
8 Jun, 2008 - 08:36 PM
Post #8

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
So let me see if I understand you correctly. My code should look as follows: and this goes into my GUI class (or in my case LabelFrame class)?
CODE

jlVideo.setText(movie[index].getVideo());
          jlStock.setText("" + movie[index].getStock());
          jlItem.setText("" + movie[index].getItem())


QUOTE(pbl @ 8 Jun, 2008 - 09:28 PM) *

QUOTE(smithgang1994 @ 8 Jun, 2008 - 09:22 PM) *

I am looking and pondering what you gave the other guy... but I have one question for you... Does it matter that he is working with JTextField and I am working with JLabel. One part I am not too clear on is where you gave him this: do I just change the jtf to jl?

In your case the only difference will be that JLabel are (by default) transparent so they will have the same background color as the panel/frame
JTextField have a default background color an can be edited... might not be a good idea in your case unles you want the GUI to be able to change Item name, number, prices, ......

but you can change the "transparent" behaviour of JLabel by making them opaque

JLabel label = new JLabel("");
label.setOpaque(true);
label.setBackground(Color.WHITE);

if your code works with one or the other don't bother changing them


User is offlineProfile CardPM
+Quote Post

pbl
RE: GUI Help
8 Jun, 2008 - 08:40 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 @ 8 Jun, 2008 - 09:36 PM) *

So let me see if I understand you correctly. My code should look as follows: and this goes into my GUI class (or in my case LabelFrame class)?
CODE

jlVideo.setText(movie[index].getVideo());
          jlStock.setText("" + movie[index].getStock());
          jlItem.setText("" + movie[index].getItem())




Got it son... and index is an int which value is 0
if you have an array of movie in LabelFrame

User is offlineProfile CardPM
+Quote Post

smithgang1994
RE: GUI Help
8 Jun, 2008 - 08:44 PM
Post #10

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
btw..I'm not a son smile.gif

QUOTE(pbl @ 8 Jun, 2008 - 09:40 PM) *

QUOTE(smithgang1994 @ 8 Jun, 2008 - 09:36 PM) *

So let me see if I understand you correctly. My code should look as follows: and this goes into my GUI class (or in my case LabelFrame class)?
CODE

jlVideo.setText(movie[index].getVideo());
          jlStock.setText("" + movie[index].getStock());
          jlItem.setText("" + movie[index].getItem())




Got it son... and index is an int which value is 0
if you have an array of movie in LabelFrame


User is offlineProfile CardPM
+Quote Post

pbl
RE: GUI Help
8 Jun, 2008 - 08:50 PM
Post #11

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
QUOTE(smithgang1994 @ 8 Jun, 2008 - 09:44 PM) *

btw..I'm not a son smile.gif

yah your right I'm too old to procreate since 15 years smile.gif
User is offlineProfile CardPM
+Quote Post

smithgang1994
RE: GUI Help
8 Jun, 2008 - 08:53 PM
Post #12

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
no you misunderstand...I am a she not a he smile.gif



QUOTE(pbl @ 8 Jun, 2008 - 09:50 PM) *

QUOTE(smithgang1994 @ 8 Jun, 2008 - 09:44 PM) *

btw..I'm not a son smile.gif

yah your right I'm too old to procreate since 15 years smile.gif


User is offlineProfile CardPM
+Quote Post

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

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