我试图将单击按钮时可见性设置为false,但编译器显示“不兼容的类型”。那里说if (frame.setVisible(true))
我用JFrame
,JButton
,JLabel
,BorderLayout
,ActionEvent
,并ActionListener
单击按钮以更改可见性
Object source = event.getSource();
if (source == changeTextButton)
{
if (label.getText().equals(LABEL1))
{
label.setText(LABEL2);
}
else
{
label.setText(LABEL1);
}
} // end of if (source == button)
if (source == closeButton)
{
if (frame.setVisible(true))
{
setVisible(false);
}
} // end of if (source == closeButton)
哪条线给你错误? –
“if(frame.setVisible(true))” – user3479783
而且,问题在于此语句不是有效的Java。你实际上陈述了“if(void)”,这是没有意义的。 –