방치하기

swing label textfield 본문

홍익대 Java/수업

swing label textfield

Yi Junho 2009. 7. 28. 17:31
반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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());
             
          }
         }
          
      }
}
반응형
Comments