1
이것은 내 코드이며 실행하면 빈 창이됩니다. 스윙 구성 요소가 표시되지 않습니다.
그래서 내가 생성자에 넣어,하지만 아무것도 표시되지 것입니다 : 내가"Cannot make a static reference to the non-static field panel"
main.setContentPane()
을하려고 할 때 우선이 오류가 발생했습니다.
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MainFrame extends JFrame{
private JPanel panel;
private JButton performance;
private JButton concordance;
private JButton discordance;
private JButton resultat;
public void MainFrame() {
panel = new JPanel(new GridLayout(4, 1, 10, 10));
performance = new JButton("performance");
concordance = new JButton("concordance");
discordance = new JButton("discordance");
resultat = new JButton("resultat");
performance.setSize(50, 30);
concordance.setSize(50, 30);
discordance.setSize(50, 30);
resultat.setSize(50, 30);
panel.add(performance);
panel.add(concordance);
panel.add(discordance);
panel.add(resultat);
getContentPane().add(panel);
}
public static void main(String[] args) {
MainFrame main = new MainFrame();
main.setSize(300, 200);
main.setDefaultCloseOperation(EXIT_ON_CLOSE);
main.setVisible(true);
}
}
와우, 나는 완전히 무효 말했다 놓친를, 나는 그것이 생성자라고 생각 그냥 그 위에 보았다 (테스트 및 생성자로 예상대로 작동) – phflack
걱정하지 마! 그것은 일어난다. 때로는 외부의 눈을 들여다 보는 것이 도움이됩니다. :) – richjavadev