Results 1 to 4 of 4
Thread: GUI TextField issues
- 12-02-2012, 12:50 AM #1
Member
- Join Date
- Dec 2012
- Posts
- 3
- Rep Power
- 0
GUI TextField issues
Hey, Im working through a project right now and im struggling with getting the text from the text field. Here is part of my code
Poly is an object I created in another class. But i am getting an error with the Fun.getText() line. Im sure Im just doing this the wrong way so Im just looking for the right way to do it.Java Code:public Input(){ Fun = new JTextField("Function", 12); Var = new JTextField("Variable", 12); Start = new JTextField("Start", 12); End = new JTextField("End", 12); ActionListener buttonListener = new ButtonListener(); JButton button = new JButton("Graph"); button.addActionListener(buttonListener); TPanel = new JPanel(null); TPanel.setLayout(new GridLayout(1, 5)); TPanel.add(Fun); TPanel.add(Var); TPanel.add(Start); TPanel.add(End); TPanel.add(button); add(TPanel); } } class ButtonListener implements ActionListener{ public void actionPerformed(ActionEvent e) { Poly p = new Poly(Fun.getText()); } }
Thanks
- 12-02-2012, 01:15 AM #2
Member
- Join Date
- Dec 2012
- Posts
- 74
- Rep Power
- 0
Re: GUI TextField issues
Try putting your ButtonListener class into the same class as the Input() constructor. I think that this will do the trick.
- 12-02-2012, 02:12 AM #3
Member
- Join Date
- Dec 2012
- Posts
- 3
- Rep Power
- 0
Re: GUI TextField issues
Mint dude! I think that did it.
-
Re: GUI TextField issues
You can have the listener in a separate class, and often you'll want to do that, but it will need some way to call the methods of the GUI class, and so will need a reference to the GUI passed in to it, possibly via a constructor parameter.
Similar Threads
-
Won't set to textfield
By Steffers in forum New To JavaReplies: 7Last Post: 11-04-2010, 02:32 PM -
Draw TextField
By PhQ in forum New To JavaReplies: 6Last Post: 07-17-2010, 01:30 AM -
TextField Example
By Java Tip in forum SWTReplies: 0Last Post: 07-25-2008, 02:21 PM -
JSP - getting value from a textfield
By Java Tip in forum Java TipReplies: 0Last Post: 12-01-2007, 08:58 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks