9 개의 버튼으로 구성된 JApplet 애플리케이션을 만들었습니다.내 JApplet이 처음에 흰색으로 표시되는 이유는 무엇입니까?
- 애플릿이 처음 시작될 때 완전히 흰색입니다. 단추가있는 영역을 클릭하면 단추가 표시되고 작동합니다. 애플릿이 시작된 후 바로
- 30 초, 버튼이 표시 될 수 있지만, 배경은 여전히 흰색입니다.
- 메인 메뉴는 다음과 같이한다 .
왜 애플릿이 제대로로드되지 않습니다?
ConverterApplet.java :이
public class ConverterApplet extends JApplet {
public void init()
{
try{
SwingUtilities.invokeAndWait(new Runnable(){
@Override
public void run()
{
createGUI();
}
});
}catch(Exception e)
{
System.err.println("GUI could not be created.");
}
}
public void start(){}
public void stop(){}
public void destroy(){}
public void paint(java.awt.Graphics g){
resize(400,400);
};
private void createGUI()
{
MainPanel m = new MainPanel();
getContentPane().add(m,BorderLayout.CENTER);
}
}
MainPanel.java :
public class MainPanel extends JPanel implements ActionListener {
private final static String UNIT_SELECTION_PANEL = "UNIT_SELECTION_CARD";
private final static String UNIT_CONVERSION_PANEL = "UNIT_CONVERSION_PANEL";
JPanel cardPanel;
private JButton[] UnitButtons;
private JButton backButton;
private CardLayout cardLayout;
private UnitConversionPanel unitConversionPanel;
public MainPanel()
{
super(new GridBagLayout());
cardPanel = new JPanel();
JPanel unitSelectionPanel = new JPanel();
backButton = new JButton("<-");
backButton.addActionListener(this);
backButton.setVisible(false);
UnitButtons = new JButton[9];
UnitButtons[0] = new JButton("Length");
UnitButtons[1] = new JButton("Time");
UnitButtons[2] = new JButton("Mass");
UnitButtons[3] = new JButton("Speed");
UnitButtons[4] = new JButton("Volume");
UnitButtons[5] = new JButton("Area");
UnitButtons[6] = new JButton("Pressure");
UnitButtons[7] = new JButton("Temperature");
UnitButtons[8] = new JButton("Energy");
for(int i=0;i<UnitButtons.length;i++)
{
UnitButtons[i].addActionListener(this);
}
GridLayout layout = new GridLayout(0,3,20,20);
unitSelectionPanel.setLayout(layout);
for(JButton buttons: UnitButtons)
{
unitSelectionPanel.add(buttons);
}
unitConversionPanel = new UnitConversionPanel();
cardLayout = new CardLayout();
cardPanel.setLayout(cardLayout);
cardPanel.add(UNIT_SELECTION_PANEL, unitSelectionPanel);
cardPanel.add(UNIT_CONVERSION_PANEL, unitConversionPanel);
cardLayout.show(cardPanel, UNIT_SELECTION_PANEL);
GridBagConstraints c = new GridBagConstraints();
//c.fill = GridBagConstraints.VERTICAL;
c.gridx = 0;
c.gridy = 0;
//c.insets = new Insets(5,5,5,5);
add(backButton,c);
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
c.weighty = 1;
c.gridx = 0;
c.gridy = 1;
c.gridwidth=2;
c.gridheight=1;
add(cardPanel,c);
}
}
죄송합니다. 나쁜 습관을 가지고 있습니다. 메인 패널의 크기를 변경하려고 시도했지만 작동하지 않았습니다. 다른 방법이 있습니까? –
메서드를 제거해도 문제가 해결되었지만 애플릿 창이 너무 작습니다. 이 애플릿을 실행 가능한 병으로 만들기를 바랬습니다. 대신 JFrame을 사용해야합니까? 그게 멍청한 질문이라면 유감입니다. –