Results 1 to 3 of 3
Thread: How to pass values from frames..
- 05-06-2011, 08:54 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 18
- Rep Power
- 0
-
You're learning how to code Swing, so it's probably a mistake for you to let NetBeans create your GUI code for you. I suggest you do it by hand at this stage and then later when you know how Swing works, sure, let NetBeans create some code for you.
This should probably be clarified. The more effort you put into helping us understand your problem the easier we'll be able to help you.I was wondering how could i pass the value of a string to the next frame?
More will look at your code if you post the actual code itself in the forum (with code tags -- please see my link about this below) rather than as an attachment. Another problem with NetBeans is that the code it produces is quite bloated, making it hard for others to read your code -- another reason to code by hand.I have attached my code so that you can view my files... Thank you very much!
Much luck!
-
OK, I'll be more direct and see if that will help get a response: what information are you trying to pass from one GUI to another?
and as a non-NetBeans GUI example:
Java Code:import java.awt.Window; import java.awt.Dialog.ModalityType; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class JavaAtmBrief { private static void createAndShowUI() { JFrame frame = new JFrame("ATM"); frame.getContentPane().add(new AtmPanel()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } public static void main(String[] args) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { createAndShowUI(); } }); } } class AtmPanel extends JPanel { private JTextField acctNumberField = new JTextField(10); private JButton okBtn = new JButton("OK"); public AtmPanel() { okBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { okBtnActionPerformed(); } }); add(acctNumberField); add(okBtn); } private void okBtnActionPerformed() { DialogPanel dialogPanel = new DialogPanel(acctNumberField.getText()); Window win = SwingUtilities.getWindowAncestor(this); JDialog dialog = new JDialog(win, "Dialog", ModalityType.APPLICATION_MODAL); dialog.getContentPane().add(dialogPanel); dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setVisible(true); } } class DialogPanel extends JPanel { private String acctNumber; // gui's constructor accepts a String public DialogPanel(String acctNumber) { this.acctNumber = acctNumber; // that initializes a field add(new JLabel("Account Number: " + acctNumber)); // and is displayed add(new JButton(new AbstractAction("Close") { @Override public void actionPerformed(ActionEvent e) { Window win = SwingUtilities.getWindowAncestor(DialogPanel.this); win.dispose(); } })); } }Last edited by Fubarable; 05-06-2011 at 09:32 PM.
Similar Threads
-
how to pass values from jsp to servlet
By jksathya in forum EclipseReplies: 1Last Post: 02-01-2011, 09:13 AM -
need to input values from a text file into an array and count values
By pds8475 in forum New To JavaReplies: 14Last Post: 01-22-2011, 02:36 PM -
Pass Values into 2D Array?
By noble in forum New To JavaReplies: 7Last Post: 11-09-2010, 07:30 AM -
Retaining DB values as well as Dynamically generated Values.. Help Needed !
By rajivjha in forum Advanced JavaReplies: 0Last Post: 05-22-2008, 10:53 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks