OK, this is for a class, however I'm not asking for the answer to the logic of the program just some help with the layout of the GUI.
What I'm trying to do is set up a form with a label at the top
below that will be a label with a textbox next to it and
below that will be another label and textbox.
I have played around with this for several days but with no luck.
Here is the code I have, if someone could point me in the right direction.
ThanksCode:import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.text.NumberFormat; import java.util.Locale; import javax.swing.JOptionPane; public class w2iaJ2{ public static void main (String[] args){ myFrame mcFrame = new myFrame(); mcFrame.setLocation(30,30); mcFrame.setBounds(10,50,500,700); mcFrame.setVisible(true); mcFrame.setLayout(new GridLayout(7,1,10,10)); } } class myFrame extends JFrame{ panels topPanel; panels spcPanel; panels principalPanel; panels interestPanel; panels timePanel; panels ansPanel; txtPanel ptp; txtPanel itp; txtPanel ttp; JTextField txtP; JTextField txtI; JTextField txtT; myFrame(){ topPanel = new panels("Welcome to the Amortization Calculator"); add(topPanel,0); principalPanel = new panels("Enter principal amount:"); txtP = new JTextField(10); ptp = new txtPanel(txtP); principalPanel.add(ptp); add(principalPanel,1); interestPanel = new panels("Enter interest rate:"); txtI = new JTextField(10); itp = new txtPanel(txtI); interestPanel.add(itp); // interestPanel.setBounds(10,50,780,10); add(interestPanel,2); } } class txtPanel extends JPanel{ txtPanel(JTextField tf){ setLocation(350,10); setVisible(true); add(tf); } } class panels extends JPanel{ JLabel panelLabel; panels(String lbl){ panelLabel = new JLabel(lbl); setBounds(10,10,480,10); add(panelLabel); } }
RT




Reply With Quote