[nbj2ee] Setting a main jframe

  • From: "AeneasTroy" < >
  • To:
  • Subject: [nbj2ee] Setting a main jframe
  • Date: Thu, 04 Oct 2012 18:13:10 -0400

Okay.

As far as adding buttons and textfields,
in the myFrame class, you would do this

All this does is add a button, but in order to make the button do something:

package newx;

import javax.swing.*;
import java.awt.event.*;

public class myFrame extends JFrame implements ActionListener{
    //declare all Buttons and text fields up here to make them global
    JButton myButton;
    JTextField myTextField;
    
    public myFrame(){
        super("Title");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        pack();
        setVisible(true);
        setBounds(0,0,500,500);

       setLayout(null);
        myButton = new JButton("Click me!");
        myTextField = new JTextField("");
       
        getContentPane().add(myButton);
       getContentPane().add(myTextField);

        myButton.setBounds(10,10,120,25);
        myTextField.setBounds(150,10,120,25);
     

        myButton.addActionListener(this);
    }
    
    public void actionPerformed(ActionEvent e){
         String myTextFieldsTextValue = new String("");
        if(e.getSource() == myButton){
            myTextFieldsTextValue = myTextField.getText();
            System.out.println(myTextFieldsTextValue);
        }
    }
}






[nbj2ee] Setting a main jframe

smacker 10/04/2012

[nbj2ee] Setting a main jframe

AeneasTroy 10/04/2012

[nbj2ee] Setting a main jframe

smacker 10/04/2012

[nbj2ee] Setting a main jframe

AeneasTroy 10/04/2012

[nbj2ee] Setting a main jframe

smacker 10/04/2012

[nbj2ee] Setting a main jframe

AeneasTroy 10/04/2012

[nbj2ee] Setting a main jframe

smacker 10/04/2012

[nbj2ee] Setting a main jframe

AeneasTroy 10/04/2012

[nbj2ee] Setting a main jframe

java@12345 10/10/2012

Project Features

About this Project

www was started in November 2009, is owned by jpirek, and has 21 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close