필자는 프로그램 할당을 위해 GUI를 만들려고합니다. 기본적으로 왼쪽에 두 개의 버튼이 있고 오른쪽에서 다시 시작하고 패널은 맨 아래에 있습니다.requestFocusInWindow (boolean)는 JComponent에서 액세스를 보호합니까?
Error: requestFocusInWindow(boolean) has protected access in JComponent
내가 전에 한 번이로 실행하고 나는 그 수단 중 하나가 내가 주위를 봤 좋은 설명을 않고 아무것도 그렇게 찾을 수 없습니다 무엇을 이해하지 못하는 것 같은 느낌 :하지만 말해 아마 바보 같을 것 같아.
import javax.swing.*;
import java.awt.*;
public class PendulumWindow {
protected JFrame pendFrame;
protected JPanel pendPanel;
protected JButton resume;
protected final int SIZE_X = 500;
protected final int SIZE_Y = 450;
protected Dimension pendPanSize = new Dimension(SIZE_X, SIZE_Y);
public PendulumWindow() {
}
public PendulumWindow(String s) {
makePanel();
makeFrame();
}
public void makePanel() {
pendPanel = new JPanel();
pendPanel.setPreferredSize(pendPanSize);
pendPanel.setFocusable(true);
pendPanel.requestFocusInWindow(true);
pendPanel.setBackground(Color.BLUE);
}
public void makeFrame() {
pendFrame = new JFrame("Pendulum");
start = new JButton("start");
resume = new JButton("resume");
//---------- FRAME PROPERTIES ----------//
pendFrame.setSize(500,500);
pendFrame.setVisible(true);
pendFrame.setResizable(true);
pendFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//---------- ADD ELEMENTS TO FRAME ----------//
pendFrame.setLayout(new BorderLayout());
pendFrame.add(start, BorderLayout.WEST);
pendFrame.add(resume, BorderLayout.EAST);
// pendFrame.add(pendPanel, BorderLayout.SOUTH);
}
public static void main(String[] args) {
PendulumWindow window = new PendulumWindow("Pendulum");
}
}
pendPanel.requestFocusInWindow()를 호출하는 것이 잘못된 이유는 무엇입니까? – MadProgrammer
는 Reimeus가 제안한 것과 정확히 일치하는 것입니다. public requestFocusInWindow()가 있다는 것을 알지 못했습니다. 내가 문서를 보았을 때 그것을 간과해야만합니다. – SavgStorm