일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 티스토리초대
- eslint-import-resolver-typescript
- 프리티어
- visual studio code
- GitHub 미러링
- 유니옥션
- React Native
- 티스토리 초대장/ 티스토리초대
- code .
- webstorm
- react native #gradle
- Path Alias
- '티스토리 초대장/ 티스토리초대'
- 니돈내먹
- Emmet
- GitHub Mirroring
- 프레시업 #풀무원 #하루한병 #건강만들기 #풀무원 녹즙
- currentTimeMillis
- GitLab미러링
- GitLab Mirroring
- 티스토리 초대장
- visual studio code cli
- settings sync
- 초대장
- 네이버 클라우드 플랫폼
- code 세팅
- 실행시간 측정
- code 설치
- 음료같은녹즙
- gitlab 연동
Archives
- Today
- Total
방치하기
텍스트 필드와 버튼 본문
반응형
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 72 73 74 75 | import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Add extends JFrame { private JButton addButton, printButton; Panel pan01,pan02; JTextField text01,text02; StringBuffer str= new StringBuffer(); public Add() { super ( "이름추가" ); text01 = new JTextField( 5 ); text02 = new JTextField( 10 ); text02.setEditable( false ); Container container = getContentPane(); container.setLayout( new GridLayout( 2 , 1 )); addButton = new JButton( "추가" ); printButton = new JButton( "출력" ); pan01= new Panel(); pan02= new Panel(); container.add( pan01 ); container.add( pan02 ); pan01.setLayout( new BorderLayout()); pan01.add(BorderLayout.WEST,text01); pan01.add(BorderLayout.EAST,addButton); pan01.setLayout( new GridLayout( 1 , 2 )); pan02.setLayout( new BorderLayout()); pan02.add(BorderLayout.NORTH,text02); pan02.add(BorderLayout.SOUTH,printButton); ButtonHandler handler = new ButtonHandler(); //액션이 발생하면 아래 내부 클래스로 넘김 addButton.addActionListener( handler ); printButton.addActionListener( handler ); setSize( 275 , 150 ); setVisible( true ); } public static void main( String args[] ) { Add application = new Add(); application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); } private class ButtonHandler implements ActionListener { public void actionPerformed( ActionEvent event ) { if ( "추가" .equals(event.getActionCommand())) { JOptionPane.showMessageDialog(Add. this , "You pressed: " + text01.getText()+ "추가합니다" ); str.append(text01.getText()+ " " ); System.out.println(text01.getText()+ "추가합니다" ); text01.setText( "" ); } else { String str02= str.substring( 0 ); System.out.println(str02); text02.setText(str02); } } } } |
반응형
'홍익대 Java > 수업' 카테고리의 다른 글
홍대 자바 수업 계산기임 Model / View /Control Float.parseFloat (0) | 2009.07.30 |
---|---|
홍대 자바 수업 : 리스트형(스크롤형) 버튼 텍스트 필드 컬러와 배경 색 바꾸기 . (0) | 2009.07.29 |
swing label textfield (0) | 2009.07.28 |
홍대 자바 수업 : awt 버튼 원하는 자리에 (0) | 2009.07.28 |
홍대 자바 수업 : 패널 (0) | 2009.07.28 |