•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 426,141 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,661 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 481 | Replies: 1
![]() |
•
•
Join Date: Jan 2007
Location: Stevesville, Montana, USA
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
I have tried to rezize my output window by changing the values in the width and legth - nothing happens. What am I doing wrong?
private final static int FRAME_GRID_ROWS = 3;
private final static int FRAME_GRID_COLS = 1;
private final static int FIELD_PANEL_ROWS = 10;
private final static int FIELD_PANEL_COLS = 5;
private final static int MAIN_PANEL_ROWS = 1;
private final static int MAIN_PANEL_COLS = 4;
private final static String EMPTY_ARRAY_MESSAGE = "Hit ADD to add a new Book";
private final static int FRAME_WIDTH = 350;
private final static int FRAME_LENGTH = 300;
private final static int FRAME_XLOC = 250;
private final static int FRAME_YLOC = 100;•
•
•
•
I also tried making changes in this part of the code to no avail. No matter what I change the numbers to, my window opens up the same size. Is there some code somewhere that controls this that I am not seeing?
//Set some of the frame properties
setSize( 350, 570 );
setLocation( FRAME_XLOC , FRAME_YLOC );
pack();
setResizable(true);
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
setVisible( true );•
•
•
•
Here is the rest of the code for this file, there are 2 more files with this program, but I don't think they have any code that would affect the size of the output window.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*; //For java.awt.
import java.util.Arrays;
public class Inventory6 extends JFrame
{
//Private Variables
//The private data
private Book [] book; //The inventory -- an array of Books
private int index; //An index for keep track of the Book to display
//Panels
private JPanel logoPanel; //Panel for placing the logo label
private JPanel fieldPanel; //Panel for placing the JTextFields and their JLabels
private JPanel mainPanel; //Panel for placing the main JButtons
//Labels
private JLabel logoLabel; //Label for displaying the logo
private JLabel nameLabel; //Label for the product name
private JLabel idLabel; //Label for the product id
private JLabel pagesLabel; //Label for the Book pages
private JLabel unitsLabel; //Label for the units in stock
private JLabel priceLabel; //Label for the price
private JLabel valueLabel; //Label for the stock value
private JLabel feeLabel; //Label for the restocking fee
private JLabel totalLabel; //Label for the total value of the inventory
//Text Fields
private JTextField nameText; //Field for displaying/editing the product name
private JTextField idText; //Field for displaying/editing the product id
private JTextField pagesText; //Field for displaying/editing the Book pages
private JTextField unitsText; //Field for displaying/editing the units in stock
private JTextField priceText; //Field for displaying/editing the Book price
private JTextField valueText; //Field for displaying/editing the Book stock value
private JTextField feeText; //Field for displaying/editing the Book restocking fee
private JTextField totalText; //Field for displaying/editing the total inventory value
//Navigation Buttons
private JButton firstButton; //Button for moving to the first element in the array
private JButton nextButton; //Button for moving to the next element in the array
private JButton previousButton; //Button for moving to the next element in the array
private JButton lastButton; //Button for moving to the first element in the array
//Constants
private final static int FRAME_GRID_ROWS = 3;
private final static int FRAME_GRID_COLS = 1;
private final static int FIELD_PANEL_ROWS = 10;
private final static int FIELD_PANEL_COLS = 5;
private final static int MAIN_PANEL_ROWS = 1;
private final static int MAIN_PANEL_COLS = 4;
private final static String EMPTY_ARRAY_MESSAGE = "Hit ADD to add a new Book";
private final static int FRAME_WIDTH = 350;
private final static int FRAME_LENGTH = 300;
private final static int FRAME_XLOC = 250;
private final static int FRAME_YLOC = 100;
//Constructors
//Initialization constructor
// Starts the GUI with a Book array passed by the user, but ensures unique identification numbers
public Inventory6( Book bookIn[] )
{
//Pass the frame title to JFrame and set the IconImage as well
//"Kim's Book Inventory
super( "Kim's Book Inventory" );
//Set the input array equal to the private array variable
book = bookIn;
//Sort the array
Arrays.sort( book );
//Always start the display at the first element of the array
index = 0;
//Build the GUI
buildGUI();
//Give it some values
updateAllTextFields();
}
//Set/Update/Other Methods
//A method for updating each of the GUI fields
private void updateAllTextFields()
{
if ( book.length > 0 ) //The update the TextField display
{
//Update the product name text field
nameText.setText( book[index].getName() );
//Update the product id text field
idText.setText( String.format( "%d", book[index].getIdentificationNumber() ) );
//Update the pages text field
pagesText.setText( String.format( "%d", book[index].getPages() ) );
//Update the units in stock text field
unitsText.setText( String.format( "%d", book[index].getUnitsInStock() ) );
//Update the price text field
priceText.setText( String.format( "$%.2f" , book[index].getUnitPriceInDollars() ));
//Update the stock value text field
valueText.setText( String.format( "$%.2f" , book[index].stockValueInDollars() ));
//Update the restocking fee text field
feeText.setText( String.format( "$%.2f" , book[index].restockingFee() ));
//Update the total value text field
totalText.setText( String.format( "$%.2f" , Product.totalInventoryValue( book ) ));
}//End if
else //Put a special message in the fields
{
//Update the product name text field
nameText.setText( EMPTY_ARRAY_MESSAGE );
//Update the product id text field
idText.setText( EMPTY_ARRAY_MESSAGE );
//Update the pages text field
pagesText.setText( EMPTY_ARRAY_MESSAGE );
//Update the units in stock text field
unitsText.setText( EMPTY_ARRAY_MESSAGE );
//Update the price text field
priceText.setText( EMPTY_ARRAY_MESSAGE );
//Update the stock value text field
valueText.setText( EMPTY_ARRAY_MESSAGE );
//Update the restocking fee text field
feeText.setText( EMPTY_ARRAY_MESSAGE );
//Update the total value text field
totalText.setText( EMPTY_ARRAY_MESSAGE );
}//End else
}//End updateAllTextFields
//Update the display for the calculated fields
private void updateCalculatedFields()
{
//Update the stock value text field
valueText.setText( String.format( "$%.2f" , book[index].stockValueInDollars() ));
//Update the restocking fee text field
feeText.setText( String.format( "$%.2f" , book[index].restockingFee() ));
//Update the total value text field
totalText.setText( String.format( "$%.2f" , Product.totalInventoryValue( book ) ));
}//End updateCalculatedFields
//Set the appropriate fields editable or uneditable
private void setModifiableTextFieldsEnabled( Boolean state )
{
//The Book name, ID, pages, units in stock, and price can all be set editable or uneditable
nameText.setEditable( true );
pagesText.setEditable( true );
unitsText.setEditable( true);
priceText.setEditable( true );
}//End setModifiableTextFieldsEnabled
//Button and Text Handlers and Methods
//Button Handler Class and Handling Methods
//The handler for handling the events for the buttons
private class ButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
if( event.getSource() == firstButton ) //|<<| pressed
{
handleFirstButton();
}//End if
else if( event.getSource() == previousButton ) //|< | pressed
{
handlePreviousButton();
}//End else if
else if( event.getSource() == nextButton ) //| >| pressed
{
handleNextButton();
}//End else if
else if( event.getSource() == lastButton ) //|>>| pressed
{
handleLastButton();
}//End else if
}//End method actionPerformed
}//End class ButtonHandler
//Display the first element of the Book array
private void handleFirstButton()
{
//Set the index to the first element in the array
index = 0;
//Update and disable modification
updateAllTextFields();
setModifiableTextFieldsEnabled( false );
}//End method handleFirstButton
//Display the previous element of the Book array or wrap to the last
private void handlePreviousButton()
{
//Decrement the index
index--;
//If index is less than 0, wrap around to the last element of the array
if ( index < 0 )
{
index = book.length - 1;
}//End if
//Update and disable modification
updateAllTextFields();
setModifiableTextFieldsEnabled( false );
}//End method handlePreviousButton
//Display the next element of the Book array or wrap to the first
private void handleNextButton()
{
//Increment the index
index++;
//If index exceeds the last valid array, wrap around to the first element of the array
if ( index > book.length - 1)
{
index = 0;
}//End if
//Update and disable modification
updateAllTextFields();
setModifiableTextFieldsEnabled( false );
}//End method handleNextButton
//Display the last element of the Book array
private void handleLastButton()
{
//Set the index to the last book in the array
index = book.length - 1;
//Update and disable modification
updateAllTextFields();
setModifiableTextFieldsEnabled( false );
}//End method handleLastButton
//GUI Building Methods
//Build the GUI
private void buildGUI()
{
//Make a grid for the panels
setLayout( new GridLayout( FRAME_GRID_ROWS, FRAME_GRID_COLS ) );
//Add the logo
buildLogo();
//Add the text fields, their labels, and the SEARCH line
buildFields();
//Add the navigation and other buttons
buildMainButtons();
//Set some of the frame properties
setSize( 350, 570 );
setLocation( FRAME_XLOC , FRAME_YLOC );
pack();
setResizable(true);
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
setVisible( true );
}//End buildGUI()
//Add the logo to the JFrame
private void buildLogo()
{
//Create the panel on which to place the logo
logoPanel = new JPanel();
logoPanel.setLayout( new GridLayout( 1, 1 ) );
//Create the logo
logoLabel = new JLabel( new ImageIcon( "book10.gif" ) );
//Add the logo to the panel
logoPanel.add( logoLabel );
//Add the panel to the frame
add( logoPanel );
}//End method buildLogo
//Add the text fields, their labels, and the SEARCH line
private void buildFields()
{
//Create the panel on which to place the labels and text fields
fieldPanel = new JPanel();
fieldPanel.setLayout( new GridLayout( FIELD_PANEL_ROWS, FIELD_PANEL_COLS ) );
//Declare a handler for the buttons
ButtonHandler buttonHandler = new ButtonHandler();
//Create the name label
nameLabel = new JLabel( "Name: " );
nameLabel.setLabelFor( nameText );
fieldPanel.add( nameLabel );
//Create the name text field
nameText = new JTextField( "NONE" );
nameText.setEditable( true );
fieldPanel.add( nameText );
//Create the id label
idLabel = new JLabel( "ID: " );
idLabel.setLabelFor( idText );
fieldPanel.add( idLabel );
//Create the id text field
idText = new JTextField( "0" );
idText.setEditable( true );
fieldPanel.add( idText );
//Create the pages label
pagesLabel = new JLabel( "Pages: " );
pagesLabel.setLabelFor( pagesText );
fieldPanel.add( pagesLabel );
//Create the pages text field
pagesText = new JTextField( "" );
pagesText.setEditable( true );
fieldPanel.add( pagesText );
//Create the units in stock label
unitsLabel = new JLabel( "Units in Stock: " );
unitsLabel.setLabelFor( unitsText );
fieldPanel.add( unitsLabel );
//Create the units in stock text field
unitsText = new JTextField( "" );
unitsText.setEditable( true );
fieldPanel.add( unitsText );
//Create the unit price label
priceLabel = new JLabel( "Unit Price: " );
priceLabel.setLabelFor( priceText );
fieldPanel.add( priceLabel );
//Create the unit price text field
priceText = new JTextField( "" );
priceText.setEditable( true );
fieldPanel.add( priceText );
//Create the stock value label
valueLabel = new JLabel( "Unit Stock Value: " );
valueLabel.setLabelFor( valueText );
fieldPanel.add( valueLabel );
//Create the stock value text field
valueText = new JTextField( "" );
valueText.setEditable( true );
fieldPanel.add( valueText );
//Create the restocking fee label
feeLabel = new JLabel( "Restocking Fee: " );
feeLabel.setLabelFor( feeText );
fieldPanel.add( feeLabel );
//Create the restocking fee text field
feeText = new JTextField( "" );
feeText.setEditable( true );
fieldPanel.add( feeText );
//Add two labels that create a space between the other fields and the total inventory value field
fieldPanel.add( new JLabel( " " ) );
fieldPanel.add( new JLabel( " " ) );
//Create the total inventory value label
totalLabel = new JLabel( "Total Inventory Value: " );
totalLabel.setLabelFor( totalText );
fieldPanel.add( totalLabel );
//Create the total inventory value text field
totalText = new JTextField( "" );
totalText.setEditable( false );
fieldPanel.add( totalText );
//Add two labels that create a space between the total inventory value field and the search line
fieldPanel.add( new JLabel( " " ) );
fieldPanel.add( new JLabel( " " ) );
//Add the panel to the frame
add( fieldPanel );
}//End buildFields
//Add the main buttons to the frame
private void buildMainButtons()
{
//Create the JPanel for the main buttons
mainPanel = new JPanel();
mainPanel.setLayout( new GridLayout( MAIN_PANEL_ROWS, MAIN_PANEL_COLS ) );
//Create the FIRST (<<) button
firstButton = new JButton( "<<" );
firstButton.addActionListener( new ButtonHandler() );
mainPanel.add( firstButton );
//Create the PREVIOUS (<) button
previousButton = new JButton( "< " );
previousButton.addActionListener( new ButtonHandler() );
mainPanel.add( previousButton );
//Create the NEXT (>) button
nextButton = new JButton( ">" );
nextButton.addActionListener( new ButtonHandler() );
mainPanel.add( nextButton );
//Create the LAST (>>) button
lastButton = new JButton( ">>" );
lastButton.addActionListener( new ButtonHandler() );
mainPanel.add( lastButton );
//Add the main button panel to the frame
add( mainPanel );
}//End method buildMainButtons
//Main Method
//FutureValuePanel
//Provide a main method for genepages the GUI
public static void main( String args[] )
{
//Create some sample Books
Book myBook[] = new Book[4];
myBook[0] = new Book("Inkspell", "Funke, Cornellia", 635, 1, 600, 20.00);
myBook[1] = new Book("Thousand Orcs, The", "Salvatore, RA",345, 2, 700, 25.95);
myBook[2] = new Book("Harry Potter and the Half Blood Prince", "Rowling, JK", 652, 3, 800, 29.99);
myBook[3] = new Book("Magyk", "Sage, Angie", 564, 4, 900, 18.89);
Inventory6 gui = new Inventory6( myBook );
}
} //End class Inventory6•
•
•
•
Any help would be greatl appreiciated.
Thank you!
-bigbluesky
![]() |
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Why Output Window disappears? (C++)
- Dr.Python: running same output again (Python)
- dev-c++ Premature Closing (C++)
- help (C++)
- C compiler help (beginner question) (C++)
- Print (C++)
- I need special stuff in my project like system("cls") (C++)
Other Threads in the Java Forum
- Previous Thread: handling multiple files
- Next Thread: How to




Linear Mode