Results 1 to 7 of 7
Thread: Inputting some text in a GUI.
- 04-14-2010, 11:21 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 59
- Rep Power
- 0
Inputting some text in a GUI.
Hello. I am new to Java and am finding it difficult to grasp the GUI aspect.
What I want to do is to have some kind of input box where the user enters some text and then presses a button which processes the text (using a class that I have developed).
I don't have a clue as to how I should go about creating this input box. i would be very grateful if someone could give some suggestions as to the best way to create this input box?
Many thanks
-
JOptionPane comes to mind, but what you really must do is to study the Swing tutorials: Swing Tutorials
Much luck!
- 04-14-2010, 11:52 PM #3
Senior Member
- Join Date
- Apr 2010
- Location
- Belgrade, Serbia
- Posts
- 278
- Rep Power
- 4
i wrote some code. I think that is what you are looking for.
Java Code:import javax.swing.JTextArea; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JFrame; import javax.swing.SwingUtilities; public class CreateInputBoxExample { MyPanel panel = new MyPanel(); JFrame frame = new JFrame("my frame"); public void createAndShowGUI() { frame.add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300,300); frame.setLocation(100,100); frame.setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { CreateInputBoxExample createInputBox = new CreateInputBoxExample(); createInputBox.createAndShowGUI(); } }); } } class MyPanel extends JPanel { MyPanel() { JTextArea textArea = new JTextArea(numberOfColumns, numberOfRows); JButton processButton = new JButton("process the text"); add(textArea); add(processButton); } public static final int numberOfColumns = 10; public static final int numberOfRows = 20; }
- 04-15-2010, 01:35 AM #4
Member
- Join Date
- Apr 2010
- Posts
- 59
- Rep Power
- 0
Thank you very much for both of your replies. I really appreciated the time and quality of both posts.
I have spent sometime using the JOptionPane which works very nicely and the coding is simple.
I have also copied and pasted the coding from the last post which perhaps produces a more impressive text box as well as demonstrates using more complicated coding. However, I would be grateful if someone could tell me what variable (field) the text that has been input is stored (so that I can process it)?
Many thanks!
- 04-15-2010, 01:37 AM #5
Senior Member
- Join Date
- Mar 2010
- Posts
- 266
- Rep Power
- 4
textArea.getText()
- 04-15-2010, 02:14 AM #6
Member
- Join Date
- Apr 2010
- Posts
- 59
- Rep Power
- 0
Thank you!
- 04-15-2010, 01:20 PM #7
Member
- Join Date
- Apr 2010
- Posts
- 59
- Rep Power
- 0
Similar Threads
-
GUI's and inputting doubles or ints
By lopder1 in forum New To JavaReplies: 19Last Post: 11-05-2009, 08:50 PM -
Inputting custom numbers
By Jakora33 in forum New To JavaReplies: 14Last Post: 09-08-2009, 09:14 PM -
Reversing and inputting files
By jigglywiggly in forum New To JavaReplies: 14Last Post: 03-23-2009, 08:28 AM -
inputting and writing a file backwards
By jigglywiggly in forum New To JavaReplies: 0Last Post: 03-18-2009, 07:24 PM -
comparing inputting strings from Joptionpane and if statement
By phil128 in forum New To JavaReplies: 2Last Post: 12-06-2008, 06:54 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks