1
我如何執行Java程序時,我選擇單選按鈕當我選擇單選按鈕
class abc implements ActionListener {
public static void main (String args[]){
JFrame frame = new JFrame("Test Frame");
JPanel panel = new JPanel();
Container contpane; contpane = frame.getContentPane();
//added all Radio Buttons
JRadiobutton jb = new
JRadioButton("test1"); JRadiobutton
jb1 = new JRadioButton("test2");
jb.addActionListener(this);
jb.addActionListener(this);//when i say "this" it is giving complie time
error becaus this keyword will not be accesible
}
public void actionPerformed(ActionEvent evt){
How do i create the JTextArea and
Execute the Java class abc.java in
that JTextArea How do i add the
JTextArea to the panel and Frame
what should i write inorder to execute
the java class say abc.java
}
}
錯誤消息是正確的,因爲在靜態方法中沒有「this」。解決方案:不要在靜態main方法中做這些事情,而是在Bala顯示給你的非靜態方法或構造函數中執行它。 – 2011-04-27 02:37:26