Results 1 to 2 of 2
- 07-19-2009, 10:26 AM #1
Member
- Join Date
- Jul 2009
- Posts
- 1
- Rep Power
- 0
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 10:29 AM.
-
Similar Threads
-
Sorting 3 Integers Using If Else
By MSteinman in forum New To JavaReplies: 12Last Post: 02-19-2010, 01:52 PM -
how to get the Integers out of a String
By JordashTalon in forum New To JavaReplies: 10Last Post: 01-30-2009, 07:28 PM -
Finding Median of X Integers
By Hasan in forum New To JavaReplies: 3Last Post: 08-12-2008, 03:06 PM -
Help with Code! Display Array of Strings and Integers - Sorted
By luvjoynt in forum New To JavaReplies: 7Last Post: 04-28-2008, 05:28 AM -
Random Integers
By www.kwalski.com in forum Java AppletsReplies: 8Last Post: 12-09-2007, 06:49 PM
Bookmarks