블로그 이미지
가진것도 없고 능력도 없는데 그저 바라기만 하는 인간 이런 인간을 두고 잉여인간이라고 한다. 행프

카테고리

분류 전체보기 (69)
C++ (21)
DB (25)
자바2 (9)
교양영어,토익 (0)
리눅스 (0)
알아두면 좋은것들 (1)
특강 (1)
영진소식 (12)
Total
Today
Yesterday

달력

« » 2025.7
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

공지사항

최근에 올라온 글

10월 12일 강의내용

자바2 / 2012. 10. 12. 14:54

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class SwingApplication extends JFrame implements ActionListener{
     public static final int WIDTH = 300;
     public static final int HEIGHT = 200;
     JPanel panel;
     JButton confirmButton, exitButton;
 
 
 public SwingApplication(){
      this.setTitle("Swing Application");
      setSize(WIDTH,HEIGHT);
  
      setDefaultCloseOperation(EXIT_ON_CLOSE);
  
      confirmButton = new JButton("확인");
  
      exitButton = new JButton("프로그램 종료");
      exitButton.addActionListener(this);
  
      panel = new JPanel();
  
      panel.add(confirmButton);
      panel.add(exitButton);
      this.add(panel);
  
      setVisible(true);
 }

 
 public static void main(String[] args) {
      new SwingApplication();

 }


 @Override
 public void actionPerformed(ActionEvent arg0) {
  System.exit(0);
  
 }
}
* 프로그램 종료 버튼을 눌렀을때 꺼지는 기능은   button.addActionListener(this);

ActionListener = 프로그램 종료 (하나의 약속)

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 

*레이아웃 넣기

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class SwingApplication extends JFrame implements ActionListener{
     public static final int WIDTH = 300;
     public static final int HEIGHT = 200;
     JPanel panel;
     JButton confirmButton, exitButton;
 
 public SwingApplication(){
      this.setTitle("Swing Application");
      setSize(WIDTH,HEIGHT);
  
      setLayout(new BorderLayout());
  
      setDefaultCloseOperation(EXIT_ON_CLOSE);
  
      confirmButton = new JButton("확인");
   
  
      exitButton = new JButton("프로그램 종료");
      exitButton.addActionListener(this);
  
      panel = new JPanel();
  
      panel.add(confirmButton);
 
      panel.add(exitButton);
      this.add(panel, BorderLayout.SOUTH);
  
      setVisible(true);
 }

 
 public static void main(String[] args) {
      new SwingApplication();

 }


 @Override
 public void actionPerformed(ActionEvent arg0) {
      System.exit(0);
  
 }
}

 

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class SwingApplication extends JFrame implements ActionListener{
     public static final int WIDTH = 300;
     public static final int HEIGHT = 200;
     JPanel panel;
     JButton confirmButton, exitButton;
 
 public SwingApplication(){
      this.setTitle("Swing Application");
      setSize(WIDTH,HEIGHT);
 
      setLayout(new BorderLayout());
 
      setDefaultCloseOperation(EXIT_ON_CLOSE);
 
      confirmButton = new JButton("확인");
      confirmButton.addActionListener(this);
  
 
      exitButton = new JButton("종료");
      exitButton.addActionListener(this);
 
      panel = new JPanel();
 
      panel.add(confirmButton);
 
      panel.add(exitButton);
      this.add(panel, BorderLayout.SOUTH);
 
      setVisible(true);
 }

 
 public static void main(String[] args) {
      new SwingApplication();

 }


 @Override
 public void actionPerformed(ActionEvent e) {
  JButton b = (JButton)e.getSource();
  if (b.getText().equals("확인")){
   b.setText("취소");
  } else if (b.getText() == "종료"){
 System.exit(0);
 
    }
  }
}

 

'자바2' 카테고리의 다른 글

11월 2일 강의  (0) 2012.11.05
10월19일 강의  (0) 2012.10.19
AWT  (0) 2012.10.05
9월 28일 강의내용  (0) 2012.09.28
자바 실습문제  (1) 2012.09.28
Posted by 알 수 없는 사용자
, |

최근에 달린 댓글

글 보관함