컴파일> javac -d . HelloWinApp.java
실행> java HelloWinApp

/*
 * HelloWinApp.java
 */

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

public class HelloWinApp extends Frame implements ActionListener {

   Button button1;
   Label label1;

   public static void main(String[] args) {
      HelloWinApp app = new HelloWinApp();
      app.setTitle("Hello Win");
      app.addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent we) {
            System.exit(0);
          }
      });
      app.setLocation(50, 50);
      app.setSize(200, 140);
      app.setVisible(true);
    }
 
    public HelloWinApp() {
      setLayout(null);
      button1 = new Button("클릭하세요!");
      button1.addActionListener(this);
      button1.setBounds(40, 100, 120, 30);
      label1 = new Label("");
      label1.setBounds(30, 60, 120, 20);
      setBackground(new Color(0xFF, 0xFF, 0xEE));
      add(label1);
      add(button1);
   }

   private Dialog dialog1;
   private Panel panDiag;

   public void actionPerformed(ActionEvent e) {
      Object src = e.getSource();
      if (src instanceof Button) {
            if ((Button) src == button1) {
                dialog1 = new Dialog(this, "메시지");
                dialog1.setSize(180, 120);
                dialog1.setLocation(300, 200);
                dialog1.addWindowListener(new WindowAdapter() {
                    public void windowClosing(WindowEvent we) {
                        dialog1.dispose();
                    }
                });
         
                panDiag = new Panel() {
                    public void paint(Graphics g) {
                      g.drawString( "안녕하세요?", 30, 30 );
                    }
                };

                dialog1.add(panDiag);
                dialog1.setVisible(true);
                label1.setText("Hello, world!");
            }
      }
   }
}





Creative Commons License 
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다

Posted by Scripter
,