1.사용할 컴포넌트 개체는 전부 멤버변수로 할당해야함.
ex)private Button button1;

2. VE에서는 컴포넌트를 Get방식멤버변수에서 생성하고
   이를 반환하도록 설계되어있다.
ex) private Button getButton1()
 {
  if(button1==null)
  {
   button1 = new Button();
 ..................
   });
  }
  return button1;

이렇게 구조를 잡으면 VE로도 인식가능.
***************************************
package ch11;

import java.awt.*;
import java.awt.event.*;

import javax.swing.JOptionPane;

//VE에서는 윈도우폼을 만들때 Frame 클래스를 상속받도록 한다.
public class Ch1103 extends Frame
{
 //VE에서는 사용할 컴포넌트 개체는 전부 멤버변수로
 //등록하여 관리함.
 private Button button1;
 
 public Ch1103()
 {
  // TODO 자동 생성된 생성자 스텁
  //VE에서는 생성자에 super()호출 및 initialize()호출
  super();
  initialize();
 }
 
 private void initialize()
 {
  // TODO 자동 생성된 메소드 스텁
  setVisible(true);
  setBounds(0,0,320,200);
  setLayout(null);
  setTitle("수동으로 작성한");
  setBackground(new Color(150,150,50));
 
  add(getButton1());
 
 }


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

 /**
  * VE에서는 컴포넌트를 Get방식멤버변수에서 생성하고
  * 이를 반환하도록 설계되어있다.
  * @return button1
  */
 private Button getButton1()
 {
  if(button1==null)
  {
   button1 = new Button();
   button1.setLabel("버튼1");
   button1.setBounds(70, 70, 150, 100);
   button1.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {
     // TODO 자동 생성된 메소드 스텁
     JOptionPane.showMessageDialog(null, "Hello");
     
    }});
  }
  return button1;
 }
}

Posted by 말없제이
,