1
저는 초보자 프로그래머이고 최근에 GUI를 실험 해 왔습니다. 저는 학교의 컴퓨터 (Windows XP, TextPad)에서 응용 프로그램을 작성해 왔으며 컴파일하고 잘 실행합니다. 그러나 내 집 컴퓨터 (Mac OS Mountain Lion, Eclipse)에서 똑같은 코드를 실행하면 JPanel이 JFrame에 제대로 추가되지 않는 것 같습니다. 나는 다음 수업을 듣는다.JPanels가 Eclipse IDE에 표시되지 않습니까?
Main.java :
public class Main {
public static void main(String[] args) {
new Frm();
} // end of method main()
} // end of class Main
Frm.java :
import javax.swing.JFrame;
@SuppressWarnings("serial")
public class Frm extends JFrame {
private final int HEIGHT = 400;
private final int WIDTH = 600;
public Frm() {
setSize(WIDTH, HEIGHT);
setTitle("SHREK");
setVisible(true);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().add(new Pnl());
} // end of constructor
} // end of class Frm
Pnl.java :
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
@SuppressWarnings("serial")
public class Pnl extends JPanel {
public Pnl() {
BorderFactory.createLineBorder(Color.BLACK, 5);
setBackground(Color.BLACK);
} // end of constructor
} // end of class Pnl