자바로 GUI프로그래밍을 해보려하는데 요류가 납니다.

조회수 2330회
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class index extends JFrame{
    private JLabel result;

    ButtonTest() {
        setTitle("Button Test");

        JLabel lab = new JLabel("Click one of the buttons.");
        getContentPane().add(lab, "North");

        result = new JLabel(" ");
        getContentPane().add(result, "South");

        JButton yes = new JButton("Yes");
        getContentPane().add(yes, "West");
        yes.addActionListener(new YesHandler());

        JButton no = new JButton("No");
        getContentPane().add(no, "East");
        no.addActionListener(new NoHandler());;
    }
    class YesHandler implements ActionListener {
        public void actionPerformed(ActionEvent evt) {
            result.setText("you pressed the yes button");
        }
    }
    class NoHandler implements ActionListener {
        public void actionPerformed(ActionEvent evt) {
            result.setText("you pressed the no button");
        }
    }
    public static void main(String [] args) {
        JFrame jf = new ButtonTest();
        jf.setSize(250, 150);
        jf.setVisible(true);
    }
}

이런 코드를 작성해하였는데

ButtonTest() 에서 빨간줄이 그어집니다. 물론 실행도 안되구요 왜이런걸까요?

예제를 그대로 따라했는데

  • (•́ ✖ •̀)
    알 수 없는 사용자

1 답변

  • ButtonTest는 생성자로 사용했는데 클래스 이름이랑 달라서 생긴 오류입니다.

    올리신 코드의 클래스 이름이 index네요. ButtonTest로 바꾸면 됩니다.

    자바의 기본 문법을 다시 체크하시면 될겁니다.

    • (•́ ✖ •̀)
      알 수 없는 사용자

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)