Results 1 to 2 of 2
  1. #1
    Pez
    Pez is offline Member
    Join Date
    Jul 2009
    Posts
    1
    Rep Power
    0

    Default Finding Strings, booleans and Integers

    Hello,

    I'm new to java (have been teaching myself for around 3 months) and at the moment i am trying to make a GUI using a subclass basically i need to return values to the main class for :
    boolean useFood = false; // needs to be true (in the main class) when the tickbox is selected
    static String foodType; // to be determined by a jtextfield (in the main class)
    int withdrawAmmount // to be determined by a jtextfield (in the main class)

    here is the code i have upto now, i couldnt find action listeners on jigloo but did find an abstract action not sure if thats the same thing for jigloo... any help would be much appreciated. Paul

    here is the code
    Java Code:
    public class GUI extends javax.swing.JFrame {
    	private JButton runButton;
    	private JTextField foodName;
    	private AbstractAction useFoodBoolean;
    	private AbstractAction startAction;
    	private JLabel withdrawLabel;
    	private JTextField jTextField1;
    	private JLabel FoodLabel;
    	private JCheckBox useFood;
    
    	/**
    	* Auto-generated main method to display this JFrame
    	*/
    	public static void main(String[] args) {
    		SwingUtilities.invokeLater(new Runnable() {
    			public void run() {
    				NewJFrame inst = new NewJFrame();
    				inst.setLocationRelativeTo(null);
    				inst.setVisible(true);
    			}
    		});
    	}
    
    	public GUI() {
    		super();
    		initGUI();
    	}
    
    	private void initGUI() {
    		try {
    			GroupLayout thisLayout = new GroupLayout((JComponent)getContentPane());
    			getContentPane().setLayout(thisLayout);
    			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    			{
    				runButton = new JButton();
    				runButton.setText("Start");
    				runButton.setAction(getStartAction());
    			}
    			{
    				foodName = new JTextField();
    			}
    			{
    				useFood = new JCheckBox();
    				useFood.setText("Use Food?");
    				useFood.setAction(getUseFoodBoolean());
    			}
    			{
    				FoodLabel = new JLabel();
    				FoodLabel.setText("Food Name");
    			}
    			{
    				jTextField1 = new JTextField();
    			}
    			{
    				withdrawLabel = new JLabel();
    				withdrawLabel.setText("withdraw X ?");
    			}
    			thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
    				.add(0, 8, Short.MAX_VALUE)
    				.add(useFood, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)
    				.addPreferredGap(LayoutStyle.RELATED)
    				.add(withdrawLabel, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)
    				.addPreferredGap(LayoutStyle.RELATED)
    				.add(jTextField1, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
    				.addPreferredGap(LayoutStyle.RELATED)
    				.add(FoodLabel, GroupLayout.PREFERRED_SIZE, 11, GroupLayout.PREFERRED_SIZE)
    				.addPreferredGap(LayoutStyle.RELATED)
    				.add(foodName, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
    				.addPreferredGap(LayoutStyle.RELATED)
    				.add(runButton, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
    				.addContainerGap());
    			thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
    				.addContainerGap(47, 47)
    				.add(thisLayout.createParallelGroup()
    				    .add(GroupLayout.LEADING, useFood, 0, 156, Short.MAX_VALUE)
    				    .add(GroupLayout.LEADING, runButton, 0, 156, Short.MAX_VALUE)
    				    .add(thisLayout.createSequentialGroup()
    				        .add(35)
    				        .add(thisLayout.createParallelGroup()
    				            .add(GroupLayout.LEADING, thisLayout.createSequentialGroup()
    				                .add(jTextField1, GroupLayout.PREFERRED_SIZE, 85, GroupLayout.PREFERRED_SIZE)
    				                .add(0, 11, Short.MAX_VALUE))
    				            .add(GroupLayout.LEADING, thisLayout.createSequentialGroup()
    				                .add(foodName, 0, 85, Short.MAX_VALUE)
    				                .add(11))
    				            .add(thisLayout.createSequentialGroup()
    				                .addPreferredGap(jTextField1, withdrawLabel, LayoutStyle.INDENT)
    				                .add(thisLayout.createParallelGroup()
    				                    .add(GroupLayout.LEADING, thisLayout.createSequentialGroup()
    				                        .add(withdrawLabel, 0, 87, Short.MAX_VALUE)
    				                        .addPreferredGap(LayoutStyle.RELATED))
    				                    .add(GroupLayout.LEADING, FoodLabel, 0, 90, Short.MAX_VALUE))))
    				        .add(25)))
    				.addContainerGap(34, 34));
    			thisLayout.linkSize(new Component[] {foodName, jTextField1}, GroupLayout.VERTICAL);
    			thisLayout.linkSize(new Component[] {foodName, jTextField1}, GroupLayout.HORIZONTAL);
    			pack();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	private AbstractAction getStartAction() {
    		if(startAction == null) {
    			startAction = new AbstractAction("Start", null) {
    				public void actionPerformed(ActionEvent evt) {
    					//close and intitialise booleans + ints
    				}
    			};
    		}
    		return startAction;
    	}
    
    	private AbstractAction getUseFoodBoolean() {
    		if(useFoodBoolean == null) {
    			useFoodBoolean = new AbstractAction("Use Food?", null) {
    				public void actionPerformed(ActionEvent evt) {
    				}
    			};
    		}
    		return useFoodBoolean;
    	}
    Last edited by Pez; 07-19-2009 at 09:29 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Your class is called GUI yet your main shows you trying to display a different class, NewJFrame. Could this be causing you vexation?

Similar Threads

  1. Sorting 3 Integers Using If Else
    By MSteinman in forum New To Java
    Replies: 12
    Last Post: 02-19-2010, 12:52 PM
  2. how to get the Integers out of a String
    By JordashTalon in forum New To Java
    Replies: 10
    Last Post: 01-30-2009, 06:28 PM
  3. Finding Median of X Integers
    By Hasan in forum New To Java
    Replies: 3
    Last Post: 08-12-2008, 02:06 PM
  4. Replies: 7
    Last Post: 04-28-2008, 04:28 AM
  5. Random Integers
    By www.kwalski.com in forum Java Applets
    Replies: 8
    Last Post: 12-09-2007, 05:49 PM

Posting Permissions

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