我有2碼本是主要的講座的Java GUI使用的JFrame
import javax.swing.JFrame;
class gui2
{
public static void main(String args[])
{
frame a=new frame();
a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
a.setSize(275*180);
a.setVisible(true);
}
}
,這一個課堂上,我是importing--
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class frame extends JFrame
{
private JLabel first;
public frame(){
super("Trying GUI");
setLayout(new FlowLayout());
first=new JLabel("tHIS IS a sentence");
first.setToolTipText("hover to see");
add(first);
}
}
當我運行代碼,我是得到一個無法訪問框架的錯誤。我在做什麼錯誤?
顯示完整的完整的錯誤消息,而不是你對它的解釋。 –
'a.setSize(275 * 180);'以 – MadProgrammer
@MadProgrammer開頭是錯誤的感謝您指出。它解決了這個問題。程序現在給出了正確的輸出。我錯過了逗號。 –