Olha pessoal Minha apredizagem Melhorou muito quando comprei o livro do Deitel Mais em um de seus exemplos ele faz essa aplicativo para exemplificar o JTextField…
O que acontesse é: quando eu tento copilar o programa ele me retorna a seguinte erro:
C:\java>javac 01.java
01.java:58: non-static variable JFrame cannot be referenced from a static context
JFrame.EXIT_ON_CLOSE );
^
01.java:58: cannot find symbol
symbol : variable EXIT_ON_CLOSE
location: class javax.swing.JTextField
JFrame.EXIT_ON_CLOSE );
^
2 errors
o que esta acontecendo ?
o cod. que eu tento copilar é:
[code]// pacote do núcleo do java
import java.awt.;
import java.awt.event.;
// Pacotes de extenção do java
import javax.swing.*;
class TextFieldTest extends JFrame {
private JTextField JFrame, textField1, textField2, textField3;
private JPasswordField passwordField;
// configura a GUI
public TextFieldTest() {
super( "Testing JTextField and JPasworField");
Container container = getContentPane();
container.setLayout( new FlowLayout() );
// constroi campo de texto com dimenções default
textField1 = new JTextField( 10 );
container.add( textField1 );
// constroi campo de texto cm texto default
textField2 = new JTextField( "Enter text here" );
container.add( textField2 );
// constroi campo de texto default e 20 elementos visiveis sem tratador de eventos
textField3 = new JTextField( "Uneditable text field", 20);
textField3.setEditable( false );
container.add( textField3 );
// constrói campo de texto com texto default
TextFieldHandler handler = new TextFieldHandler();
textField1.addActionListener( handler );
textField2.addActionListener( handler );
textField3.addActionListener( handler );
passwordField.addActionListener( handler );
setSize( 325, 100 );
setVisible(true);
}
// executa o aplicativo
public static void main( String args[] ){
TextFieldTest application = new TextFieldTest();
application.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE );
}
// CLASSE INTERNA PRIVADA PARA O TRATAMENTO DO EVENTO
private class TextFieldHandler implements ActionListener
{
// process text field events
public void actionPerformed( ActionEvent event )
{
String string = ""; // declare string to display
// user pressed Enter in JTextField textField1
if ( event.getSource() == textField1 )
string = String.format( "textField1: %s",
event.getActionCommand() );
// user pressed Enter in JTextField textField2
else if ( event.getSource() == textField2 )
string = String.format( "textField2: %s",
event.getActionCommand() );
// user pressed Enter in JTextField textField3
else if ( event.getSource() == textField3 )
string = String.format( "textField3: %s",
event.getActionCommand() );
// user pressed Enter in JTextField passwordField
else if ( event.getSource() == passwordField )
string = String.format( "passwordField: %s",
new String( passwordField.getPassword() ) );
// display JTextField content
JOptionPane.showMessageDialog( null, string );
} // end method actionPerformed
} // end private inner class TextFieldHandler
} // end class TextFieldFrame[/code]