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
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;
}