need help withgui with buttons and text input files

I am trying to create a gui with buttons and text files

Page 1 of 1

3 Replies - 916 Views - Last Post: 17 April 2009 - 11:11 AM Rate Topic: -----

#1 Riley1475  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 08-April 09

need help withgui with buttons and text input files

Posted 17 April 2009 - 09:07 AM

I'm trying to create a gui where I can enter information into a memory location

This part of the code compiles and gives me gui when it runs


import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.applet.*;

public class InventoryGui5
   {
	  
   public static void main(String[] args)
	   {
	   // create an instance of ButtonFrame 
		ButtonFrame frame = new ButtonFrame();
			 
	   InventoryGui5 Window = new InventoryGui5();
	 
	   // Ends program when closed
	   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	   //Set the window to be visible
		frame.setVisible(true);
	   // Set frame size
		frame.setSize( 400,400 );
				 
	   } // end main

}  // end class inventoryGui5


class ButtonFrame extends JFrame
{ 
				// create buttons and fields 
				private JButton enterButton;
		private JButton quitButton;
		private JButton showButton;
		private JTextField Inventory1Field;
		private JTextField Inventory2Field;
		private JTextArea InventoryrArea;
	//	private ArrayList<Inventory> InventoryArray = new ArrayList<Inventory>(); 

				// add to JFrame
				 ButtonFrame()
				{
							   
				
			 super( "Book Inventory");

						  
						 // create the panels for the Swing interface window

					 Container con = getContentPane();

			 BoxLayout layout = new BoxLayout(con, BoxLayout.Y_AXIS);
			 con.setLayout(layout);

			JPanel topPanel= new JPanel();
			JPanel bottomPanel= new JPanel();
			con.add(topPanel, BorderLayout.NORTH);
			con.add(bottomPanel, BorderLayout.SOUTH);

			Box lBoxUpperL= new Box(BoxLayout.Y_AXIS);
			Box lBoxUpperR= new Box(BoxLayout.Y_AXIS);
			Box lBoxLowerL= new Box(BoxLayout.Y_AXIS);
			Box lBoxLowerR= new Box(BoxLayout.Y_AXIS);
			
			topPanel.add(lBoxUpperL);
			topPanel.add(lBoxUpperR);
			bottomPanel.add(lBoxLowerL);
			bottomPanel.add(lBoxLowerR); 

				 }  // end constructor 

		 
   } // end class ButtonFrame






I then add ......




	  class TextFieldFrame extends JFrame implements ActionListner
	   {

	   private JTextField textField1; // text field with set size
	   private JTextField textField2; // text field constructed with text

	   private JTextField textField3; // text field with text and size

// TextFieldFrame constructor adds JTextFields to JFrame
public TextFieldFrame()
  {
super ( "Book Inventory" );
setLayout( new FlowLayout() ); // set frame layout

// construct textfield with 10 columns
textField1 = new JTextField( 10 );
add( textField1 ); // add textField1 to JFrame

// construct textfield with default text
textField2 = new JTextField( "Enter text here" );
add( textField2 ); // add textField2 to JFrame

// construct textfield with default text and 21 columns
textField3 = new JTextField( "Uneditable text field", 21 );
textField3.setEditable( false ); // disable editing
add( textField3 ); // add textField3 to JFrame

// register event handlers
 TextFieldHandler handler = new TextFieldHandler();

textField1.addActionListener( handler );
textField2.addActionListener( handler );
textField3.addActionListener( handler );

} // end TextFieldFrame constructor



} // end class textfieldframe 



It does not add the text fields to the gui. Also how do I set the text file to input information into a memory location? I know how to enter information into memory using the scanner utility.

Is This A Good Question/Topic? 0
  • +

Replies To: need help withgui with buttons and text input files

#2 johnmalloy  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 40
  • Joined: 24-September 08

Re: need help withgui with buttons and text input files

Posted 17 April 2009 - 10:41 AM

1. Your text fields were not added to the container

2. Easiest way is to just pass the data to a variable/object


Hope this helps get you back on track, doing great so far.
Was This Post Helpful? 0
  • +
  • -

#3 koki  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 79
  • Joined: 02-January 09

Re: need help withgui with buttons and text input files

Posted 17 April 2009 - 11:02 AM

first of all you have to add your TextField on the container
con.add(textField1, BorderLayout./*what ever*/);



and it is very easy to read a value from textfield and store it in the memory just put it in a variable
String s=textField1.getString();


Was This Post Helpful? 0
  • +
  • -

#4 Riley1475  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 08-April 09

Re: need help withgui with buttons and text input files

Posted 17 April 2009 - 11:11 AM

View Postkoki, on 17 Apr, 2009 - 10:02 AM, said:

first of all you have to add your TextField on the container
con.add(textField1, BorderLayout./*what ever*/);



and it is very easy to read a value from textfield and store it in the memory just put it in a variable
String s=textField1.getString();



Thank you Koki. I will try that

View Postjohnmalloy, on 17 Apr, 2009 - 09:41 AM, said:

1. Your text fields were not added to the container

2. Easiest way is to just pass the data to a variable/object


Hope this helps get you back on track, doing great so far.


Thank you Johnmalloy
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1