신나게 개발하기

swing label textfield 본문

홍익대 Java/수업

swing label textfield

Yi,Junho 2009. 7. 28. 17:31
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TextFieldTest extends JFrame {
	static String string = "";
	static String string2 = "";
   private JTextField textField1, textField2, textField3;

   public TextFieldTest()
   {
      super( "Testing JTextField and JPasswordField" );
      Container container = this.getContentPane();
      container.setLayout( new GridLayout(3,2) );
      JLabel label=new JLabel("이름");
	  container.add( label );
	  textField1 = new JTextField( 10 );
      container.add( textField1 );
	  JLabel label2=new JLabel("학교");
	  container.add( label2 );
      textField2 = new JTextField( 10 );
      container.add( textField2 );
      JLabel label3=new JLabel("출력");
	  container.add( label3 );
	  textField3 = new JTextField( 10 );
      container.add( textField3 );


      TextFieldHandler handler = new TextFieldHandler();
      
	  textField1.addActionListener( handler );
      textField2.addActionListener( handler );
      textField3.addActionListener( handler );

      setSize( 325, 100 );
      setVisible( true );
   } 
   public static void main( String args[] )
   { 
      TextFieldTest application = new TextFieldTest();
      application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
   }
   // private inner class for event handling
   private class TextFieldHandler implements ActionListener {
      public void actionPerformed( ActionEvent event )
      {
         
		 
		 StringBuffer string3=new StringBuffer();

         if ( event.getSource() == textField1 )
            string = event.getActionCommand();
 
         else if ( event.getSource() == textField2 )
            string2 = event.getActionCommand();
    
         else if ( event.getSource() == textField3 )
		  {
            
			
			/*string3.append("당신의 이름은");
			string3.append(string);
			string3.append("당신의 학교는");
			string3.append(string2);
			JOptionPane.showMessageDialog( null, string3 );*/
			textField3.setText(textField1.getText()+" <이름    학교>"+textField2.getText());
			
		  }
         }
         
      }
}
0 Comments
댓글쓰기 폼