Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Ron McLeod
Paul Clapham
Tim Cooke
Devaka Cooray
Sheriffs:
Liutauras Vilda
paul wheaton
Rob Spoor
Saloon Keepers:
Tim Moores
Stephan van Hulst
Tim Holloway
Piet Souris
Mikalai Zaikin
Bartenders:
Carey Brown
Roland Mueller
Forum:
Swing / AWT / SWT
GUI runtime error
Mark Phylus
Greenhorn
Posts: 18
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
My program compiles fine but gives me a runtime error.
1. Can anyone explain to me what the error means?
2. Kindly help me fix it.
I do appreciate this. here is the code
Thanks.
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class NameGui { public static void main(String[] args) { FullNameGui f = new FullNameGui(); f.setVisible(true); } } // end of NameGui /*************************************************************/ class FullNameGui extends JFrame implements ActionListener { //*************************************************************** //data members: private JTextField title, first, last, middle, formalName; private JButton formalnameButton; FullName name; //**************************************************************** /****** Constructor *********/ public FullNameGui()// constructor { // set up the frame properties setSize(300,250); setLocation(20,20); setTitle("Full Name GUI"); setResizable(false); setDefaultCloseOperation(EXIT_ON_CLOSE); // establish container & properties Container cp = getContentPane(); cp.setLayout(new FlowLayout()); cp.setBackground(Color.WHITE); // add first name information to GUI: "first" field cp.add(new JLabel("First Name")); first = new JTextField(15); cp.add(first); // add middle name information to GUI: "middle" field cp.add(new JLabel("Middle Name")); middle = new JTextField(14); cp.add(middle); // add last name information to GUI:"last" field cp.add(new JLabel("Last Name")); last = new JTextField(16); cp.add(last); // place text field for "formal name" in GUI: "formal name" field cp.add(new JLabel("Formal Name")); formalName = new JTextField(25); cp.add(formalName); // add button to "call" for processing to be done formalnameButton = new JButton("get Formal Name"); cp.add(formalnameButton); formalnameButton.addActionListener(this); } // end of constructor /******** actionPerformed method **************/ public void actionPerformed(ActionEvent e) { String fname = first.getText().trim(); // retrieve text from "first" field String lname = last.getText().trim(); // retrieve text from "last" field String t = title.getText().trim(); // retrieve text from "title" field String mname = middle.getText().trim(); // retrieve text from "middle"field if (mname == "") // middle name field empty name = new FullName(fname,lname); // call to two argument constructor else // middle name field has entry name = new FullName(fname,mname,lname);//call to three argument //constructor name.setTitle(t); // use t to set the title for the name /* set the text in the "formal name" field */ formalName.setText(name.FormalName()); } // end of actionPerformed } // end of FullNameGui
[ May 03, 2004: Message edited by: Mark Phylus ]
Michael Dunn
Ranch Hand
Posts: 4632
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You would be getting a NullPointerException here
String
t = title.getText().trim();
'title' has not been created, or added to the GUI
Mark Phylus
Greenhorn
Posts: 18
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks
I will open the floodgates of his own worst nightmare! All in a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
not showing JLabel and TextField
NoSuchMethodError: Main
text box - GridBagLayout
Object access within another Object
Not able to Inserting integer data
More...