이메일

구글 : kdj777ehdwns@gmail.com
네이버 : kdj777ehdwns@naver.com
epsckr2016.blogspot.com

2016년 9월 22일 목요일

[이클립스] 버튼과 레이블

버튼 예제
import java.awt.Button;
 import java.awt.Color;
 import java.awt.Frame;

 public class FrameTest extends Frame {

 // 생성자
 public FrameTest( String str ) {
  super( str );
 }

 public static void main(String[] args) {
  FrameTest fr = new FrameTest( "컴퓨터정보과" );
  Button btn2 = new Button();
  btn2.setLabel( "North" );
  btn2.setBackground( Color.blue );
  fr.add( btn2, "North" );
  Button btn1 = new Button();
  btn1.setLabel( "Center" );
  btn1.setBackground( Color.cyan );
  fr.add( btn1, "Center" );
  Button btn3 = new Button();
  btn3.setLabel( "West" );
  btn3.setBackground( Color.green );
  fr.add( btn3, "West" );
  Button btn4 = new Button();
  btn4.setLabel( "East" );
  btn4.setBackground( Color.orange );
  btn4.setEnabled( false );
  fr.add( btn4, "East" );
  Button btn5 = new Button();
  btn5.setLabel( "South" );
  btn5.setBackground( Color.yellow );
  fr.add( btn5, "South" );
  fr.setSize( 500, 500 );
  fr.setBackground( Color.GREEN );
  fr.setVisible( true );
 }

 }



버튼 테스트 예제

import java.awt.Button;
 import java.awt.Color;
 import java.awt.FlowLayout;
 import java.awt.Frame;
 import java.awt.Label;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;

 public class LabelTest extends Frame implements ActionListener {
 Label lbl1, lbl2, lbl3;
 Button btn;

 public static void main(String[] args) {
  LabelTest lbltest = new LabelTest( "위대한 프로그램" );
  lbltest.setSize( 500, 500 );
  lbltest.setBackground( Color.yellow );
  lbltest.setVisible( true );
 }

 public LabelTest( String title ) {
  super( title );
  setLayout( new FlowLayout() );
  lbl1 = new Label(); lbl1.setText( "은평문화예술정보학교" );
  lbl1.setAlignment( Label.LEFT ); lbl1.setBackground( Color.cyan );
  add( lbl1 );
  lbl2 = new Label(); lbl2.setText( "컴퓨터정보" );
  lbl2.setAlignment( Label.CENTER );
  add( lbl2 );
  lbl3 = new Label(); lbl3.setText( "이세진" );
  lbl3.setAlignment( Label.RIGHT ); lbl3.setBackground( Color.blue );
  add( lbl3 );
  btn = new Button( "종료" );
  btn.addActionListener( this );
  add( btn );
 }

 public void actionPerformed( ActionEvent e ) {
  if( e.getSource() == btn ) {
   System.exit( 0 );
  }
 }

 }



버튼과 레이블 예제

import java.awt.Button;
 import java.awt.Color;
 import java.awt.FlowLayout;
 import java.awt.Frame;
 import java.awt.Label;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;

 public class ButtonLabelTest extends Frame implements ActionListener {
    Button btn1, btn2, btn3, btn4;
    Label label;

    public static void main( String args[] ) {
       ButtonLabelTest fr = new ButtonLabelTest( "컴퓨터정보과" );

       fr.setSize( 500, 500 );
       fr.setBackground( Color.blue );
       fr.setVisible( true );
    }

    public ButtonLabelTest( String str ) {
       super( str );

       setLayout( new FlowLayout() );

       btn1 = new Button( "C언어" );
       btn1.setBackground( Color.cyan );
       btn1.addActionListener( this );

       btn2 = new Button( "자바" );
       btn2.setBackground( Color.yellow );
       btn2.addActionListener( this );

       btn3 = new Button( "Python" );
       btn3.setBackground( Color.green );
       btn3.addActionListener( this );

       label = new Label();
       label.setText( "버튼을 누르시오." );
       label.setAlignment( Label.CENTER );
       label.setBackground( Color.white );

       btn4 = new Button( "종료" );
       btn4.addActionListener( this );

       add( btn1 );
       add( btn2 );
       add( btn3 );
       add( label );
       add( btn4 );
    }

    public void actionPerformed( ActionEvent e ) {
       if( e.getSource() == btn1 ) {
          label.setText( "C언어 선택" );
       }
       if( e.getSource() == btn2 ) {
          label.setText( "자바 선택" );
       }
       if( e.getSource() == btn3 ) {
          label.setText( "Python 선택" );
       }
       if( e.getSource() == btn4 ) {
          System.exit( 0 );
       }
    }
 }




날짜 : 2016년 09월 22일




댓글 없음:

댓글 쓰기