Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-05-2008, 08:35 PM
Member
 
Join Date: May 2008
Posts: 29
adeeb is on a distinguished road
Regarding Text Field
Hi,
I have added two text fields and a button on a panel which is set with cardlayout now i want to store characters in two different strings.
And when i enter the text in the fields and click the button i should move to second card.
Only i need is getting the data from the text fields and comparing it.
The rest i can handle.
So please some one help
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-06-2008, 12:01 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,146
hardwired is on a distinguished road
For more on these kind of things see Trail: Creating a GUI with JFC/Swing.
Code:
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class GettingText implements ActionListener { JTextField hi = new JTextField(12); JTextField lo = new JTextField(12); JPanel panel; public void actionPerformed(ActionEvent e) { String hiText = hi.getText(); String loText = lo.getText(); boolean equal = hiText.equals(loText); int compare = hiText.compareTo(loText); // see String api System.out.printf("hiText = %s loText = %s " + "equal = %b compare = %d%n", hiText, loText, equal, compare); CardLayout cards = (CardLayout)panel.getLayout(); cards.next(panel); // or // cards.show(panel, "blue"); } private JPanel getContent() { CardLayout cards = new CardLayout(); panel = new JPanel(cards); panel.add("data", getComponentPanel()); panel.add("blue", getBluePanel()); return panel; } private JPanel getComponentPanel() { JButton button = new JButton("jump"); button.addActionListener(this); // Optionally, you can also add the ActionListener // to the two textFields which will generate an // ActionEvent when you press the enter/return key. hi.addActionListener(this); lo.addActionListener(this); JPanel panel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(5,0,5,0); gbc.weighty = 1.0; gbc.gridwidth = GridBagConstraints.REMAINDER; panel.add(hi, gbc); panel.add(lo, gbc); panel.add(button, gbc); return panel; } private JPanel getBluePanel() { JPanel panel = new JPanel(); panel.setBackground(Color.blue); return panel; } public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new GettingText().getContent()); f.setSize(400,400); f.setLocationRelativeTo(null); f.setVisible(true); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
get numeric value from a text field Lehane_9 New To Java 2 06-14-2008 04:19 AM
Unsupported Content-Type: text/html Supported ones are: [text/xml] luislopezco Advanced Java 0 05-26-2008 05:26 PM
[SOLVED] How to check what type of value entered in text field Renegade85 New To Java 2 04-28-2008 11:26 AM
Waste Space & Text Field Gajesh Tripathi AWT / Swing 2 12-01-2007 08:44 AM
Final field question derrickD Advanced Java 1 04-28-2007 11:37 PM


All times are GMT +3. The time now is 07:56 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org