Netbeans ( java coding )

In this forum members can discuss topics about specific programming languages.
Post Reply
Posts: 1
Joined: Mon May 02, 2011 2:10 am

Netbeans ( java coding )

Post by kinggenton »

Ok guys i am creating a GUI with two buttons and a textfield
what i need help in is how when i press a button
it uses the info in my textfield to generate my answer!
this is what i am looking for

so lets say my program asked my name
i enter Darnelle in the field and one of my buttons i need it to use that name!
and for output give me Hi Darnelle thank you for coming

and i know how to import! JOptionPane its not part of this exercise!
i just need some code to help use the info from the textfield thanks!
Posts: 14
Joined: Fri Mar 04, 2011 10:53 pm

Re: Netbeans ( java coding )

Post by davidFashion »


Here is a complete program that shows how, when a button is pressed, that the information is read from the text field and displayed in a JOptionPane.

Fundamentally, a Java ActionListener object is added to the button. At the place in the code where the ActionListener is added to the button, the ActionListerer object has access to the TextField object. Hence, the ActionListerer object can read the text that exists in the TextField object.

Code: Select all

import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Window {

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                final JFrame frame = new JFrame();

                JPanel panel = new JPanel(new GridLayout(2, 1));
                JButton button = new JButton("Press Me");
                final JTextField textfield = new JTextField(25);

                button.addActionListener(new ActionListener() {
                    @Override public void actionPerformed(ActionEvent e) {
                        JOptionPane.showMessageDialog(frame, textfield.getText(), "Message", JOptionPane.INFORMATION_MESSAGE);


Posts: 2
Joined: Sun Oct 23, 2011 8:44 am

Re: Netbeans ( java coding )

Post by chorinne »

How to disable the Java Runtime error messages saying to debug? On one of the Google sites my volunteer group uses, I constantly get about 7 Java Runtime error messages asking me if I want to debug. It is extremely annoying, and I'd like to know how to disable this feature.
keyword research ~ keyword tool ~ keyword tracking ~ affiliate elite
Post Reply