Hi,

I've just started learning Java, and after a few chapters of theory, I decided to try a bit of GUI to see if it helped drive the theory home. I think it's working a bit, but I've got a problem that I"m sure demonstrates a pretty fundamental part of Java prgramming.

The source below is from a GUI doc that I've been doing, using FlowLayout manager. For some reason, all the panels that I've created are controlled by the layout manager of the last panel, and have no individual control. As far as I"m aware, every panel is a new object with a new FlowLayout manager, so each should be individually controllable, but it isn't working. I'd really appreciate any help - and please don't laugh - it's only a play thing to try to teach me some of the basics...

Source:

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

public class CurrencyConverter extends JFrame {

FlowLayout primaryFlow = new FlowLayout(FlowLayout.CENTER);


String[] currency = {"Convert From:", " ", "UK Pounds", "US Dollars", "French Francs", "Spanish Pesetas", "German Marks",
"Welsh Sheep", "Arabian Camels", "Essex Virgins* "};

String[] reverseCurrency = {"Convert To:", " ", "Essex Virgins* ", "Arabian Camels","Welsh Sheep",
"German Marks", "Spanish Pesetas", "French Francs", "US Dollars", "UK Pounds" };


public CurrencyConverter() {
super("Currency Converter");
setSize(550, 600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);



//declare all new panels
JPanel topList = new JPanel();
JPanel selectCurrencyFrom = new JPanel();
JPanel selectCurrencyTo = new JPanel();
JPanel availability = new JPanel();
JPanel exchangeDetails = new JPanel();
JPanel changeAmount = new JPanel();
JPanel actionButtons = new JPanel();
JPanel result = new JPanel();
JPanel checkBox = new JPanel();
//declare all new lists
JList convertFrom = new JList(currency);
JList convertTo = new JList(reverseCurrency);
//declare all new text fields
JTextField exchangeRate = new JTextField(8);
JTextField amountToChange = new JTextField(8);
JTextField conversionResult = new JTextField(8);
//declare all new labels
JLabel select = new JLabel("Please select the currency to convert FROM and TO in the boxes below:");
JLabel subjectToAvailability = new JLabel("* Subject to Availability - first come first served.");
JLabel rate = new JLabel("Enter Current Exchange Rate (2 Decimal Places):");
JLabel enterAmount = new JLabel("Enter the Amount of Money You Want to Change: ");
JLabel conversionSum = new JLabel("The Conversion Result is: ");
//declare all new buttons and check boxes
JButton calculate = new JButton("Calculate");
JButton cancel = new JButton("Cancel");
JCheckBox please = new JCheckBox("Oh yes please - inundate me with useless information!", true);
//add new flow layouts
FlowLayout topListFlow = new FlowLayout(FlowLayout.CENTER, 10, 10);
FlowLayout currencyFromFlow = new FlowLayout(FlowLayout.CENTER, 10, 10);
FlowLayout toListFlow = new FlowLayout(FlowLayout.CENTER, 100, 10);
FlowLayout subjectToAvailabilityFlow = new FlowLayout(FlowLayout.CENTER, 100, 10);
FlowLayout exchangeRateFlow = new FlowLayout(FlowLayout.RIGHT, 100, 10);
FlowLayout amountFlow = new FlowLayout(FlowLayout.CENTER, 100, 10);
FlowLayout buttonFlow = new FlowLayout(FlowLayout.LEFT, 10, 10);
FlowLayout answerFlow = new FlowLayout(FlowLayout.CENTER, 100, 10);
FlowLayout pleaseFlow = new FlowLayout(FlowLayout.CENTER, 100, 10);



//create topList
topList.add(select);
getContentPane().add(topList);
getContentPane().setLayout(topListFlow);
setVisible(true);

//create select currency From list
getContentPane().setLayout(currencyFromFlow);
convertFrom.setVisibleRowCount(7);
JScrollPane scroller1 = new JScrollPane(convertFrom);
selectCurrencyFrom.add(scroller1);
getContentPane().add(selectCurrencyFrom);
setVisible(true);

//create select currency To list
getContentPane().setLayout(toListFlow);
convertTo.setVisibleRowCount(7);
JScrollPane scroller2 = new JScrollPane(convertTo);
selectCurrencyTo.add(scroller2);
getContentPane().add(selectCurrencyTo);
setVisible(true);

//create subjectToAvailability
getContentPane().setLayout(subjectToAvailabilityFlow);
availability.add(subjectToAvailability);
getContentPane().add(availability);
setVisible(true);


//add current exchange rate panel
getContentPane().setLayout(exchangeRateFlow);
exchangeDetails.add(rate);
exchangeDetails.add(exchangeRate);
getContentPane().add(exchangeDetails);
setVisible(true);

//add amount field
getContentPane().setLayout(amountFlow);
changeAmount.add(enterAmount);
changeAmount.add(amountToChange);
getContentPane().add(changeAmount);
setVisible(true);

//add calculate and cancel buttons
actionButtons.add(calculate);
actionButtons.add(cancel);
getContentPane().add(actionButtons);
getContentPane().setLayout(buttonFlow);
setVisible(true);

//add answer field
getContentPane().setLayout(answerFlow);
result.add(conversionSum);
result.add(conversionResult);
getContentPane().add(result);
setVisible(true);

//add inundate me with junk panel
getContentPane().setLayout(pleaseFlow);
checkBox.add(please);
getContentPane().add(please);
setVisible(true);

}

public static void main(String[] args) {
CurrencyConverter app = new CurrencyConverter();
}
}



Sorry if that's silly amounts of code, but I figured it was all likely to be useful.