글 목록

최신 글과 검색 결과
DEVELOPMENT/JAVA

[10번째 과제] container 와 component 를 이용한 화면 구현

간지뽕빨리턴님

이 글의 목차

    반응형
      자바

    과제 일시 : 2019 - 10 - 10

    과제 내용

    container 와 component 를 이용한 화면 구현하기

    p392-394의 계산기 화면을 container 와 component 를 이용하여 완성하세요.

     

    - Warning! 화면 구성은 하였지만, 동작하진 않습니다.


     

     

     

     

    [ Source Code ]


    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
    /*
     * File : Window.java
     */
    public class Window {
     
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            
            new WindowBox();
            
        }
     
    }
    -------------------------------------------------------------------------------------------------------
    -------------------------------------------------------------------------------------------------------
     
    /*
     * File : WindowBox
     */
     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.GridLayout;
     
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
     
    public class WindowBox extends JFrame {
        WindowBox() {
            
            JTextField jtfDisplay = new JTextField(35);
            JPanel p = new JPanel();
            String[] labels = {
                    "Backspace""""""CE""C",
                    "7""8""9""/""sqrt",
                    "4""5""6""x""%",
                    "1""2""3""-""1/x",
                    "0""+/-"".""+""="
            };
            
            JButton[] buttons = new JButton[25];;
            p.setLayout(new GridLayout(5533));
            
            int index = 0;
            for (int rows = 0; rows<5; rows++) {
                for(int cols=0; cols<5; cols++) {
                    buttons[index] = new JButton(labels[index]);
                    if(cols >= 3) buttons[index].setForeground(Color.RED);
                    else  buttons[index].setBackground(Color.YELLOW);
                         buttons[index].setForeground(Color.BLUE);
                    p.add(buttons[index]);
                    index++;
                    
                }
            }
            add(jtfDisplay, BorderLayout.NORTH);
            add(p, BorderLayout.CENTER);
            setTitle("계산기");
            setSize(500400);
            setVisible(true);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            
            
        }
    }
     
    Korea 저작권 준  수

     

     

     

     

     

     

    [ 출력 화면 ]