Results 1 to 5 of 5
  1. #1
    cherylminor85 is offline Member
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Default Transferring information from one JFrame to Another JFrame

    I am writing some code where I have designed a warehouse inventory system. Within this system there is a place where you can select to reorder items that need to be added to inventory. I have set up a JFrame where you can enter what all you need to reorder and then I want to be able to hit the Fill Order button at the bottom and this same information that you entered into the desire text fields displays on another JFrame... I have included my code from where you enter the information to where I want it displayed as well as my main which is in a completely different class as well...
    I have no idea where to start in creating this information...

    This is the place where you enter what you want to reorder
    Java Code:
    /**
     * @(#)ReorderItem.java
     *
     *
     * @author 
     * @version 1.00 2012/5/23
     */
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    
    public class ReorderItem extends JPanel{
    
    	JButton placeOrder, exitSystem, accountingDepartment, inventoryDepartment;
    	
        public ReorderItem() 
        {
        	//main panel to put on frame
        	JPanel main = new JPanel();
        	main.setLayout(new BorderLayout());
        	main.setBackground(new Color(46, 139, 87));
        	main.setPreferredSize(new Dimension(600, 590));
        	add(main);
        	
        	//panel to hold title
        	JPanel title = new JPanel();
        	title.setBackground(new Color(46, 139, 87));
        	title.setPreferredSize(new Dimension(150, 150));
        	main.add(title, BorderLayout.NORTH);
        	
        	//title of page
        	Font font2 = new Font("Courier New", Font.PLAIN, 30);
        	JLabel titleName = new JLabel("<html>Enter the information <br> about the item: </html>");
        	titleName.setForeground(new Color(240, 250, 240));
        	titleName.setFont(font2);
        	title.add(titleName);
        	
        	//panel to hold buttons
        	JPanel buttons = new JPanel();
        	buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
        	buttons.setBackground(new Color(46, 139, 87));
        	buttons.setPreferredSize(new Dimension(150,150));
        	main.add(buttons, BorderLayout.SOUTH);
        	
        	//panel to hold entry fields
        	JPanel fields = new JPanel();
        	fields.setLayout(new BoxLayout(fields, BoxLayout.Y_AXIS));
        	fields.setBackground(new Color(46, 139, 87));
        	fields.setPreferredSize(new Dimension(300,300));
        	main.add(fields);
        	
        	//panel to center field panel
        	JPanel east = new JPanel();
        	east.setBackground(new Color(46, 139, 87));
        	east.setPreferredSize(new Dimension(100,100));
        	main.add(east, BorderLayout.EAST);
        	
        	//panel to center field panel
        	JPanel west = new JPanel();
        	west.setBackground(new Color(46, 139, 87));
        	west.setPreferredSize(new Dimension(100,100));
        	main.add(west, BorderLayout.WEST);
        	
        	//label for field entries
        	Font font = new Font("Courier New", Font.PLAIN, 20);
        	JLabel category = new JLabel("Category: ");
        	category.setForeground(new Color(240, 250, 240));
        	category.setFont(font);
        	JLabel name = new JLabel("Name of Item: ");
        	name.setFont(font);
        	name.setForeground(new Color(240, 250, 240));
        	JLabel serial = new JLabel("Serial Number: ");
        	serial.setFont(font);
        	serial.setForeground(new Color(240, 250, 240));
        	JLabel amount = new JLabel("Amount of Item: ");
        	amount.setFont(font);
        	amount.setForeground(new Color(240, 250, 240));
        	JLabel price = new JLabel("Price of Item: ");
        	price.setFont(font);
        	price.setForeground(new Color(240, 250, 240));
        	
        	//text fields for field entries
        	JTextField categoryText = new JTextField(10);
        	JTextField nameText = new JTextField(10);
        	JTextField serialText = new JTextField(10);
        	JTextField amountText = new JTextField(10);
        	JTextField priceText = new JTextField(10);
        	
        	//adding fields to the field panel
        	fields.add(category);
        	fields.add(categoryText);
        	fields.add(Box.createVerticalStrut(10));
        	fields.add(name);
        	fields.add(nameText);
        	fields.add(Box.createVerticalStrut(10));
        	fields.add(serial);
        	fields.add(serialText);
        	fields.add(Box.createVerticalStrut(10));
        	fields.add(amount);
        	fields.add(amountText);
        	fields.add(Box.createVerticalStrut(10));
        	fields.add(price);
        	fields.add(priceText);
        	fields.add(Box.createVerticalStrut(10));
        	
        	//buttons for navigation
        	placeOrder = new JButton("Place Order");
        	placeOrder.setBackground(new Color(240, 250, 240));
        	placeOrder.setForeground(new Color(46, 139, 87));
        	exitSystem = new JButton("Exit System");
        	exitSystem.setBackground(new Color(240, 250, 240));
        	exitSystem.setForeground(new Color(46, 139, 87));
        	accountingDepartment = new JButton("Accounting Department");
        	accountingDepartment.setBackground(new Color(240, 250, 240));
        	accountingDepartment.setForeground(new Color(46, 139, 87));
        	inventoryDepartment = new JButton("Inventory Department");
        	inventoryDepartment.setBackground(new Color(240, 250, 240));
        	inventoryDepartment.setForeground(new Color(46, 139, 87));
        	
        	//adding buttons to button panel
        	buttons.add(Box.createHorizontalStrut(35));
        	buttons.add(placeOrder);
        	buttons.add(Box.createHorizontalStrut(5));
        	buttons.add(exitSystem);
        	buttons.add(Box.createHorizontalStrut(5));
        	buttons.add(accountingDepartment);
        	buttons.add(Box.createHorizontalStrut(5));
        	buttons.add(inventoryDepartment);
        	buttons.add(Box.createHorizontalStrut(5));
        	
        	//action listeners for buttons
        	placeOrder.addActionListener(new ButtonListener());
        	exitSystem.addActionListener(new ButtonListener());
        	accountingDepartment.addActionListener(new ButtonListener());
        	inventoryDepartment.addActionListener(new ButtonListener());
        	
        	
        }
      
      //action performance for buttons  
      public class ButtonListener implements ActionListener
      {
      	public void actionPerformed(ActionEvent event)
      	{
      		
      		if(event.getSource() == placeOrder)
      		{
      			//actual placing of order
      			JFrame frame1 = new JFrame("Order Placed");
      			frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      			frame1.getContentPane().add(new FulfilledOrder());
      			frame1.pack();
      			frame1.setVisible(true);
      			frame1.setSize(600,600);
      		}
      		if(event.getSource() == exitSystem)
      		{
      			//exit out of entire system
      			System.exit(0);
      		}
      		if(event.getSource() == accountingDepartment)
      		{
      			//creating the new frame for the accounting department page
        		JFrame frame3 = new JFrame("Accounting Department");
        		frame3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        		frame3.getContentPane().add(new AccountingDepartment());
        		frame3.pack();
        		frame3.setVisible(true);
        		frame3.setBackground(new Color(46, 139, 87));
      		}
      		if(event.getSource() == inventoryDepartment)
      		{
      			
    			//creating the new frame for the inventory department page
        		JFrame frame2 = new JFrame("Inventory Department");
       			frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       			frame2.getContentPane().add(new InventoryDepartment());
       			frame2.pack();
       			frame2.setVisible(true);
       			frame2.setBackground(new Color(46, 139, 87));
      		}
      	}
      }  
    }

    This displays what you placed in those fields

    Java Code:
    /**
     * @(#)FulfilledOrder.java
     *
     *
     * @author 
     * @version 1.00 2012/5/23
     */
     import javax.swing.event.*;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.border.*;
    
    public class FulfilledOrder extends JPanel{
    
    	JButton exitSystem, inventoryDepartment, accountingDepartment;
    	
        public FulfilledOrder() 
        {
        	JPanel main = new JPanel();
        	main.setLayout(new BorderLayout());
        	main.setPreferredSize(new Dimension(600,590));
        	main.setBackground(new Color(46, 139, 87));
        	add(main);
        	
        	JPanel title = new JPanel();
        	title.setPreferredSize(new Dimension(200,200));
        	title.setBackground(new Color(46, 139, 87));
        	main.add(title, BorderLayout.NORTH);
        	
        	Font font = new Font("Courier New", Font.PLAIN, 30);
        	JLabel titleName = new JLabel("<html> Your order has been placed. <br><br> Fulfilled Order: </html>");
        	titleName.setFont(font);
        	titleName.setForeground(new Color(240, 250, 240));
        	title.add(titleName);
        	
        	JPanel buttons = new JPanel();
        	buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
        	buttons.setBackground(new Color(46, 139, 87));
        	buttons.setPreferredSize(new Dimension(100,100));
        	main.add(buttons, BorderLayout.SOUTH);
        	
        	JPanel fields = new JPanel();
        	fields.setLayout(new BoxLayout(fields, BoxLayout.Y_AXIS));
        	fields.setPreferredSize(new Dimension(300,300));
        	fields.setBackground(new Color(46, 139, 87));
        	main.add(fields, BorderLayout.CENTER);
        	
        	Font font3 = new Font("Courier New", Font.PLAIN, 20);
        	JLabel category = new JLabel("             Category:");
        	category.setFont(font3);
        	category.setForeground(new Color(240, 250, 240));
        	JLabel name = new JLabel("         Name of Item:");
        	name.setFont(font3);
        	name.setForeground(new Color(240, 250, 240));
        	JLabel serial = new JLabel("Serial Number of Item:");
        	serial.setFont(font3);
        	serial.setForeground(new Color(240, 250, 240));
        	JLabel amount = new JLabel("       Amount of Item:");
        	amount.setFont(font3);
        	amount.setForeground(new Color(240, 250, 240));
        	JLabel price = new JLabel("        Price of Item:");
        	price.setFont(font3);
        	price.setForeground(new Color(240, 250, 240));
        	
        	fields.add(category);
        	fields.add(Box.createVerticalStrut(10));
        	fields.add(name);
        	fields.add(Box.createVerticalStrut(10));
        	fields.add(serial);
        	fields.add(Box.createVerticalStrut(10));
        	fields.add(amount);
        	fields.add(Box.createVerticalStrut(10));
        	fields.add(price);
        	fields.add(Box.createVerticalStrut(10));
        	
        	JPanel east = new JPanel();
        	east.setBackground(new Color(46, 139, 87));
        	east.setPreferredSize(new Dimension(100,100));
        	main.add(east, BorderLayout.EAST);
        	
        	JPanel west = new JPanel();
        	west.setBackground(new Color(46, 139, 87));
        	west.setPreferredSize(new Dimension(20,20));
        	main.add(west, BorderLayout.WEST);
        	
        	//buttons for navigating
        	Font font2 = new Font("Courier New", Font.PLAIN, 15);
        	exitSystem = new JButton("Exit System");
        	exitSystem.setBackground(new Color(240, 250, 240));
        	exitSystem.setForeground(new Color(46, 139, 87));
        	exitSystem.setFont(font2);
        	inventoryDepartment = new JButton("Inventory Department");
        	inventoryDepartment.setBackground(new Color(240, 250, 240));
        	inventoryDepartment.setForeground(new Color(46, 139, 87));
        	inventoryDepartment.setFont(font2);
        	accountingDepartment = new JButton("Accounting Department");
        	accountingDepartment.setBackground(new Color(240, 250, 240));
        	accountingDepartment.setForeground(new Color(46, 139, 87));
        	accountingDepartment.setFont(font2);
        	
        	//adding buttons to button panel
        	buttons.add(Box.createHorizontalStrut(10));
        	buttons.add(exitSystem);
        	buttons.add(Box.createHorizontalStrut(5));
        	buttons.add(accountingDepartment);
        	buttons.add(Box.createHorizontalStrut(5));
        	buttons.add(inventoryDepartment);
        	buttons.add(Box.createHorizontalStrut(5));
        	
        	//action listeners for buttons
        	exitSystem.addActionListener(new ButtonListener());
        	accountingDepartment.addActionListener(new ButtonListener());
        	inventoryDepartment.addActionListener(new ButtonListener());
        	
        	
        }
        
        public class ButtonListener implements ActionListener
        {
        	public void actionPerformed(ActionEvent event)
        	{
        		if(event.getSource() == exitSystem)
        		{
        			//exit out of the system
        			System.exit(0);
        		}
        		if(event.getSource() == accountingDepartment)
        		{
        			//creating the new frame for the accounting department page
        				JFrame frame3 = new JFrame("Accounting Department");
        				frame3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        				frame3.getContentPane().add(new AccountingDepartment());
        				frame3.pack();
        				frame3.setVisible(true);
        				frame3.setBackground(new Color(46, 139, 87));
        		}
        		if(event.getSource() == inventoryDepartment)
        		{
        			//creating the new frame for the inventory department page
        				JFrame frame2 = new JFrame("Inventory Department");
        				frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        				frame2.getContentPane().add(new InventoryDepartment());
        				frame2.pack();
        				frame2.setVisible(true);
        				frame2.setBackground(new Color(46, 139, 87));
        		}
        	}
        }
        
    }

    This is my main that I run to display my project
    Java Code:
    /**
     * Project: Warehouse Inventory System
     * Name: Cheryl Minor
     * Date: May 2, 2012
     *
     * Rewriting the Warehouse Inventory System that I created in Visual Basic
     */
     
    import javax.swing.*;
    
    
    public class WarehouseInventorySystem {
            
       
           public static void main(String[] args) {
            //Displaying the main page GUI
            JFrame frame = new JFrame ("Main Page");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(new MainFramePanel());
    		frame.pack();
    		frame.setVisible(true);
        }
        
        
    }

  2. #2
    aussiemcgr is offline Member
    Join Date
    May 2012
    Posts
    5
    Rep Power
    0

    Default Re: Transferring information from one JFrame to Another JFrame

    A quick second of stylistic advice: users generally dislike having a handful of windows to deal with (scares them, or they get lost, or something, not sure why). I usually try to keep as much on one window as possible by using JTabbedPane and/or CardLayout.

    But getting back to your issue, none of the fields in FulfilledOrder Object are accessible from the outside. That is a big problem, since you need to pass values to your GUI objects. I would suggest creating a handful of setters in your FulfilledOrder class that accepts values and sends them to the GUI objects. But, you don't appear to have any items that allow dynamic text. I'm noticing you are using the Box class for what I suspect you want to be text related components. To my knowledge, Box cannot accept text. I would suggest using JTextField, and if you want to stop the user from making changes to the values, you can use the setEditable(false) method.

    Out of curiousity, is there a particular reason you are using the Box class?

  3. #3
    cherylminor85 is offline Member
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Default Re: Transferring information from one JFrame to Another JFrame

    Quote Originally Posted by aussiemcgr View Post
    A quick second of stylistic advice: users generally dislike having a handful of windows to deal with (scares them, or they get lost, or something, not sure why). I usually try to keep as much on one window as possible by using JTabbedPane and/or CardLayout.

    But getting back to your issue, none of the fields in FulfilledOrder Object are accessible from the outside. That is a big problem, since you need to pass values to your GUI objects. I would suggest creating a handful of setters in your FulfilledOrder class that accepts values and sends them to the GUI objects. But, you don't appear to have any items that allow dynamic text. I'm noticing you are using the Box class for what I suspect you want to be text related components. To my knowledge, Box cannot accept text. I would suggest using JTextField, and if you want to stop the user from making changes to the values, you can use the setEditable(false) method.

    Out of curiousity, is there a particular reason you are using the Box class?
    I opted to use the box class because I wanted the items I listed to stand on top of each other and after working with Java I realized that the way most people seemed to get things to stack in the Y_AXIS direction is by using the BoxLayout... I get that it is usually better to use Tabs and I think after I get most of my stuff done I might go back and switch a lot of it to tabs... right now, this is a project I am doing just because I like programming and have nothing else to do.. I created this project in visual basic and am now transferring it to Java... just something I am doing to pass time.

  4. #4
    aussiemcgr is offline Member
    Join Date
    May 2012
    Posts
    5
    Rep Power
    0

    Default Re: Transferring information from one JFrame to Another JFrame

    Well I think the Box class is used more for formatting (creating invisible components) than actual GUI objects. If you want to display dynamic text of some sorts, you should use something that extends JTextComponent.

    The good news if you want to use tabs later on is that your classes extend JPanel instead of JFrame. That will at least make the transition MUCH easier (since you send JTabbedPanes JPanels).

    Personally, I've created my own Layout Manager, of sorts, because the standard Java Layout Managers suck. The only really powerful Layout Manager is SpringLayout, and that is a nightmare to work with if you are a human. If you aren't making something you plan on selling, I'll give you a copy of my Layout Manager to use. It extends SpringLayout (because it's easier to extend SpringLayout than use it) and lets you add components using coordinates, centered, or as a form (by sending it a 2 dimensional array of components in the way you want it the Layout Manager to lay them). It's all Javadoc'ed, so if you use an IDE like Eclipse or Netbeans, you'll get all the same suggestions and information that you would get with any other Layout Manager.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Transferring information from one JFrame to Another JFrame

    Quote Originally Posted by aussiemcgr View Post
    Well I think the Box class is used more for formatting (creating invisible components) than actual GUI objects.
    Too much trouble to read the API and actually discover what it is or isn't?

    Quote Originally Posted by aussiemcgr View Post
    ... the standard Java Layout Managers suck.
    A bad carpenter, etc. etc.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 3
    Last Post: 11-27-2011, 06:18 AM
  2. Sharing information between tabbed jframe?
    By iminhell in forum New To Java
    Replies: 6
    Last Post: 10-31-2010, 11:00 PM
  3. Replies: 5
    Last Post: 06-14-2010, 07:10 PM
  4. Passing data from one JFrame to another JFrame
    By tarami in forum New To Java
    Replies: 3
    Last Post: 08-06-2009, 06:44 PM
  5. Replies: 4
    Last Post: 04-23-2009, 12:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •